diff --git a/src/Config.zig b/src/Config.zig index 00d5552..5b4df43 100644 --- a/src/Config.zig +++ b/src/Config.zig @@ -52,6 +52,14 @@ inlay_hints_show_builtin: bool = true, /// don't show inlay hints for single argument calls inlay_hints_exclude_single_argument: bool = true, +/// don't show inlay hints when parameter name matches the identifier +/// for example: `foo: foo` +inlay_hints_hide_redundant_param_names: bool = false, + +/// don't show inlay hints when parameter names matches the last +/// for example: `foo: bar.foo`, `foo: &foo` +inlay_hints_hide_redundant_param_names_last_token: bool = false, + /// Whether to enable `*` and `?` operators in completion lists operator_completions: bool = true, @@ -69,8 +77,6 @@ skip_std_references: bool = false, builtin_path: ?[]const u8 = null, pub fn loadFromFile(allocator: std.mem.Allocator, file_path: []const u8) ?Config { - @setEvalBranchQuota(5000); - const tracy_zone = tracy.trace(@src()); defer tracy_zone.end(); @@ -84,7 +90,7 @@ pub fn loadFromFile(allocator: std.mem.Allocator, file_path: []const u8) ?Config const file_buf = file.readToEndAlloc(allocator, 0x1000000) catch return null; defer allocator.free(file_buf); - @setEvalBranchQuota(3000); + @setEvalBranchQuota(7000); const parse_options = std.json.ParseOptions{ .allocator = allocator, .ignore_unknown_fields = true }; // TODO: Better errors? Doesn't seem like std.json can provide us positions or context. var config = std.json.parse(Config, &std.json.TokenStream.init(file_buf), parse_options) catch |err| { diff --git a/src/inlay_hints.zig b/src/inlay_hints.zig index 032f2ff..0cba1d0 100644 --- a/src/inlay_hints.zig +++ b/src/inlay_hints.zig @@ -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, diff --git a/src/requests.zig b/src/requests.zig index 522d5d1..d4970b1 100644 --- a/src/requests.zig +++ b/src/requests.zig @@ -300,6 +300,8 @@ pub const Configuration = struct { enable_inlay_hints: ?bool, inlay_hints_show_builtin: ?bool, inlay_hints_exclude_single_argument: ?bool, + inlay_hints_hide_redundant_param_names: ?bool, + inlay_hints_hide_redundant_param_names_last_token: ?bool, operator_completions: ?bool, include_at_in_builtins: ?bool, max_detail_length: ?usize,