Skip to content

internal: Make autoclosing angle brackets configurable, disabled by default #12382

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions crates/ide/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,11 +342,16 @@ impl Analysis {
&self,
position: FilePosition,
char_typed: char,
autoclose: bool,
) -> Cancellable<Option<SourceChange>> {
// Fast path to not even parse the file.
if !typing::TRIGGER_CHARS.contains(char_typed) {
return Ok(None);
}
if char_typed == '<' && !autoclose {
return Ok(None);
}

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

Expand Down
2 changes: 1 addition & 1 deletion crates/ide/src/typing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ fn on_char_typed_inner(
'<' => on_left_angle_typed(&file.tree(), offset),
'>' => conv(on_right_angle_typed(&file.tree(), offset)),
'{' => conv(on_opening_brace_typed(file, offset)),
_ => unreachable!(),
_ => return None,
};

fn conv(text_edit: Option<TextEdit>) -> Option<ExtendedTextEdit> {
Expand Down
7 changes: 7 additions & 0 deletions crates/rust-analyzer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,9 @@ config_data! {
/// Show documentation.
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: WorkspaceSymbolSearchKindDef = "\"only_types\"",
/// Limits the number of items returned from a workspace symbol search (Defaults to 128).
Expand Down Expand Up @@ -1220,6 +1223,10 @@ impl Config {
n => n,
}
}

pub fn typing_autoclose_angle(&self) -> bool {
self.data.typing_autoClosingAngleBrackets_enable
}
}
// Deserialization definitions

Expand Down
3 changes: 2 additions & 1 deletion crates/rust-analyzer/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,8 @@ pub(crate) fn handle_on_type_formatting(
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 {
Some(it) => it,
None => return Ok(None),
Expand Down
5 changes: 5 additions & 0 deletions docs/user/generated_config.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,11 @@ Show full signature of the callable. Only shows parameters if disabled.
--
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"`)::
+
--
Expand Down
5 changes: 5 additions & 0 deletions editors/code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,11 @@
"default": true,
"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": {
"markdownDescription": "Workspace symbol search kind.",
"default": "only_types",
Expand Down