Skip to content

Commit 4a4e9c0

Browse files
committed
Auto merge of rust-lang#12203 - Veykril:completions, r=Veykril
internal: Simplify
2 parents cc69536 + 40bb800 commit 4a4e9c0

File tree

4 files changed

+22
-17
lines changed

4 files changed

+22
-17
lines changed

crates/ide-completion/src/completions/mod_.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@ use crate::{
1717
/// Complete mod declaration, i.e. `mod $0;`
1818
pub(crate) fn complete_mod(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> {
1919
let mod_under_caret = match ctx.name_ctx() {
20-
Some(NameContext { kind: NameKind::Module(mod_under_caret), .. })
21-
if mod_under_caret.item_list().is_none() =>
22-
{
23-
mod_under_caret
24-
}
20+
Some(NameContext { kind: NameKind::Module(mod_under_caret), .. }) => mod_under_caret,
2521
_ => return None,
2622
};
23+
if mod_under_caret.item_list().is_some() {
24+
return None;
25+
}
2726

2827
let _p = profile::span("completion::complete_mod");
2928

@@ -32,8 +31,8 @@ pub(crate) fn complete_mod(acc: &mut Completions, ctx: &CompletionContext) -> Op
3231
// interested in its parent.
3332
if ctx.original_token.kind() == SyntaxKind::IDENT {
3433
if let Some(module) = ctx.original_token.ancestors().nth(1).and_then(ast::Module::cast) {
35-
match current_module.definition_source(ctx.db).value {
36-
ModuleSource::Module(src) if src == module => {
34+
match ctx.sema.to_def(&module) {
35+
Some(module) if module == current_module => {
3736
if let Some(parent) = current_module.parent(ctx.db) {
3837
current_module = parent;
3938
}

crates/ide-completion/src/context.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ impl<'a> CompletionContext<'a> {
326326
matches!(self.completion_location, Some(ImmediateLocation::ItemList))
327327
}
328328

329+
// FIXME: This shouldn't exist
329330
pub(crate) fn expects_generic_arg(&self) -> bool {
330331
matches!(self.completion_location, Some(ImmediateLocation::GenericArgList(_)))
331332
}
@@ -395,10 +396,6 @@ impl<'a> CompletionContext<'a> {
395396
matches!(self.path_context(), Some(PathCompletionCtx { kind: PathKind::Type, .. }))
396397
}
397398

398-
pub(crate) fn path_is_call(&self) -> bool {
399-
self.path_context().map_or(false, |it| it.has_call_parens)
400-
}
401-
402399
pub(crate) fn is_non_trivial_path(&self) -> bool {
403400
matches!(
404401
self.path_context(),
@@ -417,10 +414,6 @@ impl<'a> CompletionContext<'a> {
417414
self.path_context().map(|it| it.kind)
418415
}
419416

420-
pub(crate) fn is_immediately_after_macro_bang(&self) -> bool {
421-
self.token.kind() == BANG && self.token.parent().map_or(false, |it| it.kind() == MACRO_CALL)
422-
}
423-
424417
/// Checks if an item is visible and not `doc(hidden)` at the completion site.
425418
pub(crate) fn is_visible<I>(&self, item: &I) -> Visible
426419
where

crates/ide-completion/src/render.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,19 @@ impl<'a> RenderContext<'a> {
6565
}
6666
}
6767

68+
fn is_immediately_after_macro_bang(&self) -> bool {
69+
self.completion.token.kind() == SyntaxKind::BANG
70+
&& self
71+
.completion
72+
.token
73+
.parent()
74+
.map_or(false, |it| it.kind() == SyntaxKind::MACRO_CALL)
75+
}
76+
77+
pub(crate) fn path_is_call(&self) -> bool {
78+
self.completion.path_context().map_or(false, |it| it.has_call_parens)
79+
}
80+
6881
fn is_deprecated(&self, def: impl HasAttrs) -> bool {
6982
let attrs = def.attrs(self.db());
7083
attrs.by_key("deprecated").exists()

crates/ide-completion/src/render/macro_.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fn render(
2020
name: hir::Name,
2121
macro_: hir::Macro,
2222
) -> Builder {
23-
let source_range = if completion.is_immediately_after_macro_bang() {
23+
let source_range = if ctx.is_immediately_after_macro_bang() {
2424
cov_mark::hit!(completes_macro_call_if_cursor_at_bang_token);
2525
completion.token.parent().map_or_else(|| ctx.source_range(), |it| it.text_range())
2626
} else {
@@ -52,7 +52,7 @@ fn render(
5252

5353
let name = &*name;
5454
match ctx.snippet_cap() {
55-
Some(cap) if needs_bang && !completion.path_is_call() => {
55+
Some(cap) if needs_bang && !ctx.path_is_call() => {
5656
let snippet = format!("{}!{}$0{}", name, bra, ket);
5757
let lookup = banged_name(name);
5858
item.insert_snippet(cap, snippet).lookup_by(lookup);

0 commit comments

Comments
 (0)