mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +00:00
internal: Remove unqualified_path completions module
This commit is contained in:
parent
25d133e3b8
commit
16d2e79b50
14 changed files with 464 additions and 421 deletions
49
crates/ide-completion/src/completions/expr.rs
Normal file
49
crates/ide-completion/src/completions/expr.rs
Normal file
|
@ -0,0 +1,49 @@
|
|||
//! Completion of names from the current scope in expression position.
|
||||
|
||||
use hir::ScopeDef;
|
||||
|
||||
use crate::{
|
||||
context::{PathCompletionCtx, PathKind, PathQualifierCtx},
|
||||
CompletionContext, Completions,
|
||||
};
|
||||
|
||||
pub(crate) fn complete_expr_path(acc: &mut Completions, ctx: &CompletionContext) {
|
||||
let _p = profile::span("complete_expr_path");
|
||||
if ctx.is_path_disallowed() {
|
||||
return;
|
||||
}
|
||||
|
||||
let (&is_absolute_path, qualifier) = match &ctx.path_context {
|
||||
Some(PathCompletionCtx {
|
||||
kind: Some(PathKind::Expr), is_absolute_path, qualifier, ..
|
||||
}) => (is_absolute_path, qualifier),
|
||||
_ => return,
|
||||
};
|
||||
|
||||
match qualifier {
|
||||
Some(PathQualifierCtx { .. }) => return,
|
||||
None if is_absolute_path => acc.add_crate_roots(ctx),
|
||||
None => {
|
||||
acc.add_nameref_keywords_with_colon(ctx);
|
||||
if let Some(hir::Adt::Enum(e)) =
|
||||
ctx.expected_type.as_ref().and_then(|ty| ty.strip_references().as_adt())
|
||||
{
|
||||
super::enum_variants_with_paths(acc, ctx, e, |acc, ctx, variant, path| {
|
||||
acc.add_qualified_enum_variant(ctx, variant, path)
|
||||
});
|
||||
}
|
||||
ctx.process_all_names(&mut |name, def| {
|
||||
use hir::{GenericParam::*, ModuleDef::*};
|
||||
let add_resolution = match def {
|
||||
ScopeDef::GenericParam(LifetimeParam(_)) | ScopeDef::Label(_) => false,
|
||||
// Don't suggest attribute macros and derives.
|
||||
ScopeDef::ModuleDef(Macro(mac)) => mac.is_fn_like(ctx.db),
|
||||
_ => true,
|
||||
};
|
||||
if add_resolution {
|
||||
acc.add_resolution(ctx, name, def);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue