Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

completions for anonymous struct parameters only happen if the struct type and function are defined in a different file #1617

Closed
xdBronch opened this issue Nov 22, 2023 · 7 comments
Labels
bug Something isn't working

Comments

@xdBronch
Copy link
Contributor

Zig Version

0.12.0-dev.1680+be6f76655

Zig Language Server Version

0.12.0-dev.248+62f17ab

Steps to Reproduce

// main.zig
pub fn main() void {
    foo(.{<cursor>});
}

const Config = struct {
    conf: void,
};

fn foo(_: Config) void {}

request completions, none appear. move Config and foo into a separate file

// import.zig
pub const Config = struct {
    conf: void,
};

pub fn foo(_: Config) void {}
/////////////////////////////
// main.zig
const import = @import("import.zig");

pub fn main() void {
    import.foo(.{<cursor>});
}

request completions and they correctly appear

Expected Behavior

completions should always be given

Actual Behavior

inconsistent

@xdBronch xdBronch added the bug Something isn't working label Nov 22, 2023
@llogick
Copy link
Contributor

llogick commented Nov 22, 2023

Parser limitation - try it with #1536 or 1. instead of just ..

It has to do with syntax errors and the type node being after the current node.

@xdBronch
Copy link
Contributor Author

i have another issue to report where completions for configs like this are given instead of for the struct fields in cases where the function returns a type. is this related? i can open a new issue if not

@llogick
Copy link
Contributor

llogick commented Nov 22, 2023

It's the std.heap.GeneralPurposeAllocator(.{}){.<cursor>} issue isn't it.. 😅
I keep forgetting about it so an issue as a reminder wouldn't be bad.

@xdBronch
Copy link
Contributor Author

yeah thats it lol, will open an issue

@xdBronch
Copy link
Contributor Author

#1618 i also noticed that @import("std").heap.GeneralPurposeAllocator(.{}){} doesnt give any completions so i had to split the import into a const, is that the same issue as this?

@llogick
Copy link
Contributor

llogick commented Nov 22, 2023

collectFieldAccessContainerNodes expects the first symbol to be something it can look up to determine if it's a T or instance_of_T

var symbol_iter = std.mem.tokenizeScalar(u8, field_access_slice, '.');
const first_symbol = symbol_iter.next() orelse continue;
const symbol_decl = try analyser.lookupSymbolGlobal(handle, first_symbol, loc.start) orelse continue;
const symbol_type = try symbol_decl.resolveType(analyser) orelse continue;
if (!symbol_type.type.is_type_val) { // then => instance_of_T
if (try analyser.hasSelfParam(node_type.handle, full_fn_proto)) break :blk 2;
}
break :blk 1; // is `T`, no SelfParam

A if (field_access_slice[0] == '@') break :blk 1; // assume @import("..").some.Other{.} could work.

@llogick
Copy link
Contributor

llogick commented Dec 1, 2023

The parser limitation is known and tracked in a number of other issues, the issues raised in the comments were fixed in the above linked PR.

@llogick llogick closed this as completed Dec 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants