internal: Make autoclosing angle brackets configurable, disabled by default

This commit is contained in:
Lukas Wirth 2022-05-25 12:15:36 +02:00
parent d7c147406e
commit f02c915eb5
6 changed files with 25 additions and 2 deletions

View file

@ -342,11 +342,16 @@ impl Analysis {
&self, &self,
position: FilePosition, position: FilePosition,
char_typed: char, char_typed: char,
autoclose: bool,
) -> 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) {
return Ok(None); return Ok(None);
} }
if char_typed == '<' && !autoclose {
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

@ -92,7 +92,7 @@ fn on_char_typed_inner(
'<' => on_left_angle_typed(&file.tree(), offset), '<' => on_left_angle_typed(&file.tree(), offset),
'>' => conv(on_right_angle_typed(&file.tree(), offset)), '>' => conv(on_right_angle_typed(&file.tree(), offset)),
'{' => conv(on_opening_brace_typed(file, offset)), '{' => conv(on_opening_brace_typed(file, offset)),
_ => unreachable!(), _ => return None,
}; };
fn conv(text_edit: Option<TextEdit>) -> Option<ExtendedTextEdit> { fn conv(text_edit: Option<TextEdit>) -> Option<ExtendedTextEdit> {

View file

@ -386,6 +386,9 @@ config_data! {
/// Show documentation. /// Show documentation.
signatureInfo_documentation_enable: bool = "true", signatureInfo_documentation_enable: bool = "true",
/// Whether to insert closing angle brackets when typing an opening angle bracket of a generic argument list.
typing_autoClosingAngleBrackets_enable: bool = "false",
/// Workspace symbol search kind. /// Workspace symbol search kind.
workspace_symbol_search_kind: WorkspaceSymbolSearchKindDef = "\"only_types\"", workspace_symbol_search_kind: WorkspaceSymbolSearchKindDef = "\"only_types\"",
/// Limits the number of items returned from a workspace symbol search (Defaults to 128). /// Limits the number of items returned from a workspace symbol search (Defaults to 128).
@ -1220,6 +1223,10 @@ impl Config {
n => n, n => n,
} }
} }
pub fn typing_autoclose_angle(&self) -> bool {
self.data.typing_autoClosingAngleBrackets_enable
}
} }
// Deserialization definitions // Deserialization definitions

View file

@ -299,7 +299,8 @@ pub(crate) fn handle_on_type_formatting(
return Ok(None); return Ok(None);
} }
let edit = snap.analysis.on_char_typed(position, char_typed)?; let edit =
snap.analysis.on_char_typed(position, char_typed, snap.config.typing_autoclose_angle())?;
let edit = match edit { let edit = match edit {
Some(it) => it, Some(it) => it,
None => return Ok(None), None => return Ok(None),

View file

@ -593,6 +593,11 @@ Show full signature of the callable. Only shows parameters if disabled.
-- --
Show documentation. Show documentation.
-- --
[[rust-analyzer.typing.autoClosingAngleBrackets.enable]]rust-analyzer.typing.autoClosingAngleBrackets.enable (default: `false`)::
+
--
Whether to insert closing angle brackets when typing an opening angle bracket of a generic argument list.
--
[[rust-analyzer.workspace.symbol.search.kind]]rust-analyzer.workspace.symbol.search.kind (default: `"only_types"`):: [[rust-analyzer.workspace.symbol.search.kind]]rust-analyzer.workspace.symbol.search.kind (default: `"only_types"`)::
+ +
-- --

View file

@ -1068,6 +1068,11 @@
"default": true, "default": true,
"type": "boolean" "type": "boolean"
}, },
"rust-analyzer.typing.autoClosingAngleBrackets.enable": {
"markdownDescription": "Whether to insert closing angle brackets when typing an opening angle bracket of a generic argument list.",
"default": false,
"type": "boolean"
},
"rust-analyzer.workspace.symbol.search.kind": { "rust-analyzer.workspace.symbol.search.kind": {
"markdownDescription": "Workspace symbol search kind.", "markdownDescription": "Workspace symbol search kind.",
"default": "only_types", "default": "only_types",