Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/features/signature_help.zig
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fn fnProtoToSignatureInfo(
analyser: *Analyser,
arena: std.mem.Allocator,
commas: u32,
skip_self_param: bool,
container_ty: ?Analyser.Type,
func_type: Analyser.Type,
markup_kind: types.MarkupKind,
) error{OutOfMemory}!types.SignatureHelp.Signature {
Expand All @@ -76,8 +76,8 @@ fn fnProtoToSignatureInfo(
.snippet_placeholders = false,
});

const arg_idx = if (skip_self_param) blk: {
const has_self_param = try analyser.hasSelfParam(func_type);
const arg_idx = if (container_ty) |expected_type| blk: {
const has_self_param = analyser.firstParamIs(func_type, expected_type);
break :blk commas + @intFromBool(has_self_param);
} else commas;

Expand Down Expand Up @@ -322,7 +322,7 @@ fn getSignatureInfo(
analyser,
arena,
paren_commas,
false,
null,
func_type,
markup_kind,
);
Expand All @@ -334,7 +334,7 @@ fn getSignatureInfo(
};
const name = offsets.locToSlice(handle.tree.source, name_loc);

const skip_self_param = !ty.is_type_val;
const container_ty = try ty.typeOf(analyser);
ty = try analyser.resolveFieldAccess(ty, name) orelse {
try symbol_stack.append(arena, .l_paren);
continue;
Expand All @@ -345,7 +345,7 @@ fn getSignatureInfo(
analyser,
arena,
paren_commas,
skip_self_param,
container_ty,
func_type,
markup_kind,
);
Expand Down
12 changes: 12 additions & 0 deletions tests/lsp_features/signature_help.zig
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,18 @@ test "self parameter" {
, "fn foo(self: *S, a: u32, b: void) bool", 2);
}

test "self parameter with aliased function" {
try testSignatureHelp(
\\fn fooImpl(self: S, a: u32, b: void) bool {}
\\const S = struct {
\\ alpha: u32,
\\ const foo = fooImpl;
\\};
\\const s: S = undefined;
\\const foo = s.foo(3,<cursor>);
, "fn fooImpl(self: S, a: u32, b: void) bool", 2);
}

test "self parameter is anytype" {
try testSignatureHelp(
\\const S = struct {
Expand Down
Loading