improve self param detection in inlay hints (#1258)

This commit is contained in:
Techatrix 2023-06-24 01:25:12 +00:00 committed by GitHub
parent 7e19a88ad2
commit a16fb19797
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View File

@ -87,7 +87,10 @@ fn writeCallHint(builder: *Builder, call: Ast.full.Call, decl_handle: Analyser.D
var i: usize = 0; var i: usize = 0;
var it = fn_proto.iterate(&decl_tree); var it = fn_proto.iterate(&decl_tree);
if (try builder.analyser.hasSelfParam(decl_handle.handle, fn_proto)) { if (tree.tokens.items(.tag)[call.ast.lparen - 2] == .period and
call.ast.params.len + 1 == fn_proto.ast.params.len and
try builder.analyser.hasSelfParam(decl_handle.handle, fn_proto))
{
_ = ast.nextFnParam(&it); _ = ast.nextFnParam(&it);
} }

View File

@ -48,6 +48,18 @@ test "inlayhints - function self parameter" {
\\const foo: Foo = .{}; \\const foo: Foo = .{};
\\const _ = foo.bar(<alpha>5,<beta>""); \\const _ = foo.bar(<alpha>5,<beta>"");
); );
try testInlayHints(
\\const Foo = struct { pub fn bar(self: Foo, alpha: u32, beta: []const u8) void {} };
\\const _ = Foo.bar(<self>undefined,<alpha>5,<beta>"");
);
try testInlayHints(
\\const Foo = struct {
\\ pub fn bar(self: Foo, alpha: u32, beta: []const u8) void {}
\\ pub fn foo() void {
\\ bar(<self>undefined,<alpha>5,<beta>"");
\\ }
\\};
);
} }
test "inlayhints - builtin call" { test "inlayhints - builtin call" {