Skip to content

Commit

Permalink
resolve var decl aliases of functions in inlay hints
Browse files Browse the repository at this point in the history
  • Loading branch information
Techatrix authored and leecannon committed Jun 28, 2023
1 parent 844b4a8 commit e7af795
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/features/inlay_hints.zig
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,21 @@ fn writeCallHint(builder: *Builder, call: Ast.full.Call, decl_handle: Analyser.D
const handle = builder.handle;
const tree = handle.tree;

const decl = decl_handle.decl;
const decl_tree = decl_handle.handle.tree;
const node = switch (decl_handle.decl.*) {
.ast_node => |node| node,
else => return,
};

const fn_node = switch (decl.*) {
const maybe_resolved_alias = try builder.analyser.resolveVarDeclAlias(.{ .node = node, .handle = decl_handle.handle });
const resolved_decl_handle = if (maybe_resolved_alias) |resolved_decl| resolved_decl else decl_handle;

const fn_node = switch (resolved_decl_handle.decl.*) {
.ast_node => |fn_node| fn_node,
else => return,
};

const decl_tree = resolved_decl_handle.handle.tree;

var buffer: [1]Ast.Node.Index = undefined;
const fn_proto = decl_tree.fullFnProto(&buffer, fn_node) orelse return;

Expand All @@ -99,7 +106,7 @@ fn writeCallHint(builder: *Builder, call: Ast.full.Call, decl_handle: Analyser.D
const parameters = params.items[@intFromBool(has_self_param)..];
const arguments = call.ast.params;
const min_len = @min(parameters.len, arguments.len);
for (parameters[0..min_len], call.ast.params[0..min_len]) |param, arg| {
for (parameters[0..min_len], arguments[0..min_len]) |param, arg| {
const name_token = param.name_token orelse continue;
const name = decl_tree.tokenSlice(name_token);

Expand Down
8 changes: 8 additions & 0 deletions tests/lsp_features/inlay_hints.zig
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ test "inlayhints - function self parameter" {
);
}

test "inlayhints - resolve alias" {
try testInlayHints(
\\fn foo(alpha: u32) void {}
\\const bar = foo;
\\const _ = bar(<alpha>5);
);
}

test "inlayhints - builtin call" {
try testInlayHints(
\\const _ = @memcpy(<dest>"",<source>"");
Expand Down

0 comments on commit e7af795

Please sign in to comment.