aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server
diff options
context:
space:
mode:
authorJeremy A. Kolb <[email protected]>2018-10-18 18:40:12 +0100
committerJeremy A. Kolb <[email protected]>2018-10-18 18:40:12 +0100
commit3746689e9ddea455d10a41d9fc3af33b22a3707d (patch)
tree04c4e94e40f5496d961ca2f3dc649da1dd84604e /crates/ra_lsp_server
parent2a704035f4b36a0db737f59a7c939d17656b516f (diff)
Implement Find All References for local variables
Diffstat (limited to 'crates/ra_lsp_server')
-rw-r--r--crates/ra_lsp_server/src/caps.rs2
-rw-r--r--crates/ra_lsp_server/src/main_loop/handlers.rs16
-rw-r--r--crates/ra_lsp_server/src/main_loop/mod.rs1
-rw-r--r--crates/ra_lsp_server/src/req.rs2
4 files changed, 19 insertions, 2 deletions
diff --git a/crates/ra_lsp_server/src/caps.rs b/crates/ra_lsp_server/src/caps.rs
index 1dd495791..84c43bbec 100644
--- a/crates/ra_lsp_server/src/caps.rs
+++ b/crates/ra_lsp_server/src/caps.rs
@@ -27,7 +27,7 @@ pub fn server_capabilities() -> ServerCapabilities {
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: None,
30 references_provider: None, 30 references_provider: Some(true),
31 document_highlight_provider: None, 31 document_highlight_provider: None,
32 document_symbol_provider: Some(true), 32 document_symbol_provider: Some(true),
33 workspace_symbol_provider: Some(true), 33 workspace_symbol_provider: Some(true),
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs
index c25b63852..9b8d40eaa 100644
--- a/crates/ra_lsp_server/src/main_loop/handlers.rs
+++ b/crates/ra_lsp_server/src/main_loop/handlers.rs
@@ -460,6 +460,22 @@ pub fn handle_signature_help(
460 } 460 }
461} 461}
462 462
463pub fn handle_references(
464 world: ServerWorld,
465 params: req::ReferenceParams,
466 token: JobToken,
467) -> Result<Option<Vec<Location>>> {
468 let file_id = params.text_document.try_conv_with(&world)?;
469 let line_index = world.analysis().file_line_index(file_id);
470 let offset = params.position.conv_with(&line_index);
471
472 let refs = world.analysis().find_all_refs(file_id, offset, &token);
473
474 Ok(Some(refs.into_iter()
475 .filter_map(|r| to_location(r.0, r.1, &world, &line_index).ok())
476 .collect()))
477}
478
463pub fn handle_code_action( 479pub fn handle_code_action(
464 world: ServerWorld, 480 world: ServerWorld,
465 params: req::CodeActionParams, 481 params: req::CodeActionParams,
diff --git a/crates/ra_lsp_server/src/main_loop/mod.rs b/crates/ra_lsp_server/src/main_loop/mod.rs
index a11baf4aa..7efec8a7a 100644
--- a/crates/ra_lsp_server/src/main_loop/mod.rs
+++ b/crates/ra_lsp_server/src/main_loop/mod.rs
@@ -248,6 +248,7 @@ fn on_request(
248 .on::<req::CodeActionRequest>(handlers::handle_code_action)? 248 .on::<req::CodeActionRequest>(handlers::handle_code_action)?
249 .on::<req::FoldingRangeRequest>(handlers::handle_folding_range)? 249 .on::<req::FoldingRangeRequest>(handlers::handle_folding_range)?
250 .on::<req::SignatureHelpRequest>(handlers::handle_signature_help)? 250 .on::<req::SignatureHelpRequest>(handlers::handle_signature_help)?
251 .on::<req::References>(handlers::handle_references)?
251 .finish(); 252 .finish();
252 match req { 253 match req {
253 Ok((id, handle)) => { 254 Ok((id, handle)) => {
diff --git a/crates/ra_lsp_server/src/req.rs b/crates/ra_lsp_server/src/req.rs
index b76bfbcbc..6cd04d84c 100644
--- a/crates/ra_lsp_server/src/req.rs
+++ b/crates/ra_lsp_server/src/req.rs
@@ -7,7 +7,7 @@ pub use languageserver_types::{
7 CompletionResponse, DocumentOnTypeFormattingParams, DocumentSymbolParams, 7 CompletionResponse, DocumentOnTypeFormattingParams, DocumentSymbolParams,
8 DocumentSymbolResponse, ExecuteCommandParams, Hover, InitializeResult, 8 DocumentSymbolResponse, ExecuteCommandParams, Hover, InitializeResult,
9 PublishDiagnosticsParams, SignatureHelp, TextDocumentEdit, TextDocumentPositionParams, 9 PublishDiagnosticsParams, SignatureHelp, TextDocumentEdit, TextDocumentPositionParams,
10 TextEdit, WorkspaceSymbolParams, 10 TextEdit, WorkspaceSymbolParams, ReferenceParams,
11}; 11};
12 12
13pub enum SyntaxTree {} 13pub enum SyntaxTree {}