inlay_hints: implement ability to remove redundant hints (#690)

This commit is contained in:
Vesim
2022-09-29 20:36:29 +02:00
committed by GitHub
parent 9f2ea75777
commit 32ce19f9a8
3 changed files with 29 additions and 5 deletions

View File

@@ -99,8 +99,24 @@ fn writeCallHint(builder: *Builder, arena: *std.heap.ArenaAllocator, store: *Doc
}
while (ast.nextFnParam(&it)) |param| : (i += 1) {
const name_token = param.name_token orelse continue;
if (i >= call.ast.params.len) break;
const name_token = param.name_token orelse continue;
const name = decl_tree.tokenSlice(name_token);
if (builder.config.inlay_hints_hide_redundant_param_names or builder.config.inlay_hints_hide_redundant_param_names_last_token) {
const last_param_token = tree.lastToken(call.ast.params[i]);
const param_name = tree.tokenSlice(last_param_token);
if (std.mem.eql(u8, param_name, name)) {
if (tree.firstToken(call.ast.params[i]) == last_param_token) {
if (builder.config.inlay_hints_hide_redundant_param_names)
continue;
} else {
if (builder.config.inlay_hints_hide_redundant_param_names_last_token)
continue;
}
}
}
const token_tags = decl_tree.tokens.items(.tag);
@@ -114,7 +130,7 @@ fn writeCallHint(builder: *Builder, arena: *std.heap.ArenaAllocator, store: *Doc
try builder.appendParameterHint(
offsets.tokenToPosition(tree, tree.firstToken(call.ast.params[i]), builder.encoding),
decl_tree.tokenSlice(name_token),
name,
tooltip,
no_alias,
comp_time,