Skip to content

Commit d83f0fe

Browse files
authored
Merge pull request rust-lang#18522 from tareknaser/configure_typing_exclude_chars
Add Configurable Option to Exclude Trigger Characters for Typing Assists
2 parents c1c6e71 + 68cd579 commit d83f0fe

File tree

5 files changed

+20
-15
lines changed

5 files changed

+20
-15
lines changed

src/tools/rust-analyzer/crates/ide/src/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,14 +410,16 @@ impl Analysis {
410410
&self,
411411
position: FilePosition,
412412
char_typed: char,
413-
autoclose: bool,
413+
chars_to_exclude: Option<String>,
414414
) -> Cancellable<Option<SourceChange>> {
415415
// Fast path to not even parse the file.
416416
if !typing::TRIGGER_CHARS.contains(char_typed) {
417417
return Ok(None);
418418
}
419-
if char_typed == '<' && !autoclose {
420-
return Ok(None);
419+
if let Some(chars_to_exclude) = chars_to_exclude {
420+
if chars_to_exclude.contains(char_typed) {
421+
return Ok(None);
422+
}
421423
}
422424

423425
self.with_db(|db| typing::on_char_typed(db, position, char_typed))

src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,8 @@ config_data! {
308308
/// Show documentation.
309309
signatureInfo_documentation_enable: bool = true,
310310

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

314314

315315
/// Enables automatic discovery of projects using [`DiscoverWorkspaceConfig::command`].
@@ -2156,8 +2156,8 @@ impl Config {
21562156
}
21572157
}
21582158

2159-
pub fn typing_autoclose_angle(&self) -> bool {
2160-
*self.typing_autoClosingAngleBrackets_enable()
2159+
pub fn typing_exclude_chars(&self) -> Option<String> {
2160+
self.typing_excludeChars().clone()
21612161
}
21622162

21632163
// VSCode is our reference implementation, so we allow ourselves to work around issues by

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,9 +459,9 @@ 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(position, char_typed, chars_to_exclude)?;
465465
let edit = match edit {
466466
Some(it) => it,
467467
None => return Ok(None),

src/tools/rust-analyzer/docs/user/generated_config.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -992,10 +992,10 @@ Show full signature of the callable. Only shows parameters if disabled.
992992
--
993993
Show documentation.
994994
--
995-
[[rust-analyzer.typing.autoClosingAngleBrackets.enable]]rust-analyzer.typing.autoClosingAngleBrackets.enable (default: `false`)::
995+
[[rust-analyzer.typing.excludeChars]]rust-analyzer.typing.excludeChars (default: `null`)::
996996
+
997997
--
998-
Whether to insert closing angle brackets when typing an opening angle bracket of a generic argument list.
998+
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.
999999
--
10001000
[[rust-analyzer.workspace.discoverConfig]]rust-analyzer.workspace.discoverConfig (default: `null`)::
10011001
+

src/tools/rust-analyzer/editors/code/package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2605,10 +2605,13 @@
26052605
{
26062606
"title": "typing",
26072607
"properties": {
2608-
"rust-analyzer.typing.autoClosingAngleBrackets.enable": {
2609-
"markdownDescription": "Whether to insert closing angle brackets when typing an opening angle bracket of a generic argument list.",
2610-
"default": false,
2611-
"type": "boolean"
2608+
"rust-analyzer.typing.excludeChars": {
2609+
"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.",
2610+
"default": null,
2611+
"type": [
2612+
"null",
2613+
"string"
2614+
]
26122615
}
26132616
}
26142617
},

0 commit comments

Comments
 (0)