Skip to content

Allow C pointers as valid self parameters in method detection#3198

Merged
Techatrix merged 1 commit into
zigtools:0.16.xfrom
fomgleb:0.16.x
May 14, 2026
Merged

Allow C pointers as valid self parameters in method detection#3198
Techatrix merged 1 commit into
zigtools:0.16.xfrom
fomgleb:0.16.x

Conversation

@fomgleb
Copy link
Copy Markdown
Contributor

@fomgleb fomgleb commented May 11, 2026

The language server was not recognizing methods with C pointer receivers ([*c]T) as valid methods on their container types. This meant that when working with C interop code, functions like fuse_opt_parse declared with [*c]struct_fuse_args parameters were not being offered as method completions on instances of struct_fuse_args.

Example of generated cimport.zig:

pub const struct_fuse_args = extern struct {
    argc: c_int = 0,
    argv: [*c][*c]u8 = null,
    allocated: c_int = 0,
    pub const fuse_opt_parse = __root.fuse_opt_parse;
    pub const parse = __root.fuse_opt_parse;
};
// Here, generated with `[*c]` pointer.
pub extern fn fuse_opt_parse(args: [*c]struct_fuse_args, data: ?*anyopaque, opts: [*c]const struct_fuse_opt, proc: fuse_opt_proc_t) c_int;
var fuse_args: c.struct_fuse_args = .{};

// This compiles, but no method completion was offered:
_ = fuse_args.parse(&options, &option_spec, null);

Solution

Updated firstParamIs to treat .c pointers the same as .one pointers when matching the container type.

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.
@Techatrix Techatrix changed the base branch from 0.16.x to master May 12, 2026 14:45
@Techatrix Techatrix changed the base branch from master to 0.16.x May 12, 2026 14:45
@Techatrix
Copy link
Copy Markdown
Member

Please send pull requests to the default branch (i.e. "master") instead of 0.16.x unless the change does not apply to master branch. Given that I deem this change eligible to be cherry picked into 0.16.x anyway, it's not a problem in this particular case.

@Techatrix Techatrix merged commit 469634b into zigtools:0.16.x May 14, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants