mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 06:41:48 +00:00
Simplify
This commit is contained in:
parent
9f5ee155c1
commit
7619c2afea
5 changed files with 25 additions and 37 deletions
|
@ -99,6 +99,19 @@ impl Completions {
|
||||||
item.add_to(self);
|
item.add_to(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn add_nameref_keywords(&mut self, ctx: &CompletionContext) {
|
||||||
|
["self::", "super::", "crate::"].into_iter().for_each(|kw| self.add_keyword(ctx, kw));
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn add_crate_roots(&mut self, ctx: &CompletionContext) {
|
||||||
|
ctx.process_all_names(&mut |name, res| match res {
|
||||||
|
ScopeDef::ModuleDef(hir::ModuleDef::Module(m)) if m.is_crate_root(ctx.db) => {
|
||||||
|
self.add_resolution(ctx, name, res);
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn add_resolution(
|
pub(crate) fn add_resolution(
|
||||||
&mut self,
|
&mut self,
|
||||||
ctx: &CompletionContext,
|
ctx: &CompletionContext,
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
//!
|
//!
|
||||||
//! This module uses a bit of static metadata to provide completions for builtin-in attributes and lints.
|
//! This module uses a bit of static metadata to provide completions for builtin-in attributes and lints.
|
||||||
|
|
||||||
use hir::ScopeDef;
|
|
||||||
use ide_db::{
|
use ide_db::{
|
||||||
helpers::{
|
helpers::{
|
||||||
generated_lints::{
|
generated_lints::{
|
||||||
|
@ -103,14 +102,7 @@ pub(crate) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// fresh use tree with leading colon2, only show crate roots
|
// fresh use tree with leading colon2, only show crate roots
|
||||||
None if is_absolute_path => {
|
None if is_absolute_path => acc.add_crate_roots(ctx),
|
||||||
ctx.process_all_names(&mut |name, res| match res {
|
|
||||||
ScopeDef::ModuleDef(hir::ModuleDef::Module(m)) if m.is_crate_root(ctx.db) => {
|
|
||||||
acc.add_resolution(ctx, name, res);
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
// only show modules in a fresh UseTree
|
// only show modules in a fresh UseTree
|
||||||
None => {
|
None => {
|
||||||
ctx.process_all_names(&mut |name, def| {
|
ctx.process_all_names(&mut |name, def| {
|
||||||
|
@ -118,7 +110,7 @@ pub(crate) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext)
|
||||||
acc.add_resolution(ctx, name, def);
|
acc.add_resolution(ctx, name, def);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
["self::", "super::", "crate::"].into_iter().for_each(|kw| acc.add_keyword(ctx, kw));
|
acc.add_nameref_keywords(ctx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -141,7 +141,6 @@ fn pattern_path_completion(
|
||||||
_ => return,
|
_ => return,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Note associated consts cannot be referenced in patterns
|
|
||||||
if let Some(hir::Adt::Enum(e)) = ty.as_adt() {
|
if let Some(hir::Adt::Enum(e)) = ty.as_adt() {
|
||||||
e.variants(ctx.db)
|
e.variants(ctx.db)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
@ -157,9 +156,9 @@ fn pattern_path_completion(
|
||||||
ctx.module,
|
ctx.module,
|
||||||
None,
|
None,
|
||||||
|_ty, item| {
|
|_ty, item| {
|
||||||
// We might iterate candidates of a trait multiple times here, so deduplicate
|
// Note associated consts cannot be referenced in patterns
|
||||||
// them.
|
|
||||||
if let AssocItem::TypeAlias(ta) = item {
|
if let AssocItem::TypeAlias(ta) = item {
|
||||||
|
// We might iterate candidates of a trait multiple times here, so deduplicate them.
|
||||||
if seen.insert(item) {
|
if seen.insert(item) {
|
||||||
acc.add_type_alias(ctx, ta);
|
acc.add_type_alias(ctx, ta);
|
||||||
}
|
}
|
||||||
|
@ -173,18 +172,7 @@ fn pattern_path_completion(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// qualifier can only be none here if we are in a TuplePat or RecordPat in which case special characters have to follow the path
|
// qualifier can only be none here if we are in a TuplePat or RecordPat in which case special characters have to follow the path
|
||||||
// so executing the rest of this completion doesn't make sense
|
None if *is_absolute_path => acc.add_crate_roots(ctx),
|
||||||
// fresh use tree with leading colon2, only show crate roots
|
|
||||||
None if *is_absolute_path => {
|
|
||||||
cov_mark::hit!(use_tree_crate_roots_only);
|
|
||||||
ctx.process_all_names(&mut |name, res| match res {
|
|
||||||
ScopeDef::ModuleDef(hir::ModuleDef::Module(m)) if m.is_crate_root(ctx.db) => {
|
|
||||||
acc.add_resolution(ctx, name, res);
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
// only show modules in a fresh UseTree
|
|
||||||
None => {
|
None => {
|
||||||
cov_mark::hit!(unqualified_path_only_modules_in_import);
|
cov_mark::hit!(unqualified_path_only_modules_in_import);
|
||||||
ctx.process_all_names(&mut |name, res| {
|
ctx.process_all_names(&mut |name, res| {
|
||||||
|
@ -192,7 +180,7 @@ fn pattern_path_completion(
|
||||||
acc.add_resolution(ctx, name, res);
|
acc.add_resolution(ctx, name, res);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
["self::", "super::", "crate::"].into_iter().for_each(|kw| acc.add_keyword(ctx, kw));
|
acc.add_nameref_keywords(ctx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,12 +79,7 @@ pub(crate) fn complete_use_tree(acc: &mut Completions, ctx: &CompletionContext)
|
||||||
// fresh use tree with leading colon2, only show crate roots
|
// fresh use tree with leading colon2, only show crate roots
|
||||||
None if is_absolute_path => {
|
None if is_absolute_path => {
|
||||||
cov_mark::hit!(use_tree_crate_roots_only);
|
cov_mark::hit!(use_tree_crate_roots_only);
|
||||||
ctx.process_all_names(&mut |name, res| match res {
|
acc.add_crate_roots(ctx);
|
||||||
ScopeDef::ModuleDef(hir::ModuleDef::Module(m)) if m.is_crate_root(ctx.db) => {
|
|
||||||
acc.add_resolution(ctx, name, res);
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
// only show modules in a fresh UseTree
|
// only show modules in a fresh UseTree
|
||||||
None => {
|
None => {
|
||||||
|
@ -94,7 +89,7 @@ pub(crate) fn complete_use_tree(acc: &mut Completions, ctx: &CompletionContext)
|
||||||
acc.add_resolution(ctx, name, res);
|
acc.add_resolution(ctx, name, res);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
["self::", "super::", "crate::"].into_iter().for_each(|kw| acc.add_keyword(ctx, kw));
|
acc.add_nameref_keywords(ctx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,12 +72,12 @@ pub(crate) struct PathCompletionCtx {
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) struct PathQualifierCtx {
|
pub(crate) struct PathQualifierCtx {
|
||||||
pub path: ast::Path,
|
pub(crate) path: ast::Path,
|
||||||
pub resolution: Option<PathResolution>,
|
pub(crate) resolution: Option<PathResolution>,
|
||||||
/// Whether this path consists solely of `super` segments
|
/// Whether this path consists solely of `super` segments
|
||||||
pub is_super_chain: bool,
|
pub(crate) is_super_chain: bool,
|
||||||
/// Whether the qualifier comes from a use tree parent or not
|
/// Whether the qualifier comes from a use tree parent or not
|
||||||
pub use_tree_parent: bool,
|
pub(crate) use_tree_parent: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue