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

no switch case completion on function inside container #1535

Open
Techatrix opened this issue Oct 17, 2023 · 4 comments · May be fixed by #1536
Open

no switch case completion on function inside container #1535

Techatrix opened this issue Oct 17, 2023 · 4 comments · May be fixed by #1536
Labels
bug Something isn't working

Comments

@Techatrix
Copy link
Member

Zig Version

0.12.0-dev.978+78855bd21

Zig Language Server Version

1a282b3

Steps to Reproduce

const E = enum {
    foo,
    bar,
    baz,
    fn foo(e: E) void {
        switch (e) {.<ask for completions here>}
    }
};

Expected Behavior

List all fields of E i.e. foo, bar and baz.

Actual Behavior

no completions.

Hovering of e inside the switch expression yields no result which is the underlying problem.
If you move foo outside of the enum, then it works.

This looks like one of those situations where the parser goes crazy.

@llogick
Copy link
Contributor

llogick commented Oct 17, 2023

I keep repeating it, but before anyone dives into the completions logic — parser limitation.
The workarounds (I know, not ideal):

  • structs => S{1.};
  • switch => switch (e) {.}};

@Techatrix
Copy link
Member Author

Instead of expecting users to know about a workaround, this shouldn't be necessary. This issue with the parser should be investigated and resolved upstream.

@llogick
Copy link
Contributor

llogick commented Oct 17, 2023

I don't mean to nag, simply posted it as a heads-up to anyone that might look into it, and the workarounds as a proof/way to verify that the issue stems from syntax errors.

The reason I refer to it as limitation is that it's only an issue for third parties

I've experimented with passing true(recoverable) here
https://github.com/ziglang/zig/blob/eb5276c94eaab238551fdae9a2e77b0133e31cfb/lib/std/zig/Parse.zig#L876
and from what I can tell it solves most of these, the exception being completions within a struct/switch if the type node is defined outside and after the current node.

I've also explored making additional changes, but not certain the benefits warrant supporting custom node tags.

@Techatrix
Copy link
Member Author

This appears to be fixed by #1536.

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

Successfully merging a pull request may close this issue.

2 participants