Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

project: Sanitize single-line completions from trailing newlines (#44965)

prayansh_chhablani6d776c3157a3
diff --git a/crates/project/src/lsp_store.rs b/crates/project/src/lsp_store.rs
index 7e8624daad6..5841be02b2d 100644
--- a/crates/project/src/lsp_store.rs
+++ b/crates/project/src/lsp_store.rs
@@ -13776,7 +13776,7 @@ impl From<lsp::Documentation> for CompletionDocumentation {
match docs {
lsp::Documentation::String(text) => {
if text.lines().count() <= 1 {
- CompletionDocumentation::SingleLine(text.into())
+ CompletionDocumentation::SingleLine(text.trim().to_string().into())
} else {
CompletionDocumentation::MultiLinePlainText(text.into())
}
@@ -14368,4 +14368,22 @@ mod tests {
)
);
}
+
+ #[test]
+ fn test_trailing_newline_in_completion_documentation() {
+ let doc = lsp::Documentation::String(
+ "Inappropriate argument value (of correct type).\n".to_string(),
+ );
+ let completion_doc: CompletionDocumentation = doc.into();
+ assert!(
+ matches!(completion_doc, CompletionDocumentation::SingleLine(s) if s == "Inappropriate argument value (of correct type).")
+ );
+
+ let doc = lsp::Documentation::String(" some value \n".to_string());
+ let completion_doc: CompletionDocumentation = doc.into();
+ assert!(matches!(
+ completion_doc,
+ CompletionDocumentation::SingleLine(s) if s == "some value"
+ ));
+ }
}