Skip to content
Open
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
6 changes: 5 additions & 1 deletion src/analysis.zig
Original file line number Diff line number Diff line change
Expand Up @@ -459,11 +459,15 @@ pub fn firstParamIs(
if (!resolved_type.is_type_val) return false;
if (resolved_type.data == .anytype_parameter) return true;

const deref_type = switch (resolved_type.data) {
const deref_type = deref: switch (resolved_type.data) {
.pointer => |info| switch (info.size) {
.one => info.elem_ty.*,
.many, .slice, .c => return false,
},
.optional => |opt| switch (opt.data) {
.pointer => continue :deref opt.data,
else => opt.*,
},
else => resolved_type,
};

Expand Down
16 changes: 16 additions & 0 deletions tests/lsp_features/completion.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1377,6 +1377,22 @@ test "struct" {
.{ .label = "alpha", .kind = .Field, .detail = "u32" },
.{ .label = "beta", .kind = .Field, .detail = "[]const u8" },
});

try testCompletion(
\\const S = struct {
\\ alpha: u32,
\\ fn foo(self: S) void {
\\ self.<cursor>
\\ }
\\ fn optPtr(_: ?*S) void {}
\\ fn optValue(_: ?S) void {}
\\};
, &.{
.{ .label = "alpha", .kind = .Field, .detail = "u32" },
.{ .label = "foo", .kind = .Method, .detail = "fn (self: S) void" },
.{ .label = "optPtr", .kind = .Method, .detail = "fn (_: ?*S) void" },
.{ .label = "optValue", .kind = .Method, .detail = "fn (_: ?S) void" },
});
}

test "union" {
Expand Down
Loading