mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-18 18:53:04 +00:00
fix: Fix lens location "above_whole_item" breaking lenses
This commit is contained in:
parent
affe5a7315
commit
712e67cf11
@ -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) {
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user