Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide_db/src/helpers/import_assets.rs')
-rw-r--r--crates/ide_db/src/helpers/import_assets.rs21
1 files changed, 19 insertions, 2 deletions
diff --git a/crates/ide_db/src/helpers/import_assets.rs b/crates/ide_db/src/helpers/import_assets.rs
index f1e8ee4935..0b3ecd095b 100644
--- a/crates/ide_db/src/helpers/import_assets.rs
+++ b/crates/ide_db/src/helpers/import_assets.rs
@@ -8,10 +8,11 @@ use rustc_hash::FxHashSet;
use syntax::{
ast::{self, HasName},
utils::path_to_string_stripping_turbo_fish,
- AstNode, SyntaxNode,
+ AstNode, AstToken, SyntaxNode,
};
use crate::{
+ helpers::get_path_in_derive_attr,
items_locator::{self, AssocItemSearch, DEFAULT_QUERY_SEARCH_LIMIT},
RootDatabase,
};
@@ -119,7 +120,7 @@ impl ImportAssets {
})
}
- pub fn for_ident_pat(pat: &ast::IdentPat, sema: &Semantics<RootDatabase>) -> Option<Self> {
+ pub fn for_ident_pat(sema: &Semantics<RootDatabase>, pat: &ast::IdentPat) -> Option<Self> {
if !pat.is_simple_ident() {
return None;
}
@@ -132,6 +133,22 @@ impl ImportAssets {
})
}
+ pub fn for_derive_ident(sema: &Semantics<RootDatabase>, ident: &ast::Ident) -> Option<Self> {
+ let attr = ident.syntax().ancestors().find_map(ast::Attr::cast)?;
+ let path = get_path_in_derive_attr(sema, &attr, ident)?;
+
+ if let Some(_) = path.qualifier() {
+ return None;
+ }
+ let name = NameToImport::Exact(path.segment()?.name_ref()?.to_string());
+ let candidate_node = attr.syntax().clone();
+ Some(Self {
+ import_candidate: ImportCandidate::Path(PathImportCandidate { qualifier: None, name }),
+ module_with_candidate: sema.scope(&candidate_node).module()?,
+ candidate_node,
+ })
+ }
+
pub fn for_fuzzy_path(
module_with_candidate: Module,
qualifier: Option<ast::Path>,