completions: centralize calculation of relevance and ref matches

This commit is contained in:
Josh Mcguigan 2021-03-15 19:26:59 -07:00
parent c0a2b4e826
commit 405bbb3aa4
3 changed files with 174 additions and 52 deletions

View file

@ -6,7 +6,8 @@ use itertools::Itertools;
use crate::{
item::{CompletionItem, CompletionKind, ImportEdit},
render::{builder_ext::Params, RenderContext},
render::{builder_ext::Params, compute_exact_type_match, compute_ref_match, RenderContext},
CompletionRelevance,
};
pub(crate) fn render_variant<'a>(
@ -74,6 +75,16 @@ impl<'a> EnumRender<'a> {
item.lookup_by(self.short_qualified_name);
}
let ty = self.variant.parent_enum(self.ctx.completion.db).ty(self.ctx.completion.db);
item.set_relevance(CompletionRelevance {
exact_type_match: compute_exact_type_match(self.ctx.completion, &ty),
..CompletionRelevance::default()
});
if let Some(ref_match) = compute_ref_match(self.ctx.completion, &ty) {
item.ref_match(ref_match);
}
item.build()
}