Skip to content

Commit 63cc108

Browse files
committed
Allow C pointers as valid self parameters in method detection
This change updates firstParamIs to accept `[*c]T` pointers as equivalent to `*T` pointers when checking if a function's first parameter matches the container type, enabling proper method completion for functions with C pointer receivers.
1 parent 4d41bbb commit 63cc108

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

src/analysis.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -461,16 +461,16 @@ pub fn firstParamIs(
461461

462462
const deref_type = switch (resolved_type.data) {
463463
.pointer => |info| switch (info.size) {
464-
.one => info.elem_ty.*,
465-
.many, .slice, .c => return false,
464+
.one, .c => info.elem_ty.*,
465+
.many, .slice => return false,
466466
},
467467
else => resolved_type,
468468
};
469469

470470
const deref_expected_type = switch (expected_type.data) {
471471
.pointer => |info| switch (info.size) {
472-
.one => info.elem_ty.*,
473-
.many, .slice, .c => return false,
472+
.one, .c => info.elem_ty.*,
473+
.many, .slice => return false,
474474
},
475475
else => expected_type,
476476
};

tests/lsp_features/completion.zig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,18 +1337,21 @@ test "struct" {
13371337
\\fn fooImpl(_: Foo) void {}
13381338
\\fn barImpl(_: *const Foo) void {}
13391339
\\fn bazImpl(_: u32) void {}
1340+
\\fn quxImpl(_: [*c]const Foo) void {}
13401341
\\const Foo = struct {
13411342
\\ alpha: u32,
13421343
\\ pub const foo = fooImpl;
13431344
\\ pub const bar = barImpl;
13441345
\\ pub const baz = bazImpl;
1346+
\\ pub const qux = quxImpl;
13451347
\\};
13461348
\\const foo = Foo{};
13471349
\\const baz = foo.<cursor>;
13481350
, &.{
13491351
.{ .label = "alpha", .kind = .Field, .detail = "u32" },
13501352
.{ .label = "foo", .kind = .Method, .detail = "fn (_: Foo) void" },
13511353
.{ .label = "bar", .kind = .Method, .detail = "fn (_: *const Foo) void" },
1354+
.{ .label = "qux", .kind = .Method, .detail = "fn (_: [*c]const Foo) void" },
13521355
});
13531356
try testCompletion(
13541357
\\alpha: u32,

0 commit comments

Comments
 (0)