aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_lsp_server')
-rw-r--r--crates/ra_lsp_server/src/conv.rs19
-rw-r--r--crates/ra_lsp_server/src/lib.rs1
-rw-r--r--crates/ra_lsp_server/src/main_loop/handlers.rs11
-rw-r--r--crates/ra_lsp_server/src/markdown.rs38
4 files changed, 54 insertions, 15 deletions
diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs
index 8c87f5195..c033ecdea 100644
--- a/crates/ra_lsp_server/src/conv.rs
+++ b/crates/ra_lsp_server/src/conv.rs
@@ -87,13 +87,6 @@ impl ConvWith for CompletionItem {
87 None 87 None
88 }; 88 };
89 89
90 let documentation = self.documentation().map(|value| {
91 Documentation::MarkupContent(MarkupContent {
92 kind: MarkupKind::Markdown,
93 value: value.to_string(),
94 })
95 });
96
97 let mut res = lsp_types::CompletionItem { 90 let mut res = lsp_types::CompletionItem {
98 label: self.label().to_string(), 91 label: self.label().to_string(),
99 detail: self.detail().map(|it| it.to_string()), 92 detail: self.detail().map(|it| it.to_string()),
@@ -101,7 +94,7 @@ impl ConvWith for CompletionItem {
101 kind: self.kind().map(|it| it.conv()), 94 kind: self.kind().map(|it| it.conv()),
102 text_edit: Some(text_edit), 95 text_edit: Some(text_edit),
103 additional_text_edits, 96 additional_text_edits,
104 documentation: documentation, 97 documentation: self.documentation().map(|it| it.conv()),
105 ..Default::default() 98 ..Default::default()
106 }; 99 };
107 res.insert_text_format = Some(match self.insert_text_format() { 100 res.insert_text_format = Some(match self.insert_text_format() {
@@ -160,6 +153,16 @@ impl ConvWith for Range {
160 } 153 }
161} 154}
162 155
156impl Conv for ra_ide_api::Documentation {
157 type Output = lsp_types::Documentation;
158 fn conv(self) -> Documentation {
159 Documentation::MarkupContent(MarkupContent {
160 kind: MarkupKind::Markdown,
161 value: crate::markdown::sanitize_markdown(self).into(),
162 })
163 }
164}
165
163impl ConvWith for TextEdit { 166impl ConvWith for TextEdit {
164 type Ctx = LineIndex; 167 type Ctx = LineIndex;
165 type Output = Vec<lsp_types::TextEdit>; 168 type Output = Vec<lsp_types::TextEdit>;
diff --git a/crates/ra_lsp_server/src/lib.rs b/crates/ra_lsp_server/src/lib.rs
index f93d4b37d..5b5f3b948 100644
--- a/crates/ra_lsp_server/src/lib.rs
+++ b/crates/ra_lsp_server/src/lib.rs
@@ -2,6 +2,7 @@ mod caps;
2mod cargo_target_spec; 2mod cargo_target_spec;
3mod conv; 3mod conv;
4mod main_loop; 4mod main_loop;
5mod markdown;
5mod project_model; 6mod project_model;
6pub mod req; 7pub mod req;
7mod server_world; 8mod server_world;
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs
index 9478ebfb8..4f75f9a22 100644
--- a/crates/ra_lsp_server/src/main_loop/handlers.rs
+++ b/crates/ra_lsp_server/src/main_loop/handlers.rs
@@ -1,7 +1,7 @@
1use gen_lsp_server::ErrorCode; 1use gen_lsp_server::ErrorCode;
2use lsp_types::{ 2use lsp_types::{
3 CodeActionResponse, CodeLens, Command, Diagnostic, DiagnosticSeverity, 3 CodeActionResponse, CodeLens, Command, Diagnostic, DiagnosticSeverity,
4 DocumentFormattingParams, DocumentHighlight, DocumentSymbol, Documentation, FoldingRange, 4 DocumentFormattingParams, DocumentHighlight, DocumentSymbol, FoldingRange,
5 FoldingRangeKind, FoldingRangeParams, Hover, HoverContents, Location, MarkupContent, 5 FoldingRangeKind, FoldingRangeParams, Hover, HoverContents, Location, MarkupContent,
6 MarkupKind, ParameterInformation, ParameterLabel, Position, PrepareRenameResponse, Range, 6 MarkupKind, ParameterInformation, ParameterLabel, Position, PrepareRenameResponse, Range,
7 RenameParams, SignatureInformation, SymbolInformation, TextDocumentIdentifier, TextEdit, 7 RenameParams, SignatureInformation, SymbolInformation, TextDocumentIdentifier, TextEdit,
@@ -401,12 +401,9 @@ pub fn handle_signature_help(
401 documentation: None, 401 documentation: None,
402 }) 402 })
403 .collect(); 403 .collect();
404 let documentation = call_info.doc.map(|value| { 404
405 Documentation::MarkupContent(MarkupContent { 405 let documentation = call_info.doc.map(|it| it.conv());
406 kind: MarkupKind::Markdown, 406
407 value,
408 })
409 });
410 let sig_info = SignatureInformation { 407 let sig_info = SignatureInformation {
411 label: call_info.label, 408 label: call_info.label,
412 documentation, 409 documentation,
diff --git a/crates/ra_lsp_server/src/markdown.rs b/crates/ra_lsp_server/src/markdown.rs
new file mode 100644
index 000000000..f505755e8
--- /dev/null
+++ b/crates/ra_lsp_server/src/markdown.rs
@@ -0,0 +1,38 @@
1use ra_ide_api::Documentation;
2
3pub(crate) fn sanitize_markdown(docs: Documentation) -> Documentation {
4 let docs: String = docs.into();
5
6 // Massage markdown
7 let mut processed_lines = Vec::new();
8 let mut in_code_block = false;
9 for line in docs.lines() {
10 if line.starts_with("```") {
11 in_code_block = !in_code_block;
12 }
13
14 let line = if in_code_block && line.starts_with("```") && !line.contains("rust") {
15 "```rust".into()
16 } else {
17 line.to_string()
18 };
19
20 processed_lines.push(line);
21 }
22
23 Documentation::new(&processed_lines.join("\n"))
24}
25
26#[cfg(test)]
27mod tests {
28 use super::*;
29
30 #[test]
31 fn test_codeblock_adds_rust() {
32 let comment = "```\nfn some_rust() {}\n```";
33 assert_eq!(
34 sanitize_markdown(Documentation::new(comment)).contents(),
35 "```rust\nfn some_rust() {}\n```"
36 );
37 }
38}