Skip to content

Commit 8b5816b

Browse files
authored
Merge pull request #19363 from euclio/varargs-detail
display varargs in completion detail
2 parents 6675b58 + e940385 commit 8b5816b

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

crates/hir/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2363,6 +2363,10 @@ impl Function {
23632363
db.function_data(self.id).is_async()
23642364
}
23652365

2366+
pub fn is_varargs(self, db: &dyn HirDatabase) -> bool {
2367+
db.function_data(self.id).is_varargs()
2368+
}
2369+
23662370
pub fn extern_block(self, db: &dyn HirDatabase) -> Option<ExternBlock> {
23672371
match self.id.lookup(db.upcast()).container {
23682372
ItemContainerId::ExternBlockId(id) => Some(ExternBlock { id }),

crates/ide-completion/src/render.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,6 +1276,53 @@ fn main() { fo$0 }
12761276
);
12771277
}
12781278

1279+
#[test]
1280+
fn fn_detail_includes_variadics() {
1281+
check(
1282+
r#"
1283+
unsafe extern "C" fn foo(a: u32, b: u32, ...) {}
1284+
1285+
fn main() { fo$0 }
1286+
"#,
1287+
SymbolKind::Function,
1288+
expect![[r#"
1289+
[
1290+
CompletionItem {
1291+
label: "foo(…)",
1292+
detail_left: None,
1293+
detail_right: Some(
1294+
"unsafe fn(u32, u32, ...)",
1295+
),
1296+
source_range: 62..64,
1297+
delete: 62..64,
1298+
insert: "foo(${1:a}, ${2:b});$0",
1299+
kind: SymbolKind(
1300+
Function,
1301+
),
1302+
lookup: "foo",
1303+
detail: "unsafe fn(u32, u32, ...)",
1304+
trigger_call_info: true,
1305+
},
1306+
CompletionItem {
1307+
label: "main()",
1308+
detail_left: None,
1309+
detail_right: Some(
1310+
"fn()",
1311+
),
1312+
source_range: 62..64,
1313+
delete: 62..64,
1314+
insert: "main();$0",
1315+
kind: SymbolKind(
1316+
Function,
1317+
),
1318+
lookup: "main",
1319+
detail: "fn()",
1320+
},
1321+
]
1322+
"#]],
1323+
);
1324+
}
1325+
12791326
#[test]
12801327
fn enum_detail_just_name_for_unit() {
12811328
check(

crates/ide-completion/src/render/function.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ fn detail_full(ctx: &CompletionContext<'_>, func: hir::Function) -> String {
343343
}
344344

345345
fn params_display(ctx: &CompletionContext<'_>, func: hir::Function) -> String {
346-
if let Some(self_param) = func.self_param(ctx.db) {
346+
let mut params = if let Some(self_param) = func.self_param(ctx.db) {
347347
let assoc_fn_params = func.assoc_fn_params(ctx.db);
348348
let params = assoc_fn_params
349349
.iter()
@@ -360,7 +360,13 @@ fn params_display(ctx: &CompletionContext<'_>, func: hir::Function) -> String {
360360
} else {
361361
let assoc_fn_params = func.assoc_fn_params(ctx.db);
362362
assoc_fn_params.iter().map(|p| p.ty().display(ctx.db, ctx.display_target)).join(", ")
363+
};
364+
365+
if func.is_varargs(ctx.db) {
366+
params.push_str(", ...");
363367
}
368+
369+
params
364370
}
365371

366372
fn params(

0 commit comments

Comments
 (0)