Unnamed repository; edit this file 'description' to name the repository.
Merge pull request #22386 from A4-Tacks/no-colon-before-colon
fix: no complete module colons before exists colons
Chayim Refael Friedman 3 weeks ago
parent 8838b32 · parent 379a130 · commit 7a4f9e8
-rw-r--r--crates/ide-completion/src/render.rs4
-rw-r--r--crates/ide-completion/src/tests/expression.rs27
2 files changed, 30 insertions, 1 deletions
diff --git a/crates/ide-completion/src/render.rs b/crates/ide-completion/src/render.rs
index fbbdffefe3..9c1cf61622 100644
--- a/crates/ide-completion/src/render.rs
+++ b/crates/ide-completion/src/render.rs
@@ -471,7 +471,9 @@ fn render_resolution_path(
.insert_snippet(cap, ""); // set is snippet
}
}
- let allow_module_path = matches!(path_ctx.kind, PathKind::Use) || !config.add_colons_to_module;
+ let allow_module_path = matches!(path_ctx.kind, PathKind::Use)
+ || completion.token.next_token().is_some_and(|it| it.kind() == syntax::T![::])
+ || !config.add_colons_to_module;
if !allow_module_path && matches!(resolution, ScopeDef::ModuleDef(Module(_))) {
insert_text = format_smolstr!("{insert_text}::");
item.lookup_by(name.clone()).label(insert_text.clone());
diff --git a/crates/ide-completion/src/tests/expression.rs b/crates/ide-completion/src/tests/expression.rs
index c1205f9e18..c26c4c2ff8 100644
--- a/crates/ide-completion/src/tests/expression.rs
+++ b/crates/ide-completion/src/tests/expression.rs
@@ -1157,6 +1157,12 @@ fn complete_module_colons() {
r#"mod module {} fn foo() { module:: }"#,
);
+ check_edit(
+ "module",
+ r#"mod module {} fn foo() { $0foo::bar }"#,
+ r#"mod module {} fn foo() { module::foo::bar }"#,
+ );
+
check_edit_with_config(
CompletionConfig { add_colons_to_module: false, ..TEST_CONFIG },
"module",
@@ -1166,6 +1172,27 @@ fn complete_module_colons() {
}
#[test]
+fn complete_module_exists_colons() {
+ check_edit(
+ "module",
+ r#"mod module {} fn foo() { $0::bar }"#,
+ r#"mod module {} fn foo() { module::bar }"#,
+ );
+
+ check_edit(
+ "module",
+ r#"
+macro_rules! i { ($i:ident) => { $i::bar } }
+mod module {}
+fn foo() { i!($0) }"#,
+ r#"
+macro_rules! i { ($i:ident) => { $i::bar } }
+mod module {}
+fn foo() { i!(module) }"#,
+ );
+}
+
+#[test]
fn else_completion_after_if() {
check(
r#"