Skip to content

Commit d6b701e

Browse files
committed
internal: Make exclude characters for typing assists configurable, default to None
Signed-off-by: Tarek <tareknaser360@gmail.com>
1 parent e6276c8 commit d6b701e

File tree

5 files changed

+37
-2
lines changed

5 files changed

+37
-2
lines changed

crates/ide/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ impl Analysis {
411411
position: FilePosition,
412412
char_typed: char,
413413
autoclose: bool,
414+
chars_to_exclude: Option<String>,
414415
) -> Cancellable<Option<SourceChange>> {
415416
// Fast path to not even parse the file.
416417
if !typing::TRIGGER_CHARS.contains(char_typed) {
@@ -419,6 +420,11 @@ impl Analysis {
419420
if char_typed == '<' && !autoclose {
420421
return Ok(None);
421422
}
423+
if let Some(chars_to_exclude) = chars_to_exclude {
424+
if chars_to_exclude.contains(char_typed) {
425+
return Ok(None);
426+
}
427+
}
422428

423429
self.with_db(|db| typing::on_char_typed(db, position, char_typed))
424430
}

crates/rust-analyzer/src/config.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,8 @@ config_data! {
310310

311311
/// Whether to insert closing angle brackets when typing an opening angle bracket of a generic argument list.
312312
typing_autoClosingAngleBrackets_enable: bool = false,
313+
/// 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.
314+
typing_excludeChars: Option<String> = None,
313315

314316

315317
/// Enables automatic discovery of projects using [`DiscoverWorkspaceConfig::command`].
@@ -2160,6 +2162,10 @@ impl Config {
21602162
*self.typing_autoClosingAngleBrackets_enable()
21612163
}
21622164

2165+
pub fn typing_exclude_chars(&self) -> Option<String> {
2166+
self.typing_excludeChars().clone()
2167+
}
2168+
21632169
// VSCode is our reference implementation, so we allow ourselves to work around issues by
21642170
// special casing certain versions
21652171
pub fn visual_studio_code_version(&self) -> Option<&Version> {

crates/rust-analyzer/src/handlers/request.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,9 +459,14 @@ pub(crate) fn handle_on_type_formatting(
459459
if char_typed == '>' {
460460
return Ok(None);
461461
}
462+
let chars_to_exclude = snap.config.typing_exclude_chars();
462463

463-
let edit =
464-
snap.analysis.on_char_typed(position, char_typed, snap.config.typing_autoclose_angle())?;
464+
let edit = snap.analysis.on_char_typed(
465+
position,
466+
char_typed,
467+
snap.config.typing_autoclose_angle(),
468+
chars_to_exclude,
469+
)?;
465470
let edit = match edit {
466471
Some(it) => it,
467472
None => return Ok(None),

docs/user/generated_config.adoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,11 @@ Show documentation.
997997
--
998998
Whether to insert closing angle brackets when typing an opening angle bracket of a generic argument list.
999999
--
1000+
[[rust-analyzer.typing.excludeChars]]rust-analyzer.typing.excludeChars (default: `null`)::
1001+
+
1002+
--
1003+
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.
1004+
--
10001005
[[rust-analyzer.workspace.discoverConfig]]rust-analyzer.workspace.discoverConfig (default: `null`)::
10011006
+
10021007
--

editors/code/package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2612,6 +2612,19 @@
26122612
}
26132613
}
26142614
},
2615+
{
2616+
"title": "typing",
2617+
"properties": {
2618+
"rust-analyzer.typing.excludeChars": {
2619+
"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.",
2620+
"default": null,
2621+
"type": [
2622+
"null",
2623+
"string"
2624+
]
2625+
}
2626+
}
2627+
},
26152628
{
26162629
"title": "workspace",
26172630
"properties": {

0 commit comments

Comments
 (0)