Skip to content

Commit 3fe137a

Browse files
committed
Auto merge of rust-lang#12382 - Veykril:ontype, r=lnicola
internal: Make autoclosing angle brackets configurable, disabled by default cc rust-lang/rust-analyzer#12379
2 parents d7c1474 + f02c915 commit 3fe137a

File tree

6 files changed

+25
-2
lines changed

6 files changed

+25
-2
lines changed

crates/ide/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,11 +342,16 @@ impl Analysis {
342342
&self,
343343
position: FilePosition,
344344
char_typed: char,
345+
autoclose: bool,
345346
) -> Cancellable<Option<SourceChange>> {
346347
// Fast path to not even parse the file.
347348
if !typing::TRIGGER_CHARS.contains(char_typed) {
348349
return Ok(None);
349350
}
351+
if char_typed == '<' && !autoclose {
352+
return Ok(None);
353+
}
354+
350355
self.with_db(|db| typing::on_char_typed(db, position, char_typed))
351356
}
352357

crates/ide/src/typing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ fn on_char_typed_inner(
9292
'<' => on_left_angle_typed(&file.tree(), offset),
9393
'>' => conv(on_right_angle_typed(&file.tree(), offset)),
9494
'{' => conv(on_opening_brace_typed(file, offset)),
95-
_ => unreachable!(),
95+
_ => return None,
9696
};
9797

9898
fn conv(text_edit: Option<TextEdit>) -> Option<ExtendedTextEdit> {

crates/rust-analyzer/src/config.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,9 @@ config_data! {
386386
/// Show documentation.
387387
signatureInfo_documentation_enable: bool = "true",
388388

389+
/// Whether to insert closing angle brackets when typing an opening angle bracket of a generic argument list.
390+
typing_autoClosingAngleBrackets_enable: bool = "false",
391+
389392
/// Workspace symbol search kind.
390393
workspace_symbol_search_kind: WorkspaceSymbolSearchKindDef = "\"only_types\"",
391394
/// Limits the number of items returned from a workspace symbol search (Defaults to 128).
@@ -1220,6 +1223,10 @@ impl Config {
12201223
n => n,
12211224
}
12221225
}
1226+
1227+
pub fn typing_autoclose_angle(&self) -> bool {
1228+
self.data.typing_autoClosingAngleBrackets_enable
1229+
}
12231230
}
12241231
// Deserialization definitions
12251232

crates/rust-analyzer/src/handlers.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,8 @@ pub(crate) fn handle_on_type_formatting(
299299
return Ok(None);
300300
}
301301

302-
let edit = snap.analysis.on_char_typed(position, char_typed)?;
302+
let edit =
303+
snap.analysis.on_char_typed(position, char_typed, snap.config.typing_autoclose_angle())?;
303304
let edit = match edit {
304305
Some(it) => it,
305306
None => return Ok(None),

docs/user/generated_config.adoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,11 @@ Show full signature of the callable. Only shows parameters if disabled.
593593
--
594594
Show documentation.
595595
--
596+
[[rust-analyzer.typing.autoClosingAngleBrackets.enable]]rust-analyzer.typing.autoClosingAngleBrackets.enable (default: `false`)::
597+
+
598+
--
599+
Whether to insert closing angle brackets when typing an opening angle bracket of a generic argument list.
600+
--
596601
[[rust-analyzer.workspace.symbol.search.kind]]rust-analyzer.workspace.symbol.search.kind (default: `"only_types"`)::
597602
+
598603
--

editors/code/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,6 +1068,11 @@
10681068
"default": true,
10691069
"type": "boolean"
10701070
},
1071+
"rust-analyzer.typing.autoClosingAngleBrackets.enable": {
1072+
"markdownDescription": "Whether to insert closing angle brackets when typing an opening angle bracket of a generic argument list.",
1073+
"default": false,
1074+
"type": "boolean"
1075+
},
10711076
"rust-analyzer.workspace.symbol.search.kind": {
10721077
"markdownDescription": "Workspace symbol search kind.",
10731078
"default": "only_types",

0 commit comments

Comments
 (0)