diff --git a/crates/ide-db/src/search.rs b/crates/ide-db/src/search.rs index 2ffce3c751..9c4f0ac8c9 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 f994c284c7..fb79b5dc21 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 ce2f993ca1..23074493ae 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 = 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 {