diff --git a/crates/project/src/lsp_store.rs b/crates/project/src/lsp_store.rs index 7e8624daad628fd653326647537eb51dad208a02..5841be02b2db80b2fa15667833b8a3d3eec4ec11 100644 --- a/crates/project/src/lsp_store.rs +++ b/crates/project/src/lsp_store.rs @@ -13776,7 +13776,7 @@ impl From 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" + )); + } }