diff options
Diffstat (limited to 'crates/ra_lsp_server/src')
-rw-r--r-- | crates/ra_lsp_server/src/conv.rs | 19 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/lib.rs | 1 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/handlers.rs | 11 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/markdown.rs | 38 |
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 | ||
156 | impl 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 | |||
163 | impl ConvWith for TextEdit { | 166 | impl 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; | |||
2 | mod cargo_target_spec; | 2 | mod cargo_target_spec; |
3 | mod conv; | 3 | mod conv; |
4 | mod main_loop; | 4 | mod main_loop; |
5 | mod markdown; | ||
5 | mod project_model; | 6 | mod project_model; |
6 | pub mod req; | 7 | pub mod req; |
7 | mod server_world; | 8 | mod 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 e94d76903..74554f15c 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 @@ | |||
1 | use gen_lsp_server::ErrorCode; | 1 | use gen_lsp_server::ErrorCode; |
2 | use lsp_types::{ | 2 | use 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, |
@@ -421,12 +421,9 @@ pub fn handle_signature_help( | |||
421 | documentation: None, | 421 | documentation: None, |
422 | }) | 422 | }) |
423 | .collect(); | 423 | .collect(); |
424 | let documentation = call_info.doc.map(|value| { | 424 | |
425 | Documentation::MarkupContent(MarkupContent { | 425 | let documentation = call_info.doc.map(|it| it.conv()); |
426 | kind: MarkupKind::Markdown, | 426 | |
427 | value, | ||
428 | }) | ||
429 | }); | ||
430 | let sig_info = SignatureInformation { | 427 | let sig_info = SignatureInformation { |
431 | label: call_info.label, | 428 | label: call_info.label, |
432 | documentation, | 429 | 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 @@ | |||
1 | use ra_ide_api::Documentation; | ||
2 | |||
3 | pub(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)] | ||
27 | mod 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 | } | ||