Unnamed repository; edit this file 'description' to name the repository.
Add a completion.addColonsToModule config
A4-Tacks 9 days ago
parent df4941f · commit f8018fc
-rw-r--r--crates/ide-completion/src/config.rs1
-rw-r--r--crates/ide-completion/src/render.rs2
-rw-r--r--crates/ide-completion/src/tests.rs1
-rw-r--r--crates/ide-completion/src/tests/expression.rs20
-rw-r--r--crates/rust-analyzer/src/config.rs6
-rw-r--r--crates/rust-analyzer/src/integrated_benchmarks.rs1
-rw-r--r--docs/book/src/configuration_generated.md9
-rw-r--r--editors/code/package.json10
8 files changed, 47 insertions, 3 deletions
diff --git a/crates/ide-completion/src/config.rs b/crates/ide-completion/src/config.rs
index 80c1572972..21f624be2c 100644
--- a/crates/ide-completion/src/config.rs
+++ b/crates/ide-completion/src/config.rs
@@ -25,6 +25,7 @@ pub struct CompletionConfig<'a> {
pub term_search_fuel: u64,
pub full_function_signatures: bool,
pub callable: Option<CallableSnippets>,
+ pub add_colons_to_module: bool,
pub add_semicolon_to_unit: bool,
pub snippet_cap: Option<SnippetCap>,
pub insert_use: InsertUseConfig,
diff --git a/crates/ide-completion/src/render.rs b/crates/ide-completion/src/render.rs
index a844489ea6..fbbdffefe3 100644
--- a/crates/ide-completion/src/render.rs
+++ b/crates/ide-completion/src/render.rs
@@ -471,7 +471,7 @@ fn render_resolution_path(
.insert_snippet(cap, ""); // set is snippet
}
}
- let allow_module_path = matches!(path_ctx.kind, PathKind::Use);
+ let allow_module_path = matches!(path_ctx.kind, PathKind::Use) || !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.rs b/crates/ide-completion/src/tests.rs
index 02e299b2a9..e574d4de0a 100644
--- a/crates/ide-completion/src/tests.rs
+++ b/crates/ide-completion/src/tests.rs
@@ -72,6 +72,7 @@ pub(crate) const TEST_CONFIG: CompletionConfig<'_> = CompletionConfig {
term_search_fuel: 200,
full_function_signatures: false,
callable: Some(CallableSnippets::FillArguments),
+ add_colons_to_module: true,
add_semicolon_to_unit: true,
snippet_cap: SnippetCap::new(true),
insert_use: InsertUseConfig {
diff --git a/crates/ide-completion/src/tests/expression.rs b/crates/ide-completion/src/tests/expression.rs
index 7e9ee7ba8d..c1205f9e18 100644
--- a/crates/ide-completion/src/tests/expression.rs
+++ b/crates/ide-completion/src/tests/expression.rs
@@ -5,8 +5,8 @@ use crate::{
CompletionConfig,
config::AutoImportExclusionType,
tests::{
- BASE_ITEMS_FIXTURE, TEST_CONFIG, check, check_edit, check_with_base_items,
- completion_list_with_config,
+ BASE_ITEMS_FIXTURE, TEST_CONFIG, check, check_edit, check_edit_with_config,
+ check_with_base_items, completion_list_with_config,
},
};
@@ -1150,6 +1150,22 @@ fn break_value_no_block() {
}
#[test]
+fn complete_module_colons() {
+ check_edit(
+ "module",
+ r#"mod module {} fn foo() { $0 }"#,
+ r#"mod module {} fn foo() { module:: }"#,
+ );
+
+ check_edit_with_config(
+ CompletionConfig { add_colons_to_module: false, ..TEST_CONFIG },
+ "module",
+ r#"mod module {} fn foo() { $0 }"#,
+ r#"mod module {} fn foo() { module }"#,
+ );
+}
+
+#[test]
fn else_completion_after_if() {
check(
r#"
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index 3a88a8fe84..f4c3f24ce6 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -627,6 +627,11 @@ config_data! {
/// Term search fuel in "units of work" for assists (Defaults to 1800).
assist_termSearch_fuel: usize = 1800,
+ /// Automatically add `::` when completing the module.
+ ///
+ /// Will not be completed in `use`.
+ completion_addColonsToModule: bool = true,
+
/// Automatically add a semicolon when completing unit-returning functions.
///
/// In `match` arms it completes a comma instead.
@@ -1901,6 +1906,7 @@ impl Config {
CallableCompletionDef::AddParentheses => Some(CallableSnippets::AddParentheses),
CallableCompletionDef::None => None,
},
+ add_colons_to_module: *self.completion_addColonsToModule(source_root),
add_semicolon_to_unit: *self.completion_addSemicolonToUnit(source_root),
snippet_cap: SnippetCap::new(self.completion_snippet()),
insert_use: self.insert_use_config(source_root),
diff --git a/crates/rust-analyzer/src/integrated_benchmarks.rs b/crates/rust-analyzer/src/integrated_benchmarks.rs
index 7718d9e545..bd3574ae0a 100644
--- a/crates/rust-analyzer/src/integrated_benchmarks.rs
+++ b/crates/rust-analyzer/src/integrated_benchmarks.rs
@@ -337,6 +337,7 @@ fn completion_config() -> CompletionConfig<'static> {
prefer_absolute: false,
snippets: Vec::new(),
limit: None,
+ add_colons_to_module: true,
add_semicolon_to_unit: true,
fields_to_resolve: CompletionFieldsToResolve::empty(),
exclude_flyimport: vec![],
diff --git a/docs/book/src/configuration_generated.md b/docs/book/src/configuration_generated.md
index da37fc1582..069c8211db 100644
--- a/docs/book/src/configuration_generated.md
+++ b/docs/book/src/configuration_generated.md
@@ -375,6 +375,15 @@ If false, `-p <package>` will be passed instead if applicable. In case it is not
check will be performed.
+## rust-analyzer.completion.addColonsToModule {#completion.addColonsToModule}
+
+Default: `true`
+
+Automatically add `::` when completing the module.
+
+Will not be completed in `use`.
+
+
## rust-analyzer.completion.addSemicolonToUnit {#completion.addSemicolonToUnit}
Default: `true`
diff --git a/editors/code/package.json b/editors/code/package.json
index 67570cd067..14369e6f33 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -1277,6 +1277,16 @@
{
"title": "Completion",
"properties": {
+ "rust-analyzer.completion.addColonsToModule": {
+ "markdownDescription": "Automatically add `::` when completing the module.\n\nWill not be completed in `use`.",
+ "default": true,
+ "type": "boolean"
+ }
+ }
+ },
+ {
+ "title": "Completion",
+ "properties": {
"rust-analyzer.completion.addSemicolonToUnit": {
"markdownDescription": "Automatically add a semicolon when completing unit-returning functions.\n\nIn `match` arms it completes a comma instead.",
"default": true,