Refactor method candidate generation a bit

This fixes the order in which candidates are chosen a bit (not completely
though, as the ignored test demonstrates), and makes autoderef work with trait
methods. As a side effect, this also makes completion of trait methods work :)
This commit is contained in:
Florian Diebold 2019-04-14 16:08:10 +02:00
parent 88be6f3217
commit 4f8a49f43c
4 changed files with 179 additions and 58 deletions

View file

@ -18,7 +18,7 @@ use ra_syntax::{
use crate::{
HirDatabase, Function, Struct, Enum, Const, Static, Either, DefWithBody, PerNs, Name,
AsName, Module, HirFileId, Crate, Trait, Resolver,
AsName, Module, HirFileId, Crate, Trait, Resolver, Ty,
expr::{BodySourceMap, scope::{ScopeId, ExprScopes}},
ids::LocationCtx,
expr, AstId
@ -343,6 +343,16 @@ impl SourceAnalyzer {
.collect()
}
pub fn iterate_method_candidates<T>(
&self,
db: &impl HirDatabase,
ty: Ty,
name: Option<&Name>,
callback: impl FnMut(&Ty, Function) -> Option<T>,
) -> Option<T> {
ty.iterate_method_candidates(db, &self.resolver, name, callback)
}
#[cfg(test)]
pub(crate) fn body_source_map(&self) -> Arc<BodySourceMap> {
self.body_source_map.clone().unwrap()