aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2018-12-31 12:37:05 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2018-12-31 12:37:05 +0000
commit2746dacac02d56854e9aa31877730eb9e83628d5 (patch)
tree3dfe2f9e21f4a421268e480d9759a70dc8a1e2e2
parent81acdafc518f858db38f1a3d78d9ff498c989176 (diff)
parentbe75e547ce13dea281d2787ef5280637e76f6156 (diff)
Merge #385
385: Implement DocumentHighlight r=matklad a=DJMcNab Fixes #80. Co-authored-by: DJMcNab <[email protected]>
-rw-r--r--crates/ra_lsp_server/src/caps.rs2
-rw-r--r--crates/ra_lsp_server/src/main_loop.rs1
-rw-r--r--crates/ra_lsp_server/src/main_loop/handlers.rs26
3 files changed, 25 insertions, 4 deletions
diff --git a/crates/ra_lsp_server/src/caps.rs b/crates/ra_lsp_server/src/caps.rs
index 8d508a3ba..a74f9f27b 100644
--- a/crates/ra_lsp_server/src/caps.rs
+++ b/crates/ra_lsp_server/src/caps.rs
@@ -28,7 +28,7 @@ pub fn server_capabilities() -> ServerCapabilities {
28 type_definition_provider: None, 28 type_definition_provider: None,
29 implementation_provider: None, 29 implementation_provider: None,
30 references_provider: Some(true), 30 references_provider: Some(true),
31 document_highlight_provider: None, 31 document_highlight_provider: Some(true),
32 document_symbol_provider: Some(true), 32 document_symbol_provider: Some(true),
33 workspace_symbol_provider: Some(true), 33 workspace_symbol_provider: Some(true),
34 code_action_provider: Some(CodeActionProviderCapability::Simple(true)), 34 code_action_provider: Some(CodeActionProviderCapability::Simple(true)),
diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs
index d425b6733..06dd373c0 100644
--- a/crates/ra_lsp_server/src/main_loop.rs
+++ b/crates/ra_lsp_server/src/main_loop.rs
@@ -300,6 +300,7 @@ fn on_request(
300 .on::<req::Rename>(handlers::handle_rename)? 300 .on::<req::Rename>(handlers::handle_rename)?
301 .on::<req::References>(handlers::handle_references)? 301 .on::<req::References>(handlers::handle_references)?
302 .on::<req::Formatting>(handlers::handle_formatting)? 302 .on::<req::Formatting>(handlers::handle_formatting)?
303 .on::<req::DocumentHighlightRequest>(handlers::handle_document_highlight)?
303 .finish(); 304 .finish();
304 match req { 305 match req {
305 Ok(id) => { 306 Ok(id) => {
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs
index 3b7a14a5c..012f74270 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};
13use ra_analysis::{FileId, FoldKind, Query, RunnableKind, FileRange, FilePosition, Severity}; 12use ra_analysis::{FileId, FoldKind, Query, RunnableKind, FileRange, FilePosition, Severity};
14use ra_syntax::{TextUnit, text_utils::intersect}; 13use ra_syntax::{TextUnit, text_utils::intersect};
@@ -668,6 +667,27 @@ pub fn handle_code_action(
668 Ok(Some(CodeActionResponse::Commands(res))) 667 Ok(Some(CodeActionResponse::Commands(res)))
669} 668}
670 669
670pub fn handle_document_highlight(
671 world: ServerWorld,
672 params: req::TextDocumentPositionParams,
673) -> Result<Option<Vec<DocumentHighlight>>> {
674 let file_id = params.text_document.try_conv_with(&world)?;
675 let line_index = world.analysis().file_line_index(file_id);
676
677 let refs = world
678 .analysis()
679 .find_all_refs(params.try_conv_with(&world)?)?;
680
681 Ok(Some(
682 refs.into_iter()
683 .map(|r| DocumentHighlight {
684 range: r.1.conv_with(&line_index),
685 kind: None,
686 })
687 .collect(),
688 ))
689}
690
671pub fn publish_diagnostics( 691pub fn publish_diagnostics(
672 world: &ServerWorld, 692 world: &ServerWorld,
673 file_id: FileId, 693 file_id: FileId,