about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2023-09-13 22:01:04 +0200
committerLukas Wirth <lukastw97@gmail.com>2023-09-13 22:01:04 +0200
commit712e67cf11fbf76c4be77e221f030a39fbe4f195 (patch)
tree83d70042e8170daf07ced405ca7b9f04de67f1db
parentaffe5a731525e5e8ce401248a2ead0e85cc5f7a9 (diff)
downloadrust-712e67cf11fbf76c4be77e221f030a39fbe4f195.tar.gz
rust-712e67cf11fbf76c4be77e221f030a39fbe4f195.zip
fix: Fix lens location "above_whole_item" breaking lenses
-rw-r--r--crates/ide-db/src/search.rs4
-rw-r--r--crates/ide/src/annotations.rs3
-rw-r--r--crates/rust-analyzer/src/lsp/to_proto.rs27
3 files changed, 16 insertions, 18 deletions
diff --git a/crates/ide-db/src/search.rs b/crates/ide-db/src/search.rs
index 2ffce3c7513..9c4f0ac8c9f 100644
--- a/crates/ide-db/src/search.rs
+++ b/crates/ide-db/src/search.rs
@@ -6,7 +6,7 @@
 
 use std::mem;
 
-use base_db::{FileId, FileRange, SourceDatabase, SourceDatabaseExt};
+use base_db::{salsa::Database, FileId, FileRange, SourceDatabase, SourceDatabaseExt};
 use hir::{
     AsAssocItem, DefWithBody, HasAttrs, HasSource, InFile, ModuleSource, Semantics, Visibility,
 };
@@ -470,6 +470,7 @@ impl<'a> FindUsages<'a> {
         };
 
         for (text, file_id, search_range) in scope_files(sema, &search_scope) {
+            self.sema.db.unwind_if_cancelled();
             let tree = Lazy::new(move || sema.parse(file_id).syntax().clone());
 
             // Search for occurrences of the items name
@@ -506,6 +507,7 @@ impl<'a> FindUsages<'a> {
             let finder = &Finder::new("super");
 
             for (text, file_id, search_range) in scope_files(sema, &scope) {
+                self.sema.db.unwind_if_cancelled();
                 let tree = Lazy::new(move || sema.parse(file_id).syntax().clone());
 
                 for offset in match_indices(&text, finder, search_range) {
diff --git a/crates/ide/src/annotations.rs b/crates/ide/src/annotations.rs
index f994c284c71..fb79b5dc211 100644
--- a/crates/ide/src/annotations.rs
+++ b/crates/ide/src/annotations.rs
@@ -94,10 +94,9 @@ pub(crate) fn annotations(
                         enum_
                             .variants(db)
                             .into_iter()
-                            .map(|variant| {
+                            .filter_map(|variant| {
                                 variant.source(db).and_then(|node| name_range(db, node, file_id))
                             })
-                            .flatten()
                             .for_each(|range| {
                                 let (annotation_range, target_position) = mk_ranges(range);
                                 annotations.push(Annotation {
diff --git a/crates/rust-analyzer/src/lsp/to_proto.rs b/crates/rust-analyzer/src/lsp/to_proto.rs
index ce2f993ca15..23074493aee 100644
--- a/crates/rust-analyzer/src/lsp/to_proto.rs
+++ b/crates/rust-analyzer/src/lsp/to_proto.rs
@@ -1358,17 +1358,18 @@ pub(crate) fn code_lens(
                 })
             }
         }
-        AnnotationKind::HasImpls { pos: file_range, data } => {
+        AnnotationKind::HasImpls { pos, data } => {
             if !client_commands_config.show_reference {
                 return Ok(());
             }
-            let line_index = snap.file_line_index(file_range.file_id)?;
+            let line_index = snap.file_line_index(pos.file_id)?;
             let annotation_range = range(&line_index, annotation.range);
-            let url = url(snap, file_range.file_id);
+            let url = url(snap, pos.file_id);
+            let pos = position(&line_index, pos.offset);
 
             let id = lsp_types::TextDocumentIdentifier { uri: url.clone() };
 
-            let doc_pos = lsp_types::TextDocumentPositionParams::new(id, annotation_range.start);
+            let doc_pos = lsp_types::TextDocumentPositionParams::new(id, pos);
 
             let goto_params = lsp_types::request::GotoImplementationParams {
                 text_document_position_params: doc_pos,
@@ -1391,7 +1392,7 @@ pub(crate) fn code_lens(
                 command::show_references(
                     implementation_title(locations.len()),
                     &url,
-                    annotation_range.start,
+                    pos,
                     locations,
                 )
             });
@@ -1411,28 +1412,24 @@ pub(crate) fn code_lens(
                 })(),
             })
         }
-        AnnotationKind::HasReferences { pos: file_range, data } => {
+        AnnotationKind::HasReferences { pos, data } => {
             if !client_commands_config.show_reference {
                 return Ok(());
             }
-            let line_index = snap.file_line_index(file_range.file_id)?;
+            let line_index = snap.file_line_index(pos.file_id)?;
             let annotation_range = range(&line_index, annotation.range);
-            let url = url(snap, file_range.file_id);
+            let url = url(snap, pos.file_id);
+            let pos = position(&line_index, pos.offset);
 
             let id = lsp_types::TextDocumentIdentifier { uri: url.clone() };
 
-            let doc_pos = lsp_types::TextDocumentPositionParams::new(id, annotation_range.start);
+            let doc_pos = lsp_types::TextDocumentPositionParams::new(id, pos);
 
             let command = data.map(|ranges| {
                 let locations: Vec<lsp_types::Location> =
                     ranges.into_iter().filter_map(|range| location(snap, range).ok()).collect();
 
-                command::show_references(
-                    reference_title(locations.len()),
-                    &url,
-                    annotation_range.start,
-                    locations,
-                )
+                command::show_references(reference_title(locations.len()), &url, pos, locations)
             });
 
             acc.push(lsp_types::CodeLens {