Unnamed repository; edit this file 'description' to name the repository.
internal: Make exclude characters for typing assists configurable, default to None
Signed-off-by: Tarek <[email protected]>
Tarek 2024-12-04
parent e6276c8 · commit d6b701e
-rw-r--r--crates/ide/src/lib.rs6
-rw-r--r--crates/rust-analyzer/src/config.rs6
-rw-r--r--crates/rust-analyzer/src/handlers/request.rs9
-rw-r--r--docs/user/generated_config.adoc5
-rw-r--r--editors/code/package.json13
5 files changed, 37 insertions, 2 deletions
diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs
index d4ef9570e1..b4f3de3b17 100644
--- a/crates/ide/src/lib.rs
+++ b/crates/ide/src/lib.rs
@@ -411,6 +411,7 @@ impl Analysis {
position: FilePosition,
char_typed: char,
autoclose: bool,
+ chars_to_exclude: Option<String>,
) -> Cancellable<Option<SourceChange>> {
// Fast path to not even parse the file.
if !typing::TRIGGER_CHARS.contains(char_typed) {
@@ -419,6 +420,11 @@ impl Analysis {
if char_typed == '<' && !autoclose {
return Ok(None);
}
+ if let Some(chars_to_exclude) = chars_to_exclude {
+ if chars_to_exclude.contains(char_typed) {
+ return Ok(None);
+ }
+ }
self.with_db(|db| typing::on_char_typed(db, position, char_typed))
}
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index 152ce2944a..c2d6196ca4 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -310,6 +310,8 @@ config_data! {
/// Whether to insert closing angle brackets when typing an opening angle bracket of a generic argument list.
typing_autoClosingAngleBrackets_enable: bool = false,
+ /// Specify the characters to exclude from triggering typing assists. The default trigger characters are `.`, `=`, `<`, `>`, `{`, and `(`. Setting this to a string will disable typing assists for the specified characters.
+ typing_excludeChars: Option<String> = None,
/// Enables automatic discovery of projects using [`DiscoverWorkspaceConfig::command`].
@@ -2160,6 +2162,10 @@ impl Config {
*self.typing_autoClosingAngleBrackets_enable()
}
+ pub fn typing_exclude_chars(&self) -> Option<String> {
+ self.typing_excludeChars().clone()
+ }
+
// VSCode is our reference implementation, so we allow ourselves to work around issues by
// special casing certain versions
pub fn visual_studio_code_version(&self) -> Option<&Version> {
diff --git a/crates/rust-analyzer/src/handlers/request.rs b/crates/rust-analyzer/src/handlers/request.rs
index 4975467ece..29820a3e37 100644
--- a/crates/rust-analyzer/src/handlers/request.rs
+++ b/crates/rust-analyzer/src/handlers/request.rs
@@ -459,9 +459,14 @@ pub(crate) fn handle_on_type_formatting(
if char_typed == '>' {
return Ok(None);
}
+ let chars_to_exclude = snap.config.typing_exclude_chars();
- let edit =
- snap.analysis.on_char_typed(position, char_typed, snap.config.typing_autoclose_angle())?;
+ let edit = snap.analysis.on_char_typed(
+ position,
+ char_typed,
+ snap.config.typing_autoclose_angle(),
+ chars_to_exclude,
+ )?;
let edit = match edit {
Some(it) => it,
None => return Ok(None),
diff --git a/docs/user/generated_config.adoc b/docs/user/generated_config.adoc
index 052d0a2a41..d0c95912c3 100644
--- a/docs/user/generated_config.adoc
+++ b/docs/user/generated_config.adoc
@@ -997,6 +997,11 @@ Show documentation.
--
Whether to insert closing angle brackets when typing an opening angle bracket of a generic argument list.
--
+[[rust-analyzer.typing.excludeChars]]rust-analyzer.typing.excludeChars (default: `null`)::
++
+--
+Specify the characters to exclude from triggering typing assists. The default trigger characters are `.`, `=`, `<`, `>`, `{`, and `(`. Setting this to a string will disable typing assists for the specified characters.
+--
[[rust-analyzer.workspace.discoverConfig]]rust-analyzer.workspace.discoverConfig (default: `null`)::
+
--
diff --git a/editors/code/package.json b/editors/code/package.json
index 46f7803c8a..e98205e0ea 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -2613,6 +2613,19 @@
}
},
{
+ "title": "typing",
+ "properties": {
+ "rust-analyzer.typing.excludeChars": {
+ "markdownDescription": "Specify the characters to exclude from triggering typing assists. The default trigger characters are `.`, `=`, `<`, `>`, `{`, and `(`. Setting this to a string will disable typing assists for the specified characters.",
+ "default": null,
+ "type": [
+ "null",
+ "string"
+ ]
+ }
+ }
+ },
+ {
"title": "workspace",
"properties": {
"rust-analyzer.workspace.discoverConfig": {