From a16fb19797d627a6cd500065aacee098c624a66c Mon Sep 17 00:00:00 2001 From: Techatrix <19954306+Techatrix@users.noreply.github.com> Date: Sat, 24 Jun 2023 01:25:12 +0000 Subject: [PATCH] improve self param detection in inlay hints (#1258) --- src/features/inlay_hints.zig | 5 ++++- tests/lsp_features/inlay_hints.zig | 12 ++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/features/inlay_hints.zig b/src/features/inlay_hints.zig index 8fb4ad8..6e80af3 100644 --- a/src/features/inlay_hints.zig +++ b/src/features/inlay_hints.zig @@ -87,7 +87,10 @@ fn writeCallHint(builder: *Builder, call: Ast.full.Call, decl_handle: Analyser.D var i: usize = 0; 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); } diff --git a/tests/lsp_features/inlay_hints.zig b/tests/lsp_features/inlay_hints.zig index 111477a..762d91a 100644 --- a/tests/lsp_features/inlay_hints.zig +++ b/tests/lsp_features/inlay_hints.zig @@ -48,6 +48,18 @@ test "inlayhints - function self parameter" { \\const foo: Foo = .{}; \\const _ = foo.bar(5,""); ); + try testInlayHints( + \\const Foo = struct { pub fn bar(self: Foo, alpha: u32, beta: []const u8) void {} }; + \\const _ = Foo.bar(undefined,5,""); + ); + try testInlayHints( + \\const Foo = struct { + \\ pub fn bar(self: Foo, alpha: u32, beta: []const u8) void {} + \\ pub fn foo() void { + \\ bar(undefined,5,""); + \\ } + \\}; + ); } test "inlayhints - builtin call" {