diff options
Diffstat (limited to 'crates/ra_lsp_server')
-rw-r--r-- | crates/ra_lsp_server/src/caps.rs | 4 | ||||
-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.rs | 1 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/handlers.rs | 31 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/markdown.rs | 38 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/req.rs | 2 |
7 files changed, 78 insertions, 18 deletions
diff --git a/crates/ra_lsp_server/src/caps.rs b/crates/ra_lsp_server/src/caps.rs index bca079d65..254624487 100644 --- a/crates/ra_lsp_server/src/caps.rs +++ b/crates/ra_lsp_server/src/caps.rs | |||
@@ -2,7 +2,7 @@ use lsp_types::{ | |||
2 | CodeActionProviderCapability, CodeLensOptions, CompletionOptions, DocumentOnTypeFormattingOptions, | 2 | CodeActionProviderCapability, CodeLensOptions, CompletionOptions, DocumentOnTypeFormattingOptions, |
3 | ExecuteCommandOptions, FoldingRangeProviderCapability, RenameOptions, RenameProviderCapability, | 3 | ExecuteCommandOptions, FoldingRangeProviderCapability, RenameOptions, RenameProviderCapability, |
4 | ServerCapabilities, SignatureHelpOptions, TextDocumentSyncCapability, TextDocumentSyncKind, | 4 | ServerCapabilities, SignatureHelpOptions, TextDocumentSyncCapability, TextDocumentSyncKind, |
5 | TextDocumentSyncOptions, | 5 | TextDocumentSyncOptions, ImplementationProviderCapability, |
6 | }; | 6 | }; |
7 | 7 | ||
8 | pub fn server_capabilities() -> ServerCapabilities { | 8 | pub fn server_capabilities() -> ServerCapabilities { |
@@ -26,7 +26,7 @@ pub fn server_capabilities() -> ServerCapabilities { | |||
26 | }), | 26 | }), |
27 | definition_provider: Some(true), | 27 | definition_provider: Some(true), |
28 | type_definition_provider: None, | 28 | type_definition_provider: None, |
29 | implementation_provider: None, | 29 | implementation_provider: Some(ImplementationProviderCapability::Simple(true)), |
30 | references_provider: Some(true), | 30 | references_provider: Some(true), |
31 | document_highlight_provider: Some(true), | 31 | document_highlight_provider: Some(true), |
32 | document_symbol_provider: Some(true), | 32 | document_symbol_provider: Some(true), |
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.rs b/crates/ra_lsp_server/src/main_loop.rs index e430ac6de..df390c19e 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs | |||
@@ -305,6 +305,7 @@ fn on_request( | |||
305 | .on::<req::DocumentSymbolRequest>(handlers::handle_document_symbol)? | 305 | .on::<req::DocumentSymbolRequest>(handlers::handle_document_symbol)? |
306 | .on::<req::WorkspaceSymbol>(handlers::handle_workspace_symbol)? | 306 | .on::<req::WorkspaceSymbol>(handlers::handle_workspace_symbol)? |
307 | .on::<req::GotoDefinition>(handlers::handle_goto_definition)? | 307 | .on::<req::GotoDefinition>(handlers::handle_goto_definition)? |
308 | .on::<req::GotoImplementation>(handlers::handle_goto_implementation)? | ||
308 | .on::<req::ParentModule>(handlers::handle_parent_module)? | 309 | .on::<req::ParentModule>(handlers::handle_parent_module)? |
309 | .on::<req::Runnables>(handlers::handle_runnables)? | 310 | .on::<req::Runnables>(handlers::handle_runnables)? |
310 | .on::<req::DecorationsRequest>(handlers::handle_decorations)? | 311 | .on::<req::DecorationsRequest>(handlers::handle_decorations)? |
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 9478ebfb8..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, |
@@ -229,6 +229,26 @@ pub fn handle_goto_definition( | |||
229 | Ok(Some(req::GotoDefinitionResponse::Link(res))) | 229 | Ok(Some(req::GotoDefinitionResponse::Link(res))) |
230 | } | 230 | } |
231 | 231 | ||
232 | pub fn handle_goto_implementation( | ||
233 | world: ServerWorld, | ||
234 | params: req::TextDocumentPositionParams, | ||
235 | ) -> Result<Option<req::GotoImplementationResponse>> { | ||
236 | let position = params.try_conv_with(&world)?; | ||
237 | let line_index = world.analysis().file_line_index(position.file_id); | ||
238 | let nav_info = match world.analysis().goto_implementation(position)? { | ||
239 | None => return Ok(None), | ||
240 | Some(it) => it, | ||
241 | }; | ||
242 | let nav_range = nav_info.range; | ||
243 | let res = nav_info | ||
244 | .info | ||
245 | .into_iter() | ||
246 | .map(|nav| RangeInfo::new(nav_range, nav)) | ||
247 | .map(|nav| to_location_link(&nav, &world, &line_index)) | ||
248 | .collect::<Result<Vec<_>>>()?; | ||
249 | Ok(Some(req::GotoDefinitionResponse::Link(res))) | ||
250 | } | ||
251 | |||
232 | pub fn handle_parent_module( | 252 | pub fn handle_parent_module( |
233 | world: ServerWorld, | 253 | world: ServerWorld, |
234 | params: req::TextDocumentPositionParams, | 254 | params: req::TextDocumentPositionParams, |
@@ -401,12 +421,9 @@ pub fn handle_signature_help( | |||
401 | documentation: None, | 421 | documentation: None, |
402 | }) | 422 | }) |
403 | .collect(); | 423 | .collect(); |
404 | let documentation = call_info.doc.map(|value| { | 424 | |
405 | Documentation::MarkupContent(MarkupContent { | 425 | let documentation = call_info.doc.map(|it| it.conv()); |
406 | kind: MarkupKind::Markdown, | 426 | |
407 | value, | ||
408 | }) | ||
409 | }); | ||
410 | let sig_info = SignatureInformation { | 427 | let sig_info = SignatureInformation { |
411 | label: call_info.label, | 428 | label: call_info.label, |
412 | 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 | } | ||
diff --git a/crates/ra_lsp_server/src/req.rs b/crates/ra_lsp_server/src/req.rs index a4d890755..e224ede80 100644 --- a/crates/ra_lsp_server/src/req.rs +++ b/crates/ra_lsp_server/src/req.rs | |||
@@ -8,7 +8,7 @@ pub use lsp_types::{ | |||
8 | CompletionParams, CompletionResponse, DocumentOnTypeFormattingParams, DocumentSymbolParams, | 8 | CompletionParams, CompletionResponse, DocumentOnTypeFormattingParams, DocumentSymbolParams, |
9 | DocumentSymbolResponse, ExecuteCommandParams, Hover, InitializeResult, | 9 | DocumentSymbolResponse, ExecuteCommandParams, Hover, InitializeResult, |
10 | PublishDiagnosticsParams, ReferenceParams, SignatureHelp, TextDocumentEdit, | 10 | PublishDiagnosticsParams, ReferenceParams, SignatureHelp, TextDocumentEdit, |
11 | TextDocumentPositionParams, TextEdit, WorkspaceEdit, WorkspaceSymbolParams, | 11 | TextDocumentPositionParams, TextEdit, WorkspaceEdit, WorkspaceSymbolParams |
12 | }; | 12 | }; |
13 | 13 | ||
14 | pub enum AnalyzerStatus {} | 14 | pub enum AnalyzerStatus {} |