Skip to content

Commit 089ae47

Browse files
committed
Auto merge of #15606 - Veykril:annotation-above-item-fi, r=Veykril
fix: Fix lens location "above_whole_item" breaking lenses Fixes rust-lang/rust-analyzer#15602
2 parents 15e1356 + 712e67c commit 089ae47

File tree

3 files changed

+16
-18
lines changed

3 files changed

+16
-18
lines changed

crates/ide-db/src/search.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
use std::mem;
88

9-
use base_db::{FileId, FileRange, SourceDatabase, SourceDatabaseExt};
9+
use base_db::{salsa::Database, FileId, FileRange, SourceDatabase, SourceDatabaseExt};
1010
use hir::{
1111
AsAssocItem, DefWithBody, HasAttrs, HasSource, InFile, ModuleSource, Semantics, Visibility,
1212
};
@@ -470,6 +470,7 @@ impl<'a> FindUsages<'a> {
470470
};
471471

472472
for (text, file_id, search_range) in scope_files(sema, &search_scope) {
473+
self.sema.db.unwind_if_cancelled();
473474
let tree = Lazy::new(move || sema.parse(file_id).syntax().clone());
474475

475476
// Search for occurrences of the items name
@@ -506,6 +507,7 @@ impl<'a> FindUsages<'a> {
506507
let finder = &Finder::new("super");
507508

508509
for (text, file_id, search_range) in scope_files(sema, &scope) {
510+
self.sema.db.unwind_if_cancelled();
509511
let tree = Lazy::new(move || sema.parse(file_id).syntax().clone());
510512

511513
for offset in match_indices(&text, finder, search_range) {

crates/ide/src/annotations.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,9 @@ pub(crate) fn annotations(
9494
enum_
9595
.variants(db)
9696
.into_iter()
97-
.map(|variant| {
97+
.filter_map(|variant| {
9898
variant.source(db).and_then(|node| name_range(db, node, file_id))
9999
})
100-
.flatten()
101100
.for_each(|range| {
102101
let (annotation_range, target_position) = mk_ranges(range);
103102
annotations.push(Annotation {

crates/rust-analyzer/src/lsp/to_proto.rs

+12-15
Original file line numberDiff line numberDiff line change
@@ -1358,17 +1358,18 @@ pub(crate) fn code_lens(
13581358
})
13591359
}
13601360
}
1361-
AnnotationKind::HasImpls { pos: file_range, data } => {
1361+
AnnotationKind::HasImpls { pos, data } => {
13621362
if !client_commands_config.show_reference {
13631363
return Ok(());
13641364
}
1365-
let line_index = snap.file_line_index(file_range.file_id)?;
1365+
let line_index = snap.file_line_index(pos.file_id)?;
13661366
let annotation_range = range(&line_index, annotation.range);
1367-
let url = url(snap, file_range.file_id);
1367+
let url = url(snap, pos.file_id);
1368+
let pos = position(&line_index, pos.offset);
13681369

13691370
let id = lsp_types::TextDocumentIdentifier { uri: url.clone() };
13701371

1371-
let doc_pos = lsp_types::TextDocumentPositionParams::new(id, annotation_range.start);
1372+
let doc_pos = lsp_types::TextDocumentPositionParams::new(id, pos);
13721373

13731374
let goto_params = lsp_types::request::GotoImplementationParams {
13741375
text_document_position_params: doc_pos,
@@ -1391,7 +1392,7 @@ pub(crate) fn code_lens(
13911392
command::show_references(
13921393
implementation_title(locations.len()),
13931394
&url,
1394-
annotation_range.start,
1395+
pos,
13951396
locations,
13961397
)
13971398
});
@@ -1411,28 +1412,24 @@ pub(crate) fn code_lens(
14111412
})(),
14121413
})
14131414
}
1414-
AnnotationKind::HasReferences { pos: file_range, data } => {
1415+
AnnotationKind::HasReferences { pos, data } => {
14151416
if !client_commands_config.show_reference {
14161417
return Ok(());
14171418
}
1418-
let line_index = snap.file_line_index(file_range.file_id)?;
1419+
let line_index = snap.file_line_index(pos.file_id)?;
14191420
let annotation_range = range(&line_index, annotation.range);
1420-
let url = url(snap, file_range.file_id);
1421+
let url = url(snap, pos.file_id);
1422+
let pos = position(&line_index, pos.offset);
14211423

14221424
let id = lsp_types::TextDocumentIdentifier { uri: url.clone() };
14231425

1424-
let doc_pos = lsp_types::TextDocumentPositionParams::new(id, annotation_range.start);
1426+
let doc_pos = lsp_types::TextDocumentPositionParams::new(id, pos);
14251427

14261428
let command = data.map(|ranges| {
14271429
let locations: Vec<lsp_types::Location> =
14281430
ranges.into_iter().filter_map(|range| location(snap, range).ok()).collect();
14291431

1430-
command::show_references(
1431-
reference_title(locations.len()),
1432-
&url,
1433-
annotation_range.start,
1434-
locations,
1435-
)
1432+
command::show_references(reference_title(locations.len()), &url, pos, locations)
14361433
});
14371434

14381435
acc.push(lsp_types::CodeLens {

0 commit comments

Comments
 (0)