display varargs in completion detail

This commit is contained in:
Andy Russell 2025-03-15 10:33:31 -04:00
parent e3b3d9ee59
commit e9403853c0
No known key found for this signature in database
GPG key ID: BE2221033EDBC374
3 changed files with 58 additions and 1 deletions

View file

@ -2374,6 +2374,10 @@ impl Function {
db.function_data(self.id).is_async()
}
pub fn is_varargs(self, db: &dyn HirDatabase) -> bool {
db.function_data(self.id).is_varargs()
}
pub fn extern_block(self, db: &dyn HirDatabase) -> Option<ExternBlock> {
match self.id.lookup(db.upcast()).container {
ItemContainerId::ExternBlockId(id) => Some(ExternBlock { id }),

View file

@ -1276,6 +1276,53 @@ fn main() { fo$0 }
);
}
#[test]
fn fn_detail_includes_variadics() {
check(
r#"
unsafe extern "C" fn foo(a: u32, b: u32, ...) {}
fn main() { fo$0 }
"#,
SymbolKind::Function,
expect![[r#"
[
CompletionItem {
label: "foo(…)",
detail_left: None,
detail_right: Some(
"unsafe fn(u32, u32, ...)",
),
source_range: 62..64,
delete: 62..64,
insert: "foo(${1:a}, ${2:b});$0",
kind: SymbolKind(
Function,
),
lookup: "foo",
detail: "unsafe fn(u32, u32, ...)",
trigger_call_info: true,
},
CompletionItem {
label: "main()",
detail_left: None,
detail_right: Some(
"fn()",
),
source_range: 62..64,
delete: 62..64,
insert: "main();$0",
kind: SymbolKind(
Function,
),
lookup: "main",
detail: "fn()",
},
]
"#]],
);
}
#[test]
fn enum_detail_just_name_for_unit() {
check(

View file

@ -347,7 +347,7 @@ fn detail_full(ctx: &CompletionContext<'_>, func: hir::Function) -> String {
}
fn params_display(ctx: &CompletionContext<'_>, func: hir::Function) -> String {
if let Some(self_param) = func.self_param(ctx.db) {
let mut params = if let Some(self_param) = func.self_param(ctx.db) {
let assoc_fn_params = func.assoc_fn_params(ctx.db);
let params = assoc_fn_params
.iter()
@ -364,7 +364,13 @@ fn params_display(ctx: &CompletionContext<'_>, func: hir::Function) -> String {
} else {
let assoc_fn_params = func.assoc_fn_params(ctx.db);
assoc_fn_params.iter().map(|p| p.ty().display(ctx.db, ctx.display_target)).join(", ")
};
if func.is_varargs(ctx.db) {
params.push_str(", ...");
}
params
}
fn params(