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 broken due to missing semicolon (or any recoverable error) #1112

Open
Jarred-Sumner opened this issue Apr 4, 2023 · 3 comments · May be fixed by #1536
Open

Completions broken due to missing semicolon (or any recoverable error) #1112

Jarred-Sumner opened this issue Apr 4, 2023 · 3 comments · May be fixed by #1536
Labels
bug Something isn't working

Comments

@Jarred-Sumner
Copy link
Contributor

Jarred-Sumner commented Apr 4, 2023

Zig Version

0.11.0-dev.2317+46b2f1f70

Zig Language Server Version

HEAD

Steps to Reproduce

This started happening today? Not sure if code change causes it or if zls change

  1. Put cursor on line 546: https://github.com/oven-sh/bun/blob/jarred/new-bundler/src/bundler/bundle_v2.zig#L532-L555
  2. No completions for any non-top level scope types until the syntax is 100% valid.

Screen Recording 2023-04-04 at 3 08 43 AM

Expected Behavior

Completions should appear

Actual Behavior

Completions do not appear

I suspect it's something to do with #1071

@Jarred-Sumner Jarred-Sumner added the bug Something isn't working label Apr 4, 2023
@Jarred-Sumner
Copy link
Contributor Author

More minimal reproduction:
hmmmm

const std = @import("std");

fn HelloFn() type {
    return struct {};
}

pub const Hello = struct {
    pub fn hm(arg: *HelloFn(u64, void)) void {
        _ = arg;
        switch ((union {
            empty: u32,
            success: *anyopaque,
        }){ .success = undefined }) {
            .empty => |source_index| {
                _ = source_index;
            },
            .success => |*arg2| {
                // reference "arg" here
                {
                    arg2;
                }

            },
        }
    }
};

@Techatrix
Copy link
Member

This is very similar to an Issue we had in ZLS Discord here.

This code snippet should also showcase the given problem:

pub var state: S = undefined;
pub const S = struct { foo: u32 };

pub fn main() void {
    state.
    {
        _ = state.foo;
    }
    state.foo;
}

I've initial concluded by stating that this Issue is hard to fix in ZLS because of how the zig parser got confused by the token sequence state.{. After giving this Issue another look, I think that fixing this by improving the error recovery of the Zig parser may also be a viable route.

Even if this can be fixed without modifying the parser, the error messages look really awful
zig-parser-go-crazy

@Jarred-Sumner
Copy link
Contributor Author

Almost all the bugs I run into this have to do with the . character

What if when there's a syntax error and the last character typed was ., you retry parsing with a semicolon where the . character was placed? Doing that manually fixes the issue. Obviously that's a terrible hack, but it's an improvement over the current state.

image

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