From fc8d548a9abedfe85d0896755a85e24f60028f65 Mon Sep 17 00:00:00 2001 From: psznm Date: Wed, 26 Aug 2026 15:07:38 +0200 Subject: [PATCH] Optional first param is valid to use --- src/analysis.zig | 6 +++++- tests/lsp_features/completion.zig | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/analysis.zig b/src/analysis.zig index 1c3d9535d..a39354ffa 100644 --- a/src/analysis.zig +++ b/src/analysis.zig @@ -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, }; diff --git a/tests/lsp_features/completion.zig b/tests/lsp_features/completion.zig index e2707393f..8bc28f438 100644 --- a/tests/lsp_features/completion.zig +++ b/tests/lsp_features/completion.zig @@ -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. + \\ } + \\ 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" {