internal: Make exclude characters for typing assists configurable, default to None

Signed-off-by: Tarek <tareknaser360@gmail.com>
This commit is contained in:
Tarek 2024-11-17 15:25:23 +02:00
parent e6276c8b64
commit d6b701e251
5 changed files with 37 additions and 2 deletions

View file

@ -411,6 +411,7 @@ impl Analysis {
position: FilePosition, position: FilePosition,
char_typed: char, char_typed: char,
autoclose: bool, autoclose: bool,
chars_to_exclude: Option<String>,
) -> Cancellable<Option<SourceChange>> { ) -> Cancellable<Option<SourceChange>> {
// Fast path to not even parse the file. // Fast path to not even parse the file.
if !typing::TRIGGER_CHARS.contains(char_typed) { if !typing::TRIGGER_CHARS.contains(char_typed) {
@ -419,6 +420,11 @@ impl Analysis {
if char_typed == '<' && !autoclose { if char_typed == '<' && !autoclose {
return Ok(None); 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)) self.with_db(|db| typing::on_char_typed(db, position, char_typed))
} }

View file

@ -310,6 +310,8 @@ config_data! {
/// Whether to insert closing angle brackets when typing an opening angle bracket of a generic argument list. /// Whether to insert closing angle brackets when typing an opening angle bracket of a generic argument list.
typing_autoClosingAngleBrackets_enable: bool = false, 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`]. /// Enables automatic discovery of projects using [`DiscoverWorkspaceConfig::command`].
@ -2160,6 +2162,10 @@ impl Config {
*self.typing_autoClosingAngleBrackets_enable() *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 // VSCode is our reference implementation, so we allow ourselves to work around issues by
// special casing certain versions // special casing certain versions
pub fn visual_studio_code_version(&self) -> Option<&Version> { pub fn visual_studio_code_version(&self) -> Option<&Version> {

View file

@ -459,9 +459,14 @@ pub(crate) fn handle_on_type_formatting(
if char_typed == '>' { if char_typed == '>' {
return Ok(None); return Ok(None);
} }
let chars_to_exclude = snap.config.typing_exclude_chars();
let edit = let edit = snap.analysis.on_char_typed(
snap.analysis.on_char_typed(position, char_typed, snap.config.typing_autoclose_angle())?; position,
char_typed,
snap.config.typing_autoclose_angle(),
chars_to_exclude,
)?;
let edit = match edit { let edit = match edit {
Some(it) => it, Some(it) => it,
None => return Ok(None), None => return Ok(None),

View file

@ -997,6 +997,11 @@ Show documentation.
-- --
Whether to insert closing angle brackets when typing an opening angle bracket of a generic argument list. 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`):: [[rust-analyzer.workspace.discoverConfig]]rust-analyzer.workspace.discoverConfig (default: `null`)::
+ +
-- --

View file

@ -2612,6 +2612,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", "title": "workspace",
"properties": { "properties": {