From 79941a9e701c6be849d40cb43744f1e2fee56354 Mon Sep 17 00:00:00 2001 From: DJMcNab <36049421+DJMcNab@users.noreply.github.com> Date: Mon, 31 Dec 2018 11:08:44 +0000 Subject: Implement DocumentHighlight --- crates/ra_lsp_server/src/caps.rs | 2 +- crates/ra_lsp_server/src/main_loop.rs | 1 + crates/ra_lsp_server/src/main_loop/handlers.rs | 27 +++++++++++++++++++++++--- 3 files changed, 26 insertions(+), 4 deletions(-) (limited to 'crates') 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 { type_definition_provider: None, implementation_provider: None, references_provider: Some(true), - document_highlight_provider: None, + document_highlight_provider: Some(true), document_symbol_provider: Some(true), workspace_symbol_provider: Some(true), 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 3ebae4ecd..46b48830d 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( .on::(handlers::handle_rename)? .on::(handlers::handle_references)? .on::(handlers::handle_formatting)? + .on::(handlers::handle_document_highlight)? .finish(); match req { 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 a2c12a4c1..60441e8ea 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::{ DiagnosticSeverity, DocumentSymbol, Documentation, FoldingRange, FoldingRangeKind, FoldingRangeParams, Location, MarkupContent, MarkupKind, MarkedString, Position, PrepareRenameResponse, RenameParams, SymbolInformation, TextDocumentIdentifier, TextEdit, - Range, - WorkspaceEdit, ParameterInformation, ParameterLabel, SignatureInformation, Hover, HoverContents, - DocumentFormattingParams, + Range, WorkspaceEdit, ParameterInformation, ParameterLabel, SignatureInformation, Hover, + HoverContents, DocumentFormattingParams, DocumentHighlight, }; use ra_analysis::{FileId, FoldKind, Query, RunnableKind, FileRange, FilePosition, Severity}; use ra_syntax::{TextUnit, text_utils::intersect}; @@ -673,6 +672,28 @@ pub fn handle_code_action( Ok(Some(CodeActionResponse::Commands(res))) } +pub fn handle_document_highlight( + world: ServerWorld, + params: req::TextDocumentPositionParams, +) -> Result>> { + let file_id = params.text_document.try_conv_with(&world)?; + let line_index = world.analysis().file_line_index(file_id); + let offset = params.position.conv_with(&line_index); + + let refs = world + .analysis() + .find_all_refs(FilePosition { file_id, offset })?; + + Ok(Some( + refs.into_iter() + .map(|r| DocumentHighlight { + range: r.1.conv_with(&line_index), + kind: None, + }) + .collect(), + )) +} + pub fn publish_diagnostics( world: &ServerWorld, file_id: FileId, -- cgit v1.2.3 From be75e547ce13dea281d2787ef5280637e76f6156 Mon Sep 17 00:00:00 2001 From: DJMcNab <36049421+DJMcNab@users.noreply.github.com> Date: Mon, 31 Dec 2018 12:17:05 +0000 Subject: Use TryConv for conversion --- crates/ra_lsp_server/src/main_loop/handlers.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'crates') diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 60441e8ea..228eb7ce5 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs @@ -678,11 +678,10 @@ pub fn handle_document_highlight( ) -> Result>> { let file_id = params.text_document.try_conv_with(&world)?; let line_index = world.analysis().file_line_index(file_id); - let offset = params.position.conv_with(&line_index); let refs = world .analysis() - .find_all_refs(FilePosition { file_id, offset })?; + .find_all_refs(params.try_conv_with(&world)?)?; Ok(Some( refs.into_iter() -- cgit v1.2.3