diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-01-10 21:40:57 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-01-10 21:40:57 +0000 |
commit | a9ba32e2e659dbbe78f7921f5b0abe7288c83aa9 (patch) | |
tree | fc742b1b41c72f8016329a243f0f5302d57bad85 /crates/ra_lsp_server/src | |
parent | 19eb7fa1db7da8417314ddfafe7addbbd9c3b46a (diff) | |
parent | a633a6275ab823396f57b1e93d45e58d98f8d32f (diff) |
Merge #2749
2749: Basic DocumentHighlightKind support for assignments r=matklad a=kjeremy
Wraps references per #2738 and adds limited support for DocumentHighlightKind Read/Write for simple binops assignments.
I think I need some help with determining reads/writes.
Towards #2560
Co-authored-by: Jeremy Kolb <[email protected]>
Co-authored-by: kjeremy <[email protected]>
Diffstat (limited to 'crates/ra_lsp_server/src')
-rw-r--r-- | crates/ra_lsp_server/src/conv.rs | 14 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/handlers.rs | 34 |
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..562699b7c 100644 --- a/crates/ra_lsp_server/src/conv.rs +++ b/crates/ra_lsp_server/src/conv.rs | |||
@@ -9,7 +9,7 @@ use lsp_types::{ | |||
9 | use ra_ide::{ | 9 | use 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 | }; |
14 | use ra_syntax::{SyntaxKind, TextRange, TextUnit}; | 14 | use ra_syntax::{SyntaxKind, TextRange, TextUnit}; |
15 | use ra_text_edit::{AtomTextEdit, TextEdit}; | 15 | use ra_text_edit::{AtomTextEdit, TextEdit}; |
@@ -53,6 +53,18 @@ impl Conv for SyntaxKind { | |||
53 | } | 53 | } |
54 | } | 54 | } |
55 | 55 | ||
56 | impl 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 => DocumentHighlightKind::Read, | ||
63 | ReferenceAccess::Write => DocumentHighlightKind::Write, | ||
64 | } | ||
65 | } | ||
66 | } | ||
67 | |||
56 | impl Conv for CompletionItemKind { | 68 | impl 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 | )) |