Unnamed repository; edit this file 'description' to name the repository.
Auto merge of #12203 - Veykril:completions, r=Veykril
internal: Simplify
bors 2022-05-10
parent cc69536 · parent 40bb800 · commit 4a4e9c0
-rw-r--r--crates/ide-completion/src/completions/mod_.rs13
-rw-r--r--crates/ide-completion/src/context.rs9
-rw-r--r--crates/ide-completion/src/render.rs13
-rw-r--r--crates/ide-completion/src/render/macro_.rs4
4 files changed, 22 insertions, 17 deletions
diff --git a/crates/ide-completion/src/completions/mod_.rs b/crates/ide-completion/src/completions/mod_.rs
index 827d9f85ef..78d0ef7122 100644
--- a/crates/ide-completion/src/completions/mod_.rs
+++ b/crates/ide-completion/src/completions/mod_.rs
@@ -17,13 +17,12 @@ use crate::{
/// Complete mod declaration, i.e. `mod $0;`
pub(crate) fn complete_mod(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> {
let mod_under_caret = match ctx.name_ctx() {
- Some(NameContext { kind: NameKind::Module(mod_under_caret), .. })
- if mod_under_caret.item_list().is_none() =>
- {
- mod_under_caret
- }
+ Some(NameContext { kind: NameKind::Module(mod_under_caret), .. }) => mod_under_caret,
_ => return None,
};
+ if mod_under_caret.item_list().is_some() {
+ return None;
+ }
let _p = profile::span("completion::complete_mod");
@@ -32,8 +31,8 @@ pub(crate) fn complete_mod(acc: &mut Completions, ctx: &CompletionContext) -> Op
// interested in its parent.
if ctx.original_token.kind() == SyntaxKind::IDENT {
if let Some(module) = ctx.original_token.ancestors().nth(1).and_then(ast::Module::cast) {
- match current_module.definition_source(ctx.db).value {
- ModuleSource::Module(src) if src == module => {
+ match ctx.sema.to_def(&module) {
+ Some(module) if module == current_module => {
if let Some(parent) = current_module.parent(ctx.db) {
current_module = parent;
}
diff --git a/crates/ide-completion/src/context.rs b/crates/ide-completion/src/context.rs
index 5342c481e3..f6b8962df6 100644
--- a/crates/ide-completion/src/context.rs
+++ b/crates/ide-completion/src/context.rs
@@ -326,6 +326,7 @@ impl<'a> CompletionContext<'a> {
matches!(self.completion_location, Some(ImmediateLocation::ItemList))
}
+ // FIXME: This shouldn't exist
pub(crate) fn expects_generic_arg(&self) -> bool {
matches!(self.completion_location, Some(ImmediateLocation::GenericArgList(_)))
}
@@ -395,10 +396,6 @@ impl<'a> CompletionContext<'a> {
matches!(self.path_context(), Some(PathCompletionCtx { kind: PathKind::Type, .. }))
}
- pub(crate) fn path_is_call(&self) -> bool {
- self.path_context().map_or(false, |it| it.has_call_parens)
- }
-
pub(crate) fn is_non_trivial_path(&self) -> bool {
matches!(
self.path_context(),
@@ -417,10 +414,6 @@ impl<'a> CompletionContext<'a> {
self.path_context().map(|it| it.kind)
}
- pub(crate) fn is_immediately_after_macro_bang(&self) -> bool {
- self.token.kind() == BANG && self.token.parent().map_or(false, |it| it.kind() == MACRO_CALL)
- }
-
/// Checks if an item is visible and not `doc(hidden)` at the completion site.
pub(crate) fn is_visible<I>(&self, item: &I) -> Visible
where
diff --git a/crates/ide-completion/src/render.rs b/crates/ide-completion/src/render.rs
index b09e4a6320..88b6435c95 100644
--- a/crates/ide-completion/src/render.rs
+++ b/crates/ide-completion/src/render.rs
@@ -65,6 +65,19 @@ impl<'a> RenderContext<'a> {
}
}
+ fn is_immediately_after_macro_bang(&self) -> bool {
+ self.completion.token.kind() == SyntaxKind::BANG
+ && self
+ .completion
+ .token
+ .parent()
+ .map_or(false, |it| it.kind() == SyntaxKind::MACRO_CALL)
+ }
+
+ pub(crate) fn path_is_call(&self) -> bool {
+ self.completion.path_context().map_or(false, |it| it.has_call_parens)
+ }
+
fn is_deprecated(&self, def: impl HasAttrs) -> bool {
let attrs = def.attrs(self.db());
attrs.by_key("deprecated").exists()
diff --git a/crates/ide-completion/src/render/macro_.rs b/crates/ide-completion/src/render/macro_.rs
index 9c51a6311a..5c862f013a 100644
--- a/crates/ide-completion/src/render/macro_.rs
+++ b/crates/ide-completion/src/render/macro_.rs
@@ -20,7 +20,7 @@ fn render(
name: hir::Name,
macro_: hir::Macro,
) -> Builder {
- let source_range = if completion.is_immediately_after_macro_bang() {
+ let source_range = if ctx.is_immediately_after_macro_bang() {
cov_mark::hit!(completes_macro_call_if_cursor_at_bang_token);
completion.token.parent().map_or_else(|| ctx.source_range(), |it| it.text_range())
} else {
@@ -52,7 +52,7 @@ fn render(
let name = &*name;
match ctx.snippet_cap() {
- Some(cap) if needs_bang && !completion.path_is_call() => {
+ Some(cap) if needs_bang && !ctx.path_is_call() => {
let snippet = format!("{}!{}$0{}", name, bra, ket);
let lookup = banged_name(name);
item.insert_snippet(cap, snippet).lookup_by(lookup);