Skip to content

Commit

Permalink
Auto merge of #18018 - ChayimFriedman2:unit-ret-complete-semi, r=Veykril
Browse files Browse the repository at this point in the history
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 #17263.
  • Loading branch information
bors committed Sep 11, 2024
2 parents ec72a99 + ca262a3 commit 97907ca
Show file tree
Hide file tree
Showing 12 changed files with 217 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ fn foo(a: A) { a.$0 }
struct A {}
trait Trait { fn the_method(&self); }
impl Trait for A {}
fn foo(a: A) { a.the_method()$0 }
fn foo(a: A) { a.the_method();$0 }
"#,
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub struct CompletionConfig {
pub term_search_fuel: u64,
pub full_function_signatures: bool,
pub callable: Option<CallableSnippets>,
pub add_semicolon_to_unit: bool,
pub snippet_cap: Option<SnippetCap>,
pub insert_use: InsertUseConfig,
pub prefer_no_std: bool,
Expand Down
18 changes: 9 additions & 9 deletions src/tools/rust-analyzer/crates/ide-completion/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,7 @@ fn main() { fo$0 }
label: "main()",
source_range: 68..70,
delete: 68..70,
insert: "main()$0",
insert: "main();$0",
kind: SymbolKind(
Function,
),
Expand Down Expand Up @@ -1244,7 +1244,7 @@ fn main() { let _: m::Spam = S$0 }
label: "main()",
source_range: 75..76,
delete: 75..76,
insert: "main()$0",
insert: "main();$0",
kind: SymbolKind(
Function,
),
Expand Down Expand Up @@ -1331,7 +1331,7 @@ fn main() { som$0 }
label: "main()",
source_range: 56..59,
delete: 56..59,
insert: "main()$0",
insert: "main();$0",
kind: SymbolKind(
Function,
),
Expand All @@ -1342,7 +1342,7 @@ fn main() { som$0 }
label: "something_deprecated()",
source_range: 56..59,
delete: 56..59,
insert: "something_deprecated()$0",
insert: "something_deprecated();$0",
kind: SymbolKind(
Function,
),
Expand Down Expand Up @@ -1413,7 +1413,7 @@ impl S {
label: "bar()",
source_range: 94..94,
delete: 94..94,
insert: "bar()$0",
insert: "bar();$0",
kind: SymbolKind(
Method,
),
Expand Down Expand Up @@ -1540,7 +1540,7 @@ fn foo(s: S) { s.$0 }
label: "the_method()",
source_range: 81..81,
delete: 81..81,
insert: "the_method()$0",
insert: "the_method();$0",
kind: SymbolKind(
Method,
),
Expand Down Expand Up @@ -2789,7 +2789,7 @@ fn main() {
r#"
mod m { pub fn r#type {} }
fn main() {
m::r#type()$0
m::r#type();$0
}
"#,
)
Expand Down Expand Up @@ -2963,7 +2963,7 @@ fn main() {
label: "flush()",
source_range: 193..193,
delete: 193..193,
insert: "flush()$0",
insert: "flush();$0",
kind: SymbolKind(
Method,
),
Expand All @@ -2990,7 +2990,7 @@ fn main() {
label: "write()",
source_range: 193..193,
delete: 193..193,
insert: "write()$0",
insert: "write();$0",
kind: SymbolKind(
Method,
),
Expand Down
Loading

0 comments on commit 97907ca

Please sign in to comment.