Remove superfluous early returns
This commit is contained in:
parent
85b68b1f7d
commit
d97a8ee865
@ -82,16 +82,15 @@ pub(crate) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext)
|
||||
};
|
||||
|
||||
match qualified {
|
||||
Qualified::With { resolution, is_super_chain, .. } => {
|
||||
Qualified::With {
|
||||
resolution: Some(hir::PathResolution::Def(hir::ModuleDef::Module(module))),
|
||||
is_super_chain,
|
||||
..
|
||||
} => {
|
||||
if *is_super_chain {
|
||||
acc.add_keyword(ctx, "super::");
|
||||
}
|
||||
|
||||
let module = match resolution {
|
||||
Some(hir::PathResolution::Def(hir::ModuleDef::Module(it))) => it,
|
||||
_ => return,
|
||||
};
|
||||
|
||||
for (name, def) in module.scope(ctx.db, Some(ctx.module)) {
|
||||
if let Some(def) = module_or_attr(ctx.db, def) {
|
||||
acc.add_resolution(ctx, name, def);
|
||||
@ -110,7 +109,7 @@ pub(crate) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext)
|
||||
});
|
||||
acc.add_nameref_keywords_with_colon(ctx);
|
||||
}
|
||||
Qualified::Infer => {}
|
||||
Qualified::Infer | Qualified::With { .. } => {}
|
||||
}
|
||||
|
||||
let attributes = annotated_item_kind.and_then(|kind| {
|
||||
|
@ -21,16 +21,15 @@ pub(crate) fn complete_derive(acc: &mut Completions, ctx: &CompletionContext) {
|
||||
let core = ctx.famous_defs().core();
|
||||
|
||||
match qualified {
|
||||
Qualified::With { resolution, is_super_chain, .. } => {
|
||||
Qualified::With {
|
||||
resolution: Some(hir::PathResolution::Def(hir::ModuleDef::Module(module))),
|
||||
is_super_chain,
|
||||
..
|
||||
} => {
|
||||
if *is_super_chain {
|
||||
acc.add_keyword(ctx, "super::");
|
||||
}
|
||||
|
||||
let module = match resolution {
|
||||
Some(hir::PathResolution::Def(hir::ModuleDef::Module(it))) => it,
|
||||
_ => return,
|
||||
};
|
||||
|
||||
for (name, def) in module.scope(ctx.db, Some(ctx.module)) {
|
||||
let add_def = match def {
|
||||
ScopeDef::ModuleDef(hir::ModuleDef::Macro(mac)) => {
|
||||
@ -101,7 +100,7 @@ pub(crate) fn complete_derive(acc: &mut Completions, ctx: &CompletionContext) {
|
||||
});
|
||||
acc.add_nameref_keywords_with_colon(ctx);
|
||||
}
|
||||
Qualified::Infer => {}
|
||||
Qualified::Infer | Qualified::With { .. } => {}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -65,11 +65,8 @@ pub(crate) fn complete_expr_path(acc: &mut Completions, ctx: &CompletionContext)
|
||||
.into_iter()
|
||||
.flat_map(|it| hir::Trait::from(it).items(ctx.sema.db))
|
||||
.for_each(|item| add_assoc_item(acc, ctx, item)),
|
||||
Qualified::With { resolution, .. } => {
|
||||
let resolution = match resolution {
|
||||
Some(it) => it,
|
||||
None => return,
|
||||
};
|
||||
Qualified::With { resolution: None, .. } => {}
|
||||
Qualified::With { resolution: Some(resolution), .. } => {
|
||||
// Add associated types on type parameters and `Self`.
|
||||
ctx.scope.assoc_type_shorthand_candidates(resolution, |_, alias| {
|
||||
acc.add_type_alias(ctx, alias);
|
||||
|
@ -44,12 +44,14 @@ pub(crate) fn complete_item_list(acc: &mut Completions, ctx: &CompletionContext)
|
||||
}
|
||||
|
||||
match qualified {
|
||||
Qualified::With { resolution, is_super_chain, .. } => {
|
||||
if let Some(hir::PathResolution::Def(hir::ModuleDef::Module(module))) = resolution {
|
||||
for (name, def) in module.scope(ctx.db, Some(ctx.module)) {
|
||||
if let Some(def) = module_or_fn_macro(ctx.db, def) {
|
||||
acc.add_resolution(ctx, name, def);
|
||||
}
|
||||
Qualified::With {
|
||||
resolution: Some(hir::PathResolution::Def(hir::ModuleDef::Module(module))),
|
||||
is_super_chain,
|
||||
..
|
||||
} => {
|
||||
for (name, def) in module.scope(ctx.db, Some(ctx.module)) {
|
||||
if let Some(def) = module_or_fn_macro(ctx.db, def) {
|
||||
acc.add_resolution(ctx, name, def);
|
||||
}
|
||||
}
|
||||
|
||||
@ -66,7 +68,7 @@ pub(crate) fn complete_item_list(acc: &mut Completions, ctx: &CompletionContext)
|
||||
});
|
||||
acc.add_nameref_keywords_with_colon(ctx);
|
||||
}
|
||||
Qualified::Infer | Qualified::No => {}
|
||||
Qualified::Infer | Qualified::No | Qualified::With { .. } => {}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -114,16 +114,11 @@ fn pattern_path_completion(
|
||||
PathCompletionCtx { qualified, .. }: &PathCompletionCtx,
|
||||
) {
|
||||
match qualified {
|
||||
Qualified::With { resolution, is_super_chain, .. } => {
|
||||
Qualified::With { resolution: Some(resolution), is_super_chain, .. } => {
|
||||
if *is_super_chain {
|
||||
acc.add_keyword(ctx, "super::");
|
||||
}
|
||||
|
||||
let resolution = match resolution {
|
||||
Some(it) => it,
|
||||
None => return,
|
||||
};
|
||||
|
||||
match resolution {
|
||||
hir::PathResolution::Def(hir::ModuleDef::Module(module)) => {
|
||||
let module_scope = module.scope(ctx.db, Some(ctx.module));
|
||||
@ -208,6 +203,6 @@ fn pattern_path_completion(
|
||||
|
||||
acc.add_nameref_keywords_with_colon(ctx);
|
||||
}
|
||||
Qualified::Infer => {}
|
||||
Qualified::Infer | Qualified::With { .. } => {}
|
||||
}
|
||||
}
|
||||
|
@ -58,11 +58,8 @@ pub(crate) fn complete_type_path(acc: &mut Completions, ctx: &CompletionContext)
|
||||
.into_iter()
|
||||
.flat_map(|it| hir::Trait::from(it).items(ctx.sema.db))
|
||||
.for_each(|item| add_assoc_item(acc, item)),
|
||||
Qualified::With { resolution, .. } => {
|
||||
let resolution = match resolution {
|
||||
Some(it) => it,
|
||||
None => return,
|
||||
};
|
||||
Qualified::With { resolution: None, .. } => {}
|
||||
Qualified::With { resolution: Some(resolution), .. } => {
|
||||
// Add associated types on type parameters and `Self`.
|
||||
ctx.scope.assoc_type_shorthand_candidates(resolution, |_, alias| {
|
||||
acc.add_type_alias(ctx, alias);
|
||||
|
@ -29,7 +29,7 @@ pub(crate) fn complete_use_tree(acc: &mut Completions, ctx: &CompletionContext)
|
||||
};
|
||||
|
||||
match qualified {
|
||||
Qualified::With { path, resolution, is_super_chain } => {
|
||||
Qualified::With { path, resolution: Some(resolution), is_super_chain } => {
|
||||
if *is_super_chain {
|
||||
acc.add_keyword(ctx, "super::");
|
||||
}
|
||||
@ -43,11 +43,6 @@ pub(crate) fn complete_use_tree(acc: &mut Completions, ctx: &CompletionContext)
|
||||
acc.add_keyword(ctx, "self");
|
||||
}
|
||||
|
||||
let resolution = match resolution {
|
||||
Some(it) => it,
|
||||
None => return,
|
||||
};
|
||||
|
||||
let mut already_imported_names = FxHashSet::default();
|
||||
if let Some(list) = ctx.token.parent_ancestors().find_map(ast::UseTreeList::cast) {
|
||||
let use_tree = list.parent_use_tree();
|
||||
@ -135,6 +130,6 @@ pub(crate) fn complete_use_tree(acc: &mut Completions, ctx: &CompletionContext)
|
||||
});
|
||||
acc.add_nameref_keywords_with_colon(ctx);
|
||||
}
|
||||
Qualified::Infer => {}
|
||||
Qualified::Infer | Qualified::With { resolution: None, .. } => {}
|
||||
}
|
||||
}
|
||||
|
@ -16,20 +16,18 @@ pub(crate) fn complete_vis_path(acc: &mut Completions, ctx: &CompletionContext)
|
||||
};
|
||||
|
||||
match qualified {
|
||||
Qualified::With { resolution, is_super_chain, .. } => {
|
||||
Qualified::With {
|
||||
resolution: Some(hir::PathResolution::Def(hir::ModuleDef::Module(module))),
|
||||
is_super_chain,
|
||||
..
|
||||
} => {
|
||||
// Try completing next child module of the path that is still a parent of the current module
|
||||
if let Some(hir::PathResolution::Def(hir::ModuleDef::Module(module))) = resolution {
|
||||
let next_towards_current = ctx
|
||||
.module
|
||||
.path_to_root(ctx.db)
|
||||
.into_iter()
|
||||
.take_while(|it| it != module)
|
||||
.last();
|
||||
if let Some(next) = next_towards_current {
|
||||
if let Some(name) = next.name(ctx.db) {
|
||||
cov_mark::hit!(visibility_qualified);
|
||||
acc.add_resolution(ctx, name, ScopeDef::ModuleDef(next.into()));
|
||||
}
|
||||
let next_towards_current =
|
||||
ctx.module.path_to_root(ctx.db).into_iter().take_while(|it| it != module).last();
|
||||
if let Some(next) = next_towards_current {
|
||||
if let Some(name) = next.name(ctx.db) {
|
||||
cov_mark::hit!(visibility_qualified);
|
||||
acc.add_resolution(ctx, name, ScopeDef::ModuleDef(next.into()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,7 +35,7 @@ pub(crate) fn complete_vis_path(acc: &mut Completions, ctx: &CompletionContext)
|
||||
acc.add_keyword(ctx, "super::");
|
||||
}
|
||||
}
|
||||
Qualified::Absolute | Qualified::Infer => {}
|
||||
Qualified::Absolute | Qualified::Infer | Qualified::With { .. } => {}
|
||||
Qualified::No => {
|
||||
if !has_in_token {
|
||||
cov_mark::hit!(kw_completion_in);
|
||||
|
Loading…
x
Reference in New Issue
Block a user