Skip to content

Commit

Permalink
fix: Fix lens location "above_whole_item" breaking lenses
Browse files Browse the repository at this point in the history
  • Loading branch information
Veykril committed Sep 13, 2023
1 parent affe5a7 commit 712e67c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
4 changes: 3 additions & 1 deletion crates/ide-db/src/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions crates/ide/src/annotations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
27 changes: 12 additions & 15 deletions crates/rust-analyzer/src/lsp/to_proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -1391,7 +1392,7 @@ pub(crate) fn code_lens(
command::show_references(
implementation_title(locations.len()),
&url,
annotation_range.start,
pos,
locations,
)
});
Expand All @@ -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 {
Expand Down

0 comments on commit 712e67c

Please sign in to comment.