@@ -859,7 +859,7 @@ mod tests {
" }\n",
"}\n",
"\n",
- "fn newline() { β¦ }\n",
+ "fn newline() { β¦ }\n",
]
.concat(),
);
@@ -996,7 +996,7 @@ mod tests {
"\n",
"fn outer() { outer⦠}\n",
"\n",
- "fn newline() { β¦ }\n",
+ "fn newline() { β¦ }\n",
]
.concat(),
);
@@ -7668,9 +7668,10 @@ impl LspStore {
source_worktree_id,
path,
kind: symbol_kind,
- name: symbol_name,
+ name: collapse_newlines(&symbol_name, "β΅ "),
range: range_from_lsp(symbol_location.range),
- container_name,
+ container_name: container_name
+ .map(|c| collapse_newlines(&c, "β΅ ")),
})
},
)
@@ -14275,6 +14276,13 @@ async fn populate_labels_for_symbols(
}
}
+pub(crate) fn collapse_newlines(text: &str, separator: &str) -> String {
+ text.lines()
+ .map(|line| line.trim())
+ .filter(|line| !line.is_empty())
+ .join(separator)
+}
+
fn include_text(server: &lsp::LanguageServer) -> Option<bool> {
match server.capabilities().text_document_sync.as_ref()? {
lsp::TextDocumentSyncCapability::Options(opts) => match opts.save.as_ref()? {
@@ -249,6 +249,8 @@ fn flatten_document_symbols(
output: &mut Vec<OutlineItem<Anchor>>,
) {
for symbol in symbols {
+ let name = super::collapse_newlines(&symbol.name, " ");
+
let start = snapshot.clip_point_utf16(symbol.range.start, Bias::Right);
let end = snapshot.clip_point_utf16(symbol.range.end, Bias::Left);
let selection_start = snapshot.clip_point_utf16(symbol.selection_range.start, Bias::Right);
@@ -258,18 +260,12 @@ fn flatten_document_symbols(
let selection_range =
snapshot.anchor_after(selection_start)..snapshot.anchor_before(selection_end);
- let (text, name_ranges, source_range_for_text) = enriched_symbol_text(
- &symbol.name,
- start,
- selection_start,
- selection_end,
- snapshot,
- )
- .unwrap_or_else(|| {
- let name = symbol.name.clone();
- let name_len = name.len();
- (name, vec![0..name_len], selection_range.clone())
- });
+ let (text, name_ranges, source_range_for_text) =
+ enriched_symbol_text(&name, start, selection_start, selection_end, snapshot)
+ .unwrap_or_else(|| {
+ let name_len = name.len();
+ (name.clone(), vec![0..name_len], selection_range.clone())
+ });
output.push(OutlineItem {
depth,
@@ -454,4 +450,50 @@ mod tests {
flatten_document_symbols(&symbols, &snapshot, 0, &mut items);
assert!(items.is_empty());
}
+
+ #[gpui::test]
+ async fn test_newlines_collapsed_in_name(cx: &mut TestAppContext) {
+ let buffer = cx.new(|cx| Buffer::local("x = 1\ny = 2\n", cx));
+
+ let symbols = vec![
+ make_symbol(
+ "line1\nline2",
+ lsp::SymbolKind::VARIABLE,
+ (0, 0)..(0, 5),
+ (0, 0)..(0, 1),
+ vec![],
+ ),
+ make_symbol(
+ " a \n b ",
+ lsp::SymbolKind::VARIABLE,
+ (1, 0)..(1, 5),
+ (1, 0)..(1, 1),
+ vec![],
+ ),
+ make_symbol(
+ "a\r\nb",
+ lsp::SymbolKind::VARIABLE,
+ (0, 0)..(1, 5),
+ (0, 0)..(0, 1),
+ vec![],
+ ),
+ make_symbol(
+ "a\n\nb",
+ lsp::SymbolKind::VARIABLE,
+ (0, 0)..(1, 5),
+ (0, 0)..(0, 1),
+ vec![],
+ ),
+ ];
+
+ let snapshot = buffer.read_with(cx, |buffer, _| buffer.snapshot());
+ let mut items = Vec::new();
+ flatten_document_symbols(&symbols, &snapshot, 0, &mut items);
+
+ assert_eq!(items.len(), 4);
+ assert_eq!(items[0].text, "line1 line2");
+ assert_eq!(items[1].text, "a b");
+ assert_eq!(items[2].text, "a b");
+ assert_eq!(items[3].text, "a b");
+ }
}