diff options
Diffstat (limited to 'crates/ra_lsp_server/src/main_loop')
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/handlers.rs | 73 |
1 files changed, 50 insertions, 23 deletions
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 3b7a14a5c..b5792f3b8 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs | |||
@@ -6,9 +6,8 @@ use languageserver_types::{ | |||
6 | DiagnosticSeverity, DocumentSymbol, Documentation, FoldingRange, FoldingRangeKind, | 6 | DiagnosticSeverity, DocumentSymbol, Documentation, FoldingRange, FoldingRangeKind, |
7 | FoldingRangeParams, Location, MarkupContent, MarkupKind, MarkedString, Position, | 7 | FoldingRangeParams, Location, MarkupContent, MarkupKind, MarkedString, Position, |
8 | PrepareRenameResponse, RenameParams, SymbolInformation, TextDocumentIdentifier, TextEdit, | 8 | PrepareRenameResponse, RenameParams, SymbolInformation, TextDocumentIdentifier, TextEdit, |
9 | Range, | 9 | Range, WorkspaceEdit, ParameterInformation, ParameterLabel, SignatureInformation, Hover, |
10 | WorkspaceEdit, ParameterInformation, ParameterLabel, SignatureInformation, Hover, HoverContents, | 10 | HoverContents, DocumentFormattingParams, DocumentHighlight, |
11 | DocumentFormattingParams, | ||
12 | }; | 11 | }; |
13 | use ra_analysis::{FileId, FoldKind, Query, RunnableKind, FileRange, FilePosition, Severity}; | 12 | use ra_analysis::{FileId, FoldKind, Query, RunnableKind, FileRange, FilePosition, Severity}; |
14 | use ra_syntax::{TextUnit, text_utils::intersect}; | 13 | use ra_syntax::{TextUnit, text_utils::intersect}; |
@@ -189,12 +188,11 @@ pub fn handle_workspace_symbol( | |||
189 | 188 | ||
190 | fn exec_query(world: &ServerWorld, query: Query) -> Result<Vec<SymbolInformation>> { | 189 | fn exec_query(world: &ServerWorld, query: Query) -> Result<Vec<SymbolInformation>> { |
191 | let mut res = Vec::new(); | 190 | let mut res = Vec::new(); |
192 | for (file_id, symbol) in world.analysis().symbol_search(query)? { | 191 | for nav in world.analysis().symbol_search(query)? { |
193 | let line_index = world.analysis().file_line_index(file_id); | ||
194 | let info = SymbolInformation { | 192 | let info = SymbolInformation { |
195 | name: symbol.name.to_string(), | 193 | name: nav.name().to_string(), |
196 | kind: symbol.kind.conv(), | 194 | kind: nav.kind().conv(), |
197 | location: to_location(file_id, symbol.node_range, world, &line_index)?, | 195 | location: nav.try_conv_with(world)?, |
198 | container_name: None, | 196 | container_name: None, |
199 | deprecated: None, | 197 | deprecated: None, |
200 | }; | 198 | }; |
@@ -213,12 +211,11 @@ pub fn handle_goto_definition( | |||
213 | None => return Ok(None), | 211 | None => return Ok(None), |
214 | Some(it) => it, | 212 | Some(it) => it, |
215 | }; | 213 | }; |
216 | let mut res = Vec::new(); | 214 | let res = rr |
217 | for (file_id, symbol) in rr.resolves_to { | 215 | .resolves_to |
218 | let line_index = world.analysis().file_line_index(file_id); | 216 | .into_iter() |
219 | let location = to_location(file_id, symbol.node_range, &world, &line_index)?; | 217 | .map(|nav| nav.try_conv_with(&world)) |
220 | res.push(location) | 218 | .collect::<Result<Vec<_>>>()?; |
221 | } | ||
222 | Ok(Some(req::GotoDefinitionResponse::Array(res))) | 219 | Ok(Some(req::GotoDefinitionResponse::Array(res))) |
223 | } | 220 | } |
224 | 221 | ||
@@ -227,13 +224,12 @@ pub fn handle_parent_module( | |||
227 | params: req::TextDocumentPositionParams, | 224 | params: req::TextDocumentPositionParams, |
228 | ) -> Result<Vec<Location>> { | 225 | ) -> Result<Vec<Location>> { |
229 | let position = params.try_conv_with(&world)?; | 226 | let position = params.try_conv_with(&world)?; |
230 | let mut res = Vec::new(); | 227 | world |
231 | for (file_id, symbol) in world.analysis().parent_module(position)? { | 228 | .analysis() |
232 | let line_index = world.analysis().file_line_index(file_id); | 229 | .parent_module(position)? |
233 | let location = to_location(file_id, symbol.node_range, &world, &line_index)?; | 230 | .into_iter() |
234 | res.push(location); | 231 | .map(|nav| nav.try_conv_with(&world)) |
235 | } | 232 | .collect::<Result<Vec<_>>>() |
236 | Ok(res) | ||
237 | } | 233 | } |
238 | 234 | ||
239 | pub fn handle_runnables( | 235 | pub fn handle_runnables( |
@@ -257,6 +253,7 @@ pub fn handle_runnables( | |||
257 | range: runnable.range.conv_with(&line_index), | 253 | range: runnable.range.conv_with(&line_index), |
258 | label: match &runnable.kind { | 254 | label: match &runnable.kind { |
259 | RunnableKind::Test { name } => format!("test {}", name), | 255 | RunnableKind::Test { name } => format!("test {}", name), |
256 | RunnableKind::TestMod { path } => format!("test-mod {}", path), | ||
260 | RunnableKind::Bin => "run binary".to_string(), | 257 | RunnableKind::Bin => "run binary".to_string(), |
261 | }, | 258 | }, |
262 | bin: "cargo".to_string(), | 259 | bin: "cargo".to_string(), |
@@ -308,6 +305,15 @@ pub fn handle_runnables( | |||
308 | res.push(name.to_string()); | 305 | res.push(name.to_string()); |
309 | res.push("--nocapture".to_string()); | 306 | res.push("--nocapture".to_string()); |
310 | } | 307 | } |
308 | RunnableKind::TestMod { path } => { | ||
309 | res.push("test".to_string()); | ||
310 | if let Some(spec) = spec { | ||
311 | spec.push_to(&mut res); | ||
312 | } | ||
313 | res.push("--".to_string()); | ||
314 | res.push(path.to_string()); | ||
315 | res.push("--nocapture".to_string()); | ||
316 | } | ||
311 | RunnableKind::Bin => { | 317 | RunnableKind::Bin => { |
312 | res.push("run".to_string()); | 318 | res.push("run".to_string()); |
313 | if let Some(spec) = spec { | 319 | if let Some(spec) = spec { |
@@ -508,8 +514,8 @@ pub fn handle_hover( | |||
508 | Some(it) => it, | 514 | Some(it) => it, |
509 | }; | 515 | }; |
510 | let mut result = Vec::new(); | 516 | let mut result = Vec::new(); |
511 | for (file_id, symbol) in rr.resolves_to { | 517 | for nav in rr.resolves_to { |
512 | if let Some(docs) = world.analysis().doc_text_for(file_id, symbol)? { | 518 | if let Some(docs) = world.analysis().doc_text_for(nav)? { |
513 | result.push(docs); | 519 | result.push(docs); |
514 | } | 520 | } |
515 | } | 521 | } |
@@ -668,6 +674,27 @@ pub fn handle_code_action( | |||
668 | Ok(Some(CodeActionResponse::Commands(res))) | 674 | Ok(Some(CodeActionResponse::Commands(res))) |
669 | } | 675 | } |
670 | 676 | ||
677 | pub fn handle_document_highlight( | ||
678 | world: ServerWorld, | ||
679 | params: req::TextDocumentPositionParams, | ||
680 | ) -> Result<Option<Vec<DocumentHighlight>>> { | ||
681 | let file_id = params.text_document.try_conv_with(&world)?; | ||
682 | let line_index = world.analysis().file_line_index(file_id); | ||
683 | |||
684 | let refs = world | ||
685 | .analysis() | ||
686 | .find_all_refs(params.try_conv_with(&world)?)?; | ||
687 | |||
688 | Ok(Some( | ||
689 | refs.into_iter() | ||
690 | .map(|r| DocumentHighlight { | ||
691 | range: r.1.conv_with(&line_index), | ||
692 | kind: None, | ||
693 | }) | ||
694 | .collect(), | ||
695 | )) | ||
696 | } | ||
697 | |||
671 | pub fn publish_diagnostics( | 698 | pub fn publish_diagnostics( |
672 | world: &ServerWorld, | 699 | world: &ServerWorld, |
673 | file_id: FileId, | 700 | file_id: FileId, |