Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide/src/references.rs')
-rw-r--r--crates/ide/src/references.rs44
1 files changed, 25 insertions, 19 deletions
diff --git a/crates/ide/src/references.rs b/crates/ide/src/references.rs
index 069818d50e..4fa116444b 100644
--- a/crates/ide/src/references.rs
+++ b/crates/ide/src/references.rs
@@ -11,21 +11,22 @@
use hir::{PathResolution, Semantics};
use ide_db::{
+ FileId, RootDatabase,
defs::{Definition, NameClass, NameRefClass},
search::{ReferenceCategory, SearchScope, UsageSearchResult},
- FileId, RootDatabase,
};
use itertools::Itertools;
use nohash_hasher::IntMap;
use span::Edition;
use syntax::{
- ast::{self, HasName},
- match_ast, AstNode,
+ AstNode,
SyntaxKind::*,
- SyntaxNode, TextRange, TextSize, T,
+ SyntaxNode, T, TextRange, TextSize,
+ ast::{self, HasName},
+ match_ast,
};
-use crate::{highlight_related, FilePosition, HighlightedRange, NavigationTarget, TryToNav};
+use crate::{FilePosition, HighlightedRange, NavigationTarget, TryToNav, highlight_related};
#[derive(Debug, Clone)]
pub struct ReferenceSearchResult {
@@ -67,7 +68,7 @@ pub(crate) fn find_all_refs(
.into_iter()
.map(|(file_id, refs)| {
(
- file_id.into(),
+ file_id.file_id(sema.db),
refs.into_iter()
.map(|file_ref| (file_ref.range, file_ref.category))
.unique()
@@ -123,11 +124,11 @@ pub(crate) fn find_all_refs(
}
}
-pub(crate) fn find_defs<'a>(
- sema: &'a Semantics<'_, RootDatabase>,
+pub(crate) fn find_defs(
+ sema: &Semantics<'_, RootDatabase>,
syntax: &SyntaxNode,
offset: TextSize,
-) -> Option<impl IntoIterator<Item = Definition> + 'a> {
+) -> Option<Vec<Definition>> {
let token = syntax.token_at_offset(offset).find(|t| {
matches!(
t.kind(),
@@ -306,8 +307,10 @@ fn handle_control_flow_keywords(
FilePosition { file_id, offset }: FilePosition,
) -> Option<ReferenceSearchResult> {
let file = sema.parse_guess_edition(file_id);
- let edition =
- sema.attach_first_edition(file_id).map(|it| it.edition()).unwrap_or(Edition::CURRENT);
+ let edition = sema
+ .attach_first_edition(file_id)
+ .map(|it| it.edition(sema.db))
+ .unwrap_or(Edition::CURRENT);
let token = file.syntax().token_at_offset(offset).find(|t| t.kind().is_keyword(edition))?;
let references = match token.kind() {
@@ -327,7 +330,7 @@ fn handle_control_flow_keywords(
.into_iter()
.map(|HighlightedRange { range, category }| (range, category))
.collect();
- (file_id.into(), ranges)
+ (file_id.file_id(sema.db), ranges)
})
.collect();
@@ -336,12 +339,12 @@ fn handle_control_flow_keywords(
#[cfg(test)]
mod tests {
- use expect_test::{expect, Expect};
- use ide_db::FileId;
- use span::EditionedFileId;
+ use expect_test::{Expect, expect};
+ use hir::EditionedFileId;
+ use ide_db::{FileId, RootDatabase};
use stdx::format_to;
- use crate::{fixture, SearchScope};
+ use crate::{SearchScope, fixture};
#[test]
fn exclude_tests() {
@@ -1003,7 +1006,9 @@ pub(super) struct Foo$0 {
check_with_scope(
code,
- Some(SearchScope::single_file(EditionedFileId::current_edition(FileId::from_raw(2)))),
+ Some(&mut |db| {
+ SearchScope::single_file(EditionedFileId::current_edition(db, FileId::from_raw(2)))
+ }),
expect![[r#"
quux Function FileId(0) 19..35 26..30
@@ -1259,11 +1264,12 @@ impl Foo {
fn check_with_scope(
#[rust_analyzer::rust_fixture] ra_fixture: &str,
- search_scope: Option<SearchScope>,
+ search_scope: Option<&mut dyn FnMut(&RootDatabase) -> SearchScope>,
expect: Expect,
) {
let (analysis, pos) = fixture::position(ra_fixture);
- let refs = analysis.find_all_refs(pos, search_scope).unwrap().unwrap();
+ let refs =
+ analysis.find_all_refs(pos, search_scope.map(|it| it(&analysis.db))).unwrap().unwrap();
let mut actual = String::new();
for mut refs in refs {