From 63cc1082bb3fe48016eb27713fffc5b02e119ca4 Mon Sep 17 00:00:00 2001 From: fomgleb Date: Mon, 11 May 2026 15:23:18 +0300 Subject: [PATCH] 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. --- src/analysis.zig | 8 ++++---- tests/lsp_features/completion.zig | 3 +++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/analysis.zig b/src/analysis.zig index 1c3d9535d..db59af829 100644 --- a/src/analysis.zig +++ b/src/analysis.zig @@ -461,16 +461,16 @@ pub fn firstParamIs( const deref_type = switch (resolved_type.data) { .pointer => |info| switch (info.size) { - .one => info.elem_ty.*, - .many, .slice, .c => return false, + .one, .c => info.elem_ty.*, + .many, .slice => return false, }, else => resolved_type, }; const deref_expected_type = switch (expected_type.data) { .pointer => |info| switch (info.size) { - .one => info.elem_ty.*, - .many, .slice, .c => return false, + .one, .c => info.elem_ty.*, + .many, .slice => return false, }, else => expected_type, }; diff --git a/tests/lsp_features/completion.zig b/tests/lsp_features/completion.zig index e2707393f..15bba2389 100644 --- a/tests/lsp_features/completion.zig +++ b/tests/lsp_features/completion.zig @@ -1337,11 +1337,13 @@ test "struct" { \\fn fooImpl(_: Foo) void {} \\fn barImpl(_: *const Foo) void {} \\fn bazImpl(_: u32) void {} + \\fn quxImpl(_: [*c]const Foo) void {} \\const Foo = struct { \\ alpha: u32, \\ pub const foo = fooImpl; \\ pub const bar = barImpl; \\ pub const baz = bazImpl; + \\ pub const qux = quxImpl; \\}; \\const foo = Foo{}; \\const baz = foo.; @@ -1349,6 +1351,7 @@ test "struct" { .{ .label = "alpha", .kind = .Field, .detail = "u32" }, .{ .label = "foo", .kind = .Method, .detail = "fn (_: Foo) void" }, .{ .label = "bar", .kind = .Method, .detail = "fn (_: *const Foo) void" }, + .{ .label = "qux", .kind = .Method, .detail = "fn (_: [*c]const Foo) void" }, }); try testCompletion( \\alpha: u32,