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/Cargo.toml3
-rw-r--r--crates/ra_lsp_server/src/caps.rs4
-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.rs4
-rw-r--r--crates/ra_lsp_server/src/main_loop/handlers.rs35
-rw-r--r--crates/ra_lsp_server/src/markdown.rs38
-rw-r--r--crates/ra_lsp_server/src/req.rs24
-rw-r--r--crates/ra_lsp_server/src/server_world.rs6
-rw-r--r--crates/ra_lsp_server/tests/heavy_tests/main.rs2
10 files changed, 102 insertions, 34 deletions
diff --git a/crates/ra_lsp_server/Cargo.toml b/crates/ra_lsp_server/Cargo.toml
index 160d2f672..bb92747f2 100644
--- a/crates/ra_lsp_server/Cargo.toml
+++ b/crates/ra_lsp_server/Cargo.toml
@@ -34,3 +34,6 @@ ra_vfs = { path = "../ra_vfs" }
34[dev-dependencies] 34[dev-dependencies]
35tempfile = "3" 35tempfile = "3"
36test_utils = { path = "../test_utils" } 36test_utils = { path = "../test_utils" }
37
38[features]
39jemalloc = [ "ra_ide_api/jemalloc" ]
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
8pub fn server_capabilities() -> ServerCapabilities { 8pub 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
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.rs b/crates/ra_lsp_server/src/main_loop.rs
index ddd20a41f..df390c19e 100644
--- a/crates/ra_lsp_server/src/main_loop.rs
+++ b/crates/ra_lsp_server/src/main_loop.rs
@@ -172,6 +172,7 @@ fn main_loop_inner(
172 172
173 let (libdata_sender, libdata_receiver) = unbounded(); 173 let (libdata_sender, libdata_receiver) = unbounded();
174 loop { 174 loop {
175 state.maybe_collect_garbage();
175 log::trace!("selecting"); 176 log::trace!("selecting");
176 let event = select! { 177 let event = select! {
177 recv(msg_receiver) -> msg => match msg { 178 recv(msg_receiver) -> msg => match msg {
@@ -207,7 +208,7 @@ fn main_loop_inner(
207 }; 208 };
208 match req.cast::<req::CollectGarbage>() { 209 match req.cast::<req::CollectGarbage>() {
209 Ok((id, ())) => { 210 Ok((id, ())) => {
210 state.collect_garbadge(); 211 state.collect_garbage();
211 let resp = RawResponse::ok::<req::CollectGarbage>(id, &()); 212 let resp = RawResponse::ok::<req::CollectGarbage>(id, &());
212 msg_sender.send(RawMessage::Response(resp)).unwrap() 213 msg_sender.send(RawMessage::Response(resp)).unwrap()
213 } 214 }
@@ -304,6 +305,7 @@ fn on_request(
304 .on::<req::DocumentSymbolRequest>(handlers::handle_document_symbol)? 305 .on::<req::DocumentSymbolRequest>(handlers::handle_document_symbol)?
305 .on::<req::WorkspaceSymbol>(handlers::handle_workspace_symbol)? 306 .on::<req::WorkspaceSymbol>(handlers::handle_workspace_symbol)?
306 .on::<req::GotoDefinition>(handlers::handle_goto_definition)? 307 .on::<req::GotoDefinition>(handlers::handle_goto_definition)?
308 .on::<req::GotoImplementation>(handlers::handle_goto_implementation)?
307 .on::<req::ParentModule>(handlers::handle_parent_module)? 309 .on::<req::ParentModule>(handlers::handle_parent_module)?
308 .on::<req::Runnables>(handlers::handle_runnables)? 310 .on::<req::Runnables>(handlers::handle_runnables)?
309 .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 ace3da020..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 @@
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,
@@ -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
232pub 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
232pub fn handle_parent_module( 252pub 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,
@@ -581,7 +598,7 @@ pub fn handle_code_action(
581 let edit = source_edit.try_conv_with(&world)?; 598 let edit = source_edit.try_conv_with(&world)?;
582 let cmd = Command { 599 let cmd = Command {
583 title, 600 title,
584 command: "ra-lsp.applySourceChange".to_string(), 601 command: "rust-analyzer.applySourceChange".to_string(),
585 arguments: Some(vec![to_value(edit).unwrap()]), 602 arguments: Some(vec![to_value(edit).unwrap()]),
586 }; 603 };
587 res.push(cmd); 604 res.push(cmd);
@@ -623,7 +640,7 @@ pub fn handle_code_lens(
623 range, 640 range,
624 command: Some(Command { 641 command: Some(Command {
625 title: title.into(), 642 title: title.into(),
626 command: "ra-lsp.run-single".into(), 643 command: "rust-analyzer.runSingle".into(),
627 arguments: Some(vec![to_value(r).unwrap()]), 644 arguments: Some(vec![to_value(r).unwrap()]),
628 }), 645 }),
629 data: None, 646 data: None,
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}
diff --git a/crates/ra_lsp_server/src/req.rs b/crates/ra_lsp_server/src/req.rs
index 5968e592b..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
14pub enum AnalyzerStatus {} 14pub enum AnalyzerStatus {}
@@ -16,7 +16,7 @@ pub enum AnalyzerStatus {}
16impl Request for AnalyzerStatus { 16impl Request for AnalyzerStatus {
17 type Params = (); 17 type Params = ();
18 type Result = String; 18 type Result = String;
19 const METHOD: &'static str = "ra/analyzerStatus"; 19 const METHOD: &'static str = "rust-analyzer/analyzerStatus";
20} 20}
21 21
22pub enum CollectGarbage {} 22pub enum CollectGarbage {}
@@ -24,7 +24,7 @@ pub enum CollectGarbage {}
24impl Request for CollectGarbage { 24impl Request for CollectGarbage {
25 type Params = (); 25 type Params = ();
26 type Result = (); 26 type Result = ();
27 const METHOD: &'static str = "ra/collectGarbage"; 27 const METHOD: &'static str = "rust-analyzer/collectGarbage";
28} 28}
29 29
30pub enum SyntaxTree {} 30pub enum SyntaxTree {}
@@ -32,7 +32,7 @@ pub enum SyntaxTree {}
32impl Request for SyntaxTree { 32impl Request for SyntaxTree {
33 type Params = SyntaxTreeParams; 33 type Params = SyntaxTreeParams;
34 type Result = String; 34 type Result = String;
35 const METHOD: &'static str = "m/syntaxTree"; 35 const METHOD: &'static str = "rust-analyzer/syntaxTree";
36} 36}
37 37
38#[derive(Deserialize, Debug)] 38#[derive(Deserialize, Debug)]
@@ -46,7 +46,7 @@ pub enum ExtendSelection {}
46impl Request for ExtendSelection { 46impl Request for ExtendSelection {
47 type Params = ExtendSelectionParams; 47 type Params = ExtendSelectionParams;
48 type Result = ExtendSelectionResult; 48 type Result = ExtendSelectionResult;
49 const METHOD: &'static str = "m/extendSelection"; 49 const METHOD: &'static str = "rust-analyzer/extendSelection";
50} 50}
51 51
52#[derive(Deserialize, Debug)] 52#[derive(Deserialize, Debug)]
@@ -67,7 +67,7 @@ pub enum FindMatchingBrace {}
67impl Request for FindMatchingBrace { 67impl Request for FindMatchingBrace {
68 type Params = FindMatchingBraceParams; 68 type Params = FindMatchingBraceParams;
69 type Result = Vec<Position>; 69 type Result = Vec<Position>;
70 const METHOD: &'static str = "m/findMatchingBrace"; 70 const METHOD: &'static str = "rust-analyzer/findMatchingBrace";
71} 71}
72 72
73#[derive(Deserialize, Debug)] 73#[derive(Deserialize, Debug)]
@@ -82,14 +82,14 @@ pub enum DecorationsRequest {}
82impl Request for DecorationsRequest { 82impl Request for DecorationsRequest {
83 type Params = TextDocumentIdentifier; 83 type Params = TextDocumentIdentifier;
84 type Result = Vec<Decoration>; 84 type Result = Vec<Decoration>;
85 const METHOD: &'static str = "m/decorationsRequest"; 85 const METHOD: &'static str = "rust-analyzer/decorationsRequest";
86} 86}
87 87
88pub enum PublishDecorations {} 88pub enum PublishDecorations {}
89 89
90impl Notification for PublishDecorations { 90impl Notification for PublishDecorations {
91 type Params = PublishDecorationsParams; 91 type Params = PublishDecorationsParams;
92 const METHOD: &'static str = "m/publishDecorations"; 92 const METHOD: &'static str = "rust-analyzer/publishDecorations";
93} 93}
94 94
95#[derive(Serialize, Debug)] 95#[derive(Serialize, Debug)]
@@ -112,7 +112,7 @@ pub enum ParentModule {}
112impl Request for ParentModule { 112impl Request for ParentModule {
113 type Params = TextDocumentPositionParams; 113 type Params = TextDocumentPositionParams;
114 type Result = Vec<Location>; 114 type Result = Vec<Location>;
115 const METHOD: &'static str = "m/parentModule"; 115 const METHOD: &'static str = "rust-analyzer/parentModule";
116} 116}
117 117
118pub enum JoinLines {} 118pub enum JoinLines {}
@@ -120,7 +120,7 @@ pub enum JoinLines {}
120impl Request for JoinLines { 120impl Request for JoinLines {
121 type Params = JoinLinesParams; 121 type Params = JoinLinesParams;
122 type Result = SourceChange; 122 type Result = SourceChange;
123 const METHOD: &'static str = "m/joinLines"; 123 const METHOD: &'static str = "rust-analyzer/joinLines";
124} 124}
125 125
126#[derive(Deserialize, Debug)] 126#[derive(Deserialize, Debug)]
@@ -135,7 +135,7 @@ pub enum OnEnter {}
135impl Request for OnEnter { 135impl Request for OnEnter {
136 type Params = TextDocumentPositionParams; 136 type Params = TextDocumentPositionParams;
137 type Result = Option<SourceChange>; 137 type Result = Option<SourceChange>;
138 const METHOD: &'static str = "m/onEnter"; 138 const METHOD: &'static str = "rust-analyzer/onEnter";
139} 139}
140 140
141pub enum Runnables {} 141pub enum Runnables {}
@@ -143,7 +143,7 @@ pub enum Runnables {}
143impl Request for Runnables { 143impl Request for Runnables {
144 type Params = RunnablesParams; 144 type Params = RunnablesParams;
145 type Result = Vec<Runnable>; 145 type Result = Vec<Runnable>;
146 const METHOD: &'static str = "m/runnables"; 146 const METHOD: &'static str = "rust-analyzer/runnables";
147} 147}
148 148
149#[derive(Serialize, Deserialize, Debug)] 149#[derive(Serialize, Deserialize, Debug)]
diff --git a/crates/ra_lsp_server/src/server_world.rs b/crates/ra_lsp_server/src/server_world.rs
index bf04f1125..c2167c5d8 100644
--- a/crates/ra_lsp_server/src/server_world.rs
+++ b/crates/ra_lsp_server/src/server_world.rs
@@ -232,7 +232,11 @@ impl ServerWorldState {
232 } 232 }
233 } 233 }
234 234
235 pub fn collect_garbadge(&mut self) { 235 pub fn maybe_collect_garbage(&mut self) {
236 self.analysis_host.maybe_collect_garbage()
237 }
238
239 pub fn collect_garbage(&mut self) {
236 self.analysis_host.collect_garbage() 240 self.analysis_host.collect_garbage()
237 } 241 }
238} 242}
diff --git a/crates/ra_lsp_server/tests/heavy_tests/main.rs b/crates/ra_lsp_server/tests/heavy_tests/main.rs
index 8b5c43a09..bfb0645a8 100644
--- a/crates/ra_lsp_server/tests/heavy_tests/main.rs
+++ b/crates/ra_lsp_server/tests/heavy_tests/main.rs
@@ -246,7 +246,7 @@ fn main() {}
246 "label": "create module" 246 "label": "create module"
247 } 247 }
248 ], 248 ],
249 "command": "ra-lsp.applySourceChange", 249 "command": "rust-analyzer.applySourceChange",
250 "title": "create module" 250 "title": "create module"
251 } 251 }
252 ]), 252 ]),