diff options
Diffstat (limited to 'crates/ra_hir/src/source_analyzer.rs')
-rw-r--r-- | crates/ra_hir/src/source_analyzer.rs | 56 |
1 files changed, 8 insertions, 48 deletions
diff --git a/crates/ra_hir/src/source_analyzer.rs b/crates/ra_hir/src/source_analyzer.rs index 3df48842d..76e0bff34 100644 --- a/crates/ra_hir/src/source_analyzer.rs +++ b/crates/ra_hir/src/source_analyzer.rs | |||
@@ -16,12 +16,12 @@ use hir_def::{ | |||
16 | expr::{ExprId, PatId}, | 16 | expr::{ExprId, PatId}, |
17 | nameres::ModuleSource, | 17 | nameres::ModuleSource, |
18 | resolver::{self, resolver_for_scope, HasResolver, Resolver, TypeNs, ValueNs}, | 18 | resolver::{self, resolver_for_scope, HasResolver, Resolver, TypeNs, ValueNs}, |
19 | AssocItemId, DefWithBodyId, | 19 | DefWithBodyId, TraitId, |
20 | }; | 20 | }; |
21 | use hir_expand::{ | 21 | use hir_expand::{ |
22 | hygiene::Hygiene, name::AsName, AstId, HirFileId, InFile, MacroCallId, MacroCallKind, | 22 | hygiene::Hygiene, name::AsName, AstId, HirFileId, InFile, MacroCallId, MacroCallKind, |
23 | }; | 23 | }; |
24 | use hir_ty::{method_resolution, Canonical, InEnvironment, InferenceResult, TraitEnvironment, Ty}; | 24 | use hir_ty::{InEnvironment, InferenceResult, TraitEnvironment}; |
25 | use ra_prof::profile; | 25 | use ra_prof::profile; |
26 | use ra_syntax::{ | 26 | use ra_syntax::{ |
27 | ast::{self, AstNode}, | 27 | ast::{self, AstNode}, |
@@ -29,11 +29,11 @@ use ra_syntax::{ | |||
29 | SyntaxKind::*, | 29 | SyntaxKind::*, |
30 | SyntaxNode, SyntaxNodePtr, SyntaxToken, TextRange, TextUnit, | 30 | SyntaxNode, SyntaxNodePtr, SyntaxToken, TextRange, TextUnit, |
31 | }; | 31 | }; |
32 | use rustc_hash::FxHashSet; | ||
32 | 33 | ||
33 | use crate::{ | 34 | use crate::{ |
34 | db::HirDatabase, Adt, AssocItem, Const, DefWithBody, Enum, EnumVariant, FromSource, Function, | 35 | db::HirDatabase, Adt, Const, DefWithBody, Enum, EnumVariant, FromSource, Function, ImplBlock, |
35 | ImplBlock, Local, MacroDef, Name, Path, ScopeDef, Static, Struct, Trait, Type, TypeAlias, | 36 | Local, MacroDef, Name, Path, ScopeDef, Static, Struct, Trait, Type, TypeAlias, TypeParam, |
36 | TypeParam, | ||
37 | }; | 37 | }; |
38 | 38 | ||
39 | /// `SourceAnalyzer` is a convenience wrapper which exposes HIR API in terms of | 39 | /// `SourceAnalyzer` is a convenience wrapper which exposes HIR API in terms of |
@@ -347,49 +347,9 @@ impl SourceAnalyzer { | |||
347 | .collect() | 347 | .collect() |
348 | } | 348 | } |
349 | 349 | ||
350 | pub fn iterate_method_candidates<T>( | 350 | /// Note: `FxHashSet<TraitId>` should be treated as an opaque type, passed into `Type |
351 | &self, | 351 | pub fn traits_in_scope(&self, db: &impl HirDatabase) -> FxHashSet<TraitId> { |
352 | db: &impl HirDatabase, | 352 | self.resolver.traits_in_scope(db) |
353 | ty: &Type, | ||
354 | name: Option<&Name>, | ||
355 | mut callback: impl FnMut(&Ty, Function) -> Option<T>, | ||
356 | ) -> Option<T> { | ||
357 | // There should be no inference vars in types passed here | ||
358 | // FIXME check that? | ||
359 | // FIXME replace Unknown by bound vars here | ||
360 | let canonical = Canonical { value: ty.ty.value.clone(), num_vars: 0 }; | ||
361 | method_resolution::iterate_method_candidates( | ||
362 | &canonical, | ||
363 | db, | ||
364 | &self.resolver, | ||
365 | name, | ||
366 | method_resolution::LookupMode::MethodCall, | ||
367 | |ty, it| match it { | ||
368 | AssocItemId::FunctionId(f) => callback(ty, f.into()), | ||
369 | _ => None, | ||
370 | }, | ||
371 | ) | ||
372 | } | ||
373 | |||
374 | pub fn iterate_path_candidates<T>( | ||
375 | &self, | ||
376 | db: &impl HirDatabase, | ||
377 | ty: &Type, | ||
378 | name: Option<&Name>, | ||
379 | mut callback: impl FnMut(&Ty, AssocItem) -> Option<T>, | ||
380 | ) -> Option<T> { | ||
381 | // There should be no inference vars in types passed here | ||
382 | // FIXME check that? | ||
383 | // FIXME replace Unknown by bound vars here | ||
384 | let canonical = Canonical { value: ty.ty.value.clone(), num_vars: 0 }; | ||
385 | method_resolution::iterate_method_candidates( | ||
386 | &canonical, | ||
387 | db, | ||
388 | &self.resolver, | ||
389 | name, | ||
390 | method_resolution::LookupMode::Path, | ||
391 | |ty, it| callback(ty, it.into()), | ||
392 | ) | ||
393 | } | 353 | } |
394 | 354 | ||
395 | pub fn expand( | 355 | pub fn expand( |