mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 22:54:58 +00:00
Have a better trait interface
This commit is contained in:
parent
bef5cf0b99
commit
d0a782ef1c
4 changed files with 53 additions and 72 deletions
|
@ -3,13 +3,11 @@
|
|||
|
||||
use crate::{
|
||||
db::RootDatabase,
|
||||
references::{classify_name, classify_name_ref, NameDefinition, NameKind},
|
||||
references::{classify_name, NameDefinition, NameKind},
|
||||
symbol_index::{self, FileSymbol},
|
||||
Query,
|
||||
};
|
||||
use ast::NameRef;
|
||||
use hir::{db::HirDatabase, InFile, ModPath, Module, SourceBinder};
|
||||
use itertools::Itertools;
|
||||
use hir::{db::HirDatabase, ModuleDef, SourceBinder};
|
||||
use ra_assists::ImportsLocator;
|
||||
use ra_prof::profile;
|
||||
use ra_syntax::{ast, AstNode, SyntaxKind::NAME};
|
||||
|
@ -23,46 +21,6 @@ impl<'a> ImportsLocatorIde<'a> {
|
|||
Self { source_binder: SourceBinder::new(db) }
|
||||
}
|
||||
|
||||
fn search_for_imports(
|
||||
&mut self,
|
||||
name_to_import: &ast::NameRef,
|
||||
module_with_name_to_import: Module,
|
||||
) -> Vec<ModPath> {
|
||||
let _p = profile("search_for_imports");
|
||||
let db = self.source_binder.db;
|
||||
let name_to_import = name_to_import.text();
|
||||
|
||||
let project_results = {
|
||||
let mut query = Query::new(name_to_import.to_string());
|
||||
query.exact();
|
||||
query.limit(40);
|
||||
symbol_index::world_symbols(db, query)
|
||||
};
|
||||
let lib_results = {
|
||||
let mut query = Query::new(name_to_import.to_string());
|
||||
query.libs();
|
||||
query.exact();
|
||||
query.limit(40);
|
||||
symbol_index::world_symbols(db, query)
|
||||
};
|
||||
|
||||
project_results
|
||||
.into_iter()
|
||||
.chain(lib_results.into_iter())
|
||||
.filter_map(|import_candidate| self.get_name_definition(db, &import_candidate))
|
||||
.filter_map(|name_definition_to_import| {
|
||||
if let NameKind::Def(module_def) = name_definition_to_import.kind {
|
||||
module_with_name_to_import.find_use_path(db, module_def)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.filter(|use_path| !use_path.segments.is_empty())
|
||||
.unique()
|
||||
.take(20)
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn get_name_definition(
|
||||
&mut self,
|
||||
db: &impl HirDatabase,
|
||||
|
@ -84,15 +42,35 @@ impl<'a> ImportsLocatorIde<'a> {
|
|||
}
|
||||
|
||||
impl<'a> ImportsLocator for ImportsLocatorIde<'a> {
|
||||
fn find_imports(
|
||||
&mut self,
|
||||
name_to_import: InFile<&NameRef>,
|
||||
module_with_name_to_import: Module,
|
||||
) -> Option<Vec<ModPath>> {
|
||||
if classify_name_ref(&mut self.source_binder, name_to_import).is_none() {
|
||||
Some(self.search_for_imports(name_to_import.value, module_with_name_to_import))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
fn find_imports(&mut self, name_to_import: &str) -> Vec<ModuleDef> {
|
||||
let _p = profile("search_for_imports");
|
||||
let db = self.source_binder.db;
|
||||
|
||||
let project_results = {
|
||||
let mut query = Query::new(name_to_import.to_string());
|
||||
query.exact();
|
||||
query.limit(40);
|
||||
symbol_index::world_symbols(db, query)
|
||||
};
|
||||
let lib_results = {
|
||||
let mut query = Query::new(name_to_import.to_string());
|
||||
query.libs();
|
||||
query.exact();
|
||||
query.limit(40);
|
||||
symbol_index::world_symbols(db, query)
|
||||
};
|
||||
|
||||
project_results
|
||||
.into_iter()
|
||||
.chain(lib_results.into_iter())
|
||||
.filter_map(|import_candidate| self.get_name_definition(db, &import_candidate))
|
||||
.filter_map(|name_definition_to_import| {
|
||||
if let NameKind::Def(module_def) = name_definition_to_import.kind {
|
||||
Some(module_def)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue