Skip to content

Commit 97907ca

Browse files
committed
Auto merge of rust-lang#18018 - ChayimFriedman2:unit-ret-complete-semi, r=Veykril
feat: Automatically add semicolon when completing unit-returning functions But provide a config to suppress that. I didn't check whether we are in statement expression position, because this is hard in completion (due to the natural incompleteness of source code when completion is invoked), and anyway using function returning unit as an argument to something seems... dubious. Fixes rust-lang#17263.
2 parents ec72a99 + ca262a3 commit 97907ca

File tree

12 files changed

+217
-40
lines changed

12 files changed

+217
-40
lines changed

src/tools/rust-analyzer/crates/ide-completion/src/completions/dot.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ fn foo(a: A) { a.$0 }
600600
struct A {}
601601
trait Trait { fn the_method(&self); }
602602
impl Trait for A {}
603-
fn foo(a: A) { a.the_method()$0 }
603+
fn foo(a: A) { a.the_method();$0 }
604604
"#,
605605
);
606606
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub struct CompletionConfig {
1919
pub term_search_fuel: u64,
2020
pub full_function_signatures: bool,
2121
pub callable: Option<CallableSnippets>,
22+
pub add_semicolon_to_unit: bool,
2223
pub snippet_cap: Option<SnippetCap>,
2324
pub insert_use: InsertUseConfig,
2425
pub prefer_no_std: bool,

src/tools/rust-analyzer/crates/ide-completion/src/render.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,7 +1185,7 @@ fn main() { fo$0 }
11851185
label: "main()",
11861186
source_range: 68..70,
11871187
delete: 68..70,
1188-
insert: "main()$0",
1188+
insert: "main();$0",
11891189
kind: SymbolKind(
11901190
Function,
11911191
),
@@ -1244,7 +1244,7 @@ fn main() { let _: m::Spam = S$0 }
12441244
label: "main()",
12451245
source_range: 75..76,
12461246
delete: 75..76,
1247-
insert: "main()$0",
1247+
insert: "main();$0",
12481248
kind: SymbolKind(
12491249
Function,
12501250
),
@@ -1331,7 +1331,7 @@ fn main() { som$0 }
13311331
label: "main()",
13321332
source_range: 56..59,
13331333
delete: 56..59,
1334-
insert: "main()$0",
1334+
insert: "main();$0",
13351335
kind: SymbolKind(
13361336
Function,
13371337
),
@@ -1342,7 +1342,7 @@ fn main() { som$0 }
13421342
label: "something_deprecated()",
13431343
source_range: 56..59,
13441344
delete: 56..59,
1345-
insert: "something_deprecated()$0",
1345+
insert: "something_deprecated();$0",
13461346
kind: SymbolKind(
13471347
Function,
13481348
),
@@ -1413,7 +1413,7 @@ impl S {
14131413
label: "bar()",
14141414
source_range: 94..94,
14151415
delete: 94..94,
1416-
insert: "bar()$0",
1416+
insert: "bar();$0",
14171417
kind: SymbolKind(
14181418
Method,
14191419
),
@@ -1540,7 +1540,7 @@ fn foo(s: S) { s.$0 }
15401540
label: "the_method()",
15411541
source_range: 81..81,
15421542
delete: 81..81,
1543-
insert: "the_method()$0",
1543+
insert: "the_method();$0",
15441544
kind: SymbolKind(
15451545
Method,
15461546
),
@@ -2789,7 +2789,7 @@ fn main() {
27892789
r#"
27902790
mod m { pub fn r#type {} }
27912791
fn main() {
2792-
m::r#type()$0
2792+
m::r#type();$0
27932793
}
27942794
"#,
27952795
)
@@ -2963,7 +2963,7 @@ fn main() {
29632963
label: "flush()",
29642964
source_range: 193..193,
29652965
delete: 193..193,
2966-
insert: "flush()$0",
2966+
insert: "flush();$0",
29672967
kind: SymbolKind(
29682968
Method,
29692969
),
@@ -2990,7 +2990,7 @@ fn main() {
29902990
label: "write()",
29912991
source_range: 193..193,
29922992
delete: 193..193,
2993-
insert: "write()$0",
2993+
insert: "write();$0",
29942994
kind: SymbolKind(
29952995
Method,
29962996
),

0 commit comments

Comments
 (0)