diff options
Diffstat (limited to 'crates/ra_hir/src/source_binder.rs')
-rw-r--r-- | crates/ra_hir/src/source_binder.rs | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index f1bb13bc6..a6f0ab289 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs | |||
@@ -14,14 +14,19 @@ use ra_syntax::{ | |||
14 | ast::{self, AstNode, NameOwner}, | 14 | ast::{self, AstNode, NameOwner}, |
15 | algo::find_node_at_offset, | 15 | algo::find_node_at_offset, |
16 | SyntaxKind::*, | 16 | SyntaxKind::*, |
17 | SmolStr, | ||
17 | }; | 18 | }; |
18 | 19 | ||
19 | use crate::{ | 20 | use crate::{ |
20 | HirDatabase, Function, Struct, Enum, Const, Static, Either, DefWithBody, PerNs, Name, | 21 | HirDatabase, Function, Struct, Enum, Const, Static, Either, DefWithBody, PerNs, Name, |
22 | <<<<<<< HEAD | ||
21 | AsName, Module, HirFileId, Crate, Trait, Resolver, Ty, | 23 | AsName, Module, HirFileId, Crate, Trait, Resolver, Ty, |
24 | ======= | ||
25 | AsName, Module, HirFileId, Crate, Trait, Resolver, ImportResolver, | ||
26 | >>>>>>> complete_import: add new import resolver infrastructure with some hardcoded importable name. | ||
22 | expr::{BodySourceMap, scope::{ScopeId, ExprScopes}}, | 27 | expr::{BodySourceMap, scope::{ScopeId, ExprScopes}}, |
23 | ids::LocationCtx, | 28 | ids::LocationCtx, |
24 | expr, AstId | 29 | expr, AstId, |
25 | }; | 30 | }; |
26 | 31 | ||
27 | /// Locates the module by `FileId`. Picks topmost module in the file. | 32 | /// Locates the module by `FileId`. Picks topmost module in the file. |
@@ -170,6 +175,7 @@ fn def_with_body_from_child_node( | |||
170 | #[derive(Debug)] | 175 | #[derive(Debug)] |
171 | pub struct SourceAnalyzer { | 176 | pub struct SourceAnalyzer { |
172 | resolver: Resolver, | 177 | resolver: Resolver, |
178 | import_resolver: ImportResolver, | ||
173 | body_source_map: Option<Arc<BodySourceMap>>, | 179 | body_source_map: Option<Arc<BodySourceMap>>, |
174 | infer: Option<Arc<crate::ty::InferenceResult>>, | 180 | infer: Option<Arc<crate::ty::InferenceResult>>, |
175 | scopes: Option<Arc<crate::expr::ExprScopes>>, | 181 | scopes: Option<Arc<crate::expr::ExprScopes>>, |
@@ -217,6 +223,7 @@ impl SourceAnalyzer { | |||
217 | offset: Option<TextUnit>, | 223 | offset: Option<TextUnit>, |
218 | ) -> SourceAnalyzer { | 224 | ) -> SourceAnalyzer { |
219 | let def_with_body = def_with_body_from_child_node(db, file_id, node); | 225 | let def_with_body = def_with_body_from_child_node(db, file_id, node); |
226 | let import_resolver = ImportResolver::new(); | ||
220 | if let Some(def) = def_with_body { | 227 | if let Some(def) = def_with_body { |
221 | let source_map = def.body_source_map(db); | 228 | let source_map = def.body_source_map(db); |
222 | let scopes = db.expr_scopes(def); | 229 | let scopes = db.expr_scopes(def); |
@@ -227,6 +234,7 @@ impl SourceAnalyzer { | |||
227 | let resolver = expr::resolver_for_scope(def.body(db), db, scope); | 234 | let resolver = expr::resolver_for_scope(def.body(db), db, scope); |
228 | SourceAnalyzer { | 235 | SourceAnalyzer { |
229 | resolver, | 236 | resolver, |
237 | import_resolver, | ||
230 | body_source_map: Some(source_map), | 238 | body_source_map: Some(source_map), |
231 | infer: Some(def.infer(db)), | 239 | infer: Some(def.infer(db)), |
232 | scopes: Some(scopes), | 240 | scopes: Some(scopes), |
@@ -237,6 +245,7 @@ impl SourceAnalyzer { | |||
237 | .ancestors() | 245 | .ancestors() |
238 | .find_map(|node| try_get_resolver_for_node(db, file_id, node)) | 246 | .find_map(|node| try_get_resolver_for_node(db, file_id, node)) |
239 | .unwrap_or_default(), | 247 | .unwrap_or_default(), |
248 | import_resolver, | ||
240 | body_source_map: None, | 249 | body_source_map: None, |
241 | infer: None, | 250 | infer: None, |
242 | scopes: None, | 251 | scopes: None, |
@@ -323,6 +332,14 @@ impl SourceAnalyzer { | |||
323 | self.resolver.all_names(db) | 332 | self.resolver.all_names(db) |
324 | } | 333 | } |
325 | 334 | ||
335 | pub fn all_import_names( | ||
336 | &self, | ||
337 | db: &impl HirDatabase, | ||
338 | name: &Name, | ||
339 | ) -> FxHashMap<SmolStr, Vec<SmolStr>> { | ||
340 | self.import_resolver.all_names(db, name) | ||
341 | } | ||
342 | |||
326 | pub fn find_all_refs(&self, pat: &ast::BindPat) -> Vec<ReferenceDescriptor> { | 343 | pub fn find_all_refs(&self, pat: &ast::BindPat) -> Vec<ReferenceDescriptor> { |
327 | // FIXME: at least, this should work with any DefWithBody, but ideally | 344 | // FIXME: at least, this should work with any DefWithBody, but ideally |
328 | // this should be hir-based altogether | 345 | // this should be hir-based altogether |