From d993f329a01deb3cdc011c3eb1dfd859302fec04 Mon Sep 17 00:00:00 2001 From: Jeremy Kolb Date: Sat, 4 Jan 2020 17:46:01 -0500 Subject: Basic DocumentHighlightKind support for assignments --- crates/ra_lsp_server/src/conv.rs | 14 ++++++++++- crates/ra_lsp_server/src/main_loop/handlers.rs | 34 ++++++++++++++++++-------- 2 files changed, 37 insertions(+), 11 deletions(-) (limited to 'crates/ra_lsp_server') diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs index c260b51c4..1b93195d7 100644 --- a/crates/ra_lsp_server/src/conv.rs +++ b/crates/ra_lsp_server/src/conv.rs @@ -9,7 +9,7 @@ use lsp_types::{ use ra_ide::{ translate_offset_with_edit, CompletionItem, CompletionItemKind, FileId, FilePosition, FileRange, FileSystemEdit, Fold, FoldKind, InsertTextFormat, LineCol, LineIndex, - NavigationTarget, RangeInfo, Severity, SourceChange, SourceFileEdit, + NavigationTarget, RangeInfo, ReferenceAccess, Severity, SourceChange, SourceFileEdit, }; use ra_syntax::{SyntaxKind, TextRange, TextUnit}; use ra_text_edit::{AtomTextEdit, TextEdit}; @@ -53,6 +53,18 @@ impl Conv for SyntaxKind { } } +impl Conv for ReferenceAccess { + type Output = ::lsp_types::DocumentHighlightKind; + + fn conv(self) -> Self::Output { + use lsp_types::DocumentHighlightKind::*; + match self { + ReferenceAccess::Read => Read, + ReferenceAccess::Write => Write, + } + } +} + impl Conv for CompletionItemKind { type Output = ::lsp_types::CompletionItemKind; diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index a5b6f48af..a592f0a12 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs @@ -536,18 +536,32 @@ pub fn handle_references( let locations = if params.context.include_declaration { refs.into_iter() - .filter_map(|r| { - let line_index = world.analysis().file_line_index(r.file_range.file_id).ok()?; - to_location(r.file_range.file_id, r.file_range.range, &world, &line_index).ok() + .filter_map(|reference| { + let line_index = + world.analysis().file_line_index(reference.file_range.file_id).ok()?; + to_location( + reference.file_range.file_id, + reference.file_range.range, + &world, + &line_index, + ) + .ok() }) .collect() } else { // Only iterate over the references if include_declaration was false refs.references() .iter() - .filter_map(|r| { - let line_index = world.analysis().file_line_index(r.file_range.file_id).ok()?; - to_location(r.file_range.file_id, r.file_range.range, &world, &line_index).ok() + .filter_map(|reference| { + let line_index = + world.analysis().file_line_index(reference.file_range.file_id).ok()?; + to_location( + reference.file_range.file_id, + reference.file_range.range, + &world, + &line_index, + ) + .ok() }) .collect() }; @@ -836,10 +850,10 @@ pub fn handle_document_highlight( Ok(Some( refs.into_iter() - .filter(|r| r.file_range.file_id == file_id) - .map(|r| DocumentHighlight { - range: r.file_range.range.conv_with(&line_index), - kind: None, + .filter(|reference| reference.file_range.file_id == file_id) + .map(|reference| DocumentHighlight { + range: reference.file_range.range.conv_with(&line_index), + kind: reference.access.map(|it| it.conv()), }) .collect(), )) -- cgit v1.2.3 From a633a6275ab823396f57b1e93d45e58d98f8d32f Mon Sep 17 00:00:00 2001 From: kjeremy Date: Fri, 10 Jan 2020 15:30:17 -0500 Subject: Fix Write being sent down the wire. Not sure what the deal is here but it wasn't sending Write. --- crates/ra_lsp_server/src/conv.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'crates/ra_lsp_server') diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs index 1b93195d7..562699b7c 100644 --- a/crates/ra_lsp_server/src/conv.rs +++ b/crates/ra_lsp_server/src/conv.rs @@ -57,10 +57,10 @@ impl Conv for ReferenceAccess { type Output = ::lsp_types::DocumentHighlightKind; fn conv(self) -> Self::Output { - use lsp_types::DocumentHighlightKind::*; + use lsp_types::DocumentHighlightKind; match self { - ReferenceAccess::Read => Read, - ReferenceAccess::Write => Write, + ReferenceAccess::Read => DocumentHighlightKind::Read, + ReferenceAccess::Write => DocumentHighlightKind::Write, } } } -- cgit v1.2.3