aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server
diff options
context:
space:
mode:
authorJeremy Kolb <[email protected]>2020-01-04 22:46:01 +0000
committerkjeremy <[email protected]>2020-01-10 20:14:19 +0000
commitd993f329a01deb3cdc011c3eb1dfd859302fec04 (patch)
tree4ee64d1bd29b793cf5d9cff1f712cc02077b490a /crates/ra_lsp_server
parent19eb7fa1db7da8417314ddfafe7addbbd9c3b46a (diff)
Basic DocumentHighlightKind support for assignments
Diffstat (limited to 'crates/ra_lsp_server')
-rw-r--r--crates/ra_lsp_server/src/conv.rs14
-rw-r--r--crates/ra_lsp_server/src/main_loop/handlers.rs34
2 files changed, 37 insertions, 11 deletions
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::{
9use ra_ide::{ 9use ra_ide::{
10 translate_offset_with_edit, CompletionItem, CompletionItemKind, FileId, FilePosition, 10 translate_offset_with_edit, CompletionItem, CompletionItemKind, FileId, FilePosition,
11 FileRange, FileSystemEdit, Fold, FoldKind, InsertTextFormat, LineCol, LineIndex, 11 FileRange, FileSystemEdit, Fold, FoldKind, InsertTextFormat, LineCol, LineIndex,
12 NavigationTarget, RangeInfo, Severity, SourceChange, SourceFileEdit, 12 NavigationTarget, RangeInfo, ReferenceAccess, Severity, SourceChange, SourceFileEdit,
13}; 13};
14use ra_syntax::{SyntaxKind, TextRange, TextUnit}; 14use ra_syntax::{SyntaxKind, TextRange, TextUnit};
15use ra_text_edit::{AtomTextEdit, TextEdit}; 15use ra_text_edit::{AtomTextEdit, TextEdit};
@@ -53,6 +53,18 @@ impl Conv for SyntaxKind {
53 } 53 }
54} 54}
55 55
56impl Conv for ReferenceAccess {
57 type Output = ::lsp_types::DocumentHighlightKind;
58
59 fn conv(self) -> Self::Output {
60 use lsp_types::DocumentHighlightKind::*;
61 match self {
62 ReferenceAccess::Read => Read,
63 ReferenceAccess::Write => Write,
64 }
65 }
66}
67
56impl Conv for CompletionItemKind { 68impl Conv for CompletionItemKind {
57 type Output = ::lsp_types::CompletionItemKind; 69 type Output = ::lsp_types::CompletionItemKind;
58 70
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(
536 536
537 let locations = if params.context.include_declaration { 537 let locations = if params.context.include_declaration {
538 refs.into_iter() 538 refs.into_iter()
539 .filter_map(|r| { 539 .filter_map(|reference| {
540 let line_index = world.analysis().file_line_index(r.file_range.file_id).ok()?; 540 let line_index =
541 to_location(r.file_range.file_id, r.file_range.range, &world, &line_index).ok() 541 world.analysis().file_line_index(reference.file_range.file_id).ok()?;
542 to_location(
543 reference.file_range.file_id,
544 reference.file_range.range,
545 &world,
546 &line_index,
547 )
548 .ok()
542 }) 549 })
543 .collect() 550 .collect()
544 } else { 551 } else {
545 // Only iterate over the references if include_declaration was false 552 // Only iterate over the references if include_declaration was false
546 refs.references() 553 refs.references()
547 .iter() 554 .iter()
548 .filter_map(|r| { 555 .filter_map(|reference| {
549 let line_index = world.analysis().file_line_index(r.file_range.file_id).ok()?; 556 let line_index =
550 to_location(r.file_range.file_id, r.file_range.range, &world, &line_index).ok() 557 world.analysis().file_line_index(reference.file_range.file_id).ok()?;
558 to_location(
559 reference.file_range.file_id,
560 reference.file_range.range,
561 &world,
562 &line_index,
563 )
564 .ok()
551 }) 565 })
552 .collect() 566 .collect()
553 }; 567 };
@@ -836,10 +850,10 @@ pub fn handle_document_highlight(
836 850
837 Ok(Some( 851 Ok(Some(
838 refs.into_iter() 852 refs.into_iter()
839 .filter(|r| r.file_range.file_id == file_id) 853 .filter(|reference| reference.file_range.file_id == file_id)
840 .map(|r| DocumentHighlight { 854 .map(|reference| DocumentHighlight {
841 range: r.file_range.range.conv_with(&line_index), 855 range: reference.file_range.range.conv_with(&line_index),
842 kind: None, 856 kind: reference.access.map(|it| it.conv()),
843 }) 857 })
844 .collect(), 858 .collect(),
845 )) 859 ))