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

Error when using for loop with index syntax #1400

Closed
that-ambuj opened this issue Aug 12, 2023 · 12 comments
Closed

Error when using for loop with index syntax #1400

that-ambuj opened this issue Aug 12, 2023 · 12 comments
Labels
bug Something isn't working

Comments

@that-ambuj
Copy link

that-ambuj commented Aug 12, 2023

Zig Version

0.11.0

Zig Language Server Version

0.10.0

Steps to Reproduce

Using For Loop with index syntax(tuple loop?)

const data = [_]i32{ 1, 3, 5, 6, 9, 10 };
for (data, 0..) |value, idx| { // -> Error here: Expected ')', found ','
    // do something here...
}

Expected Behavior

No error emitted by zls

Actual Behavior

Errors when using for loop syntax with two ranges/iterators.

@that-ambuj that-ambuj added the bug Something isn't working label Aug 12, 2023
@llogick
Copy link
Contributor

llogick commented Aug 12, 2023

Could you post the first ~15-20 lines of the language server log? Should contain stuff like zls version, zig version, editor.

@that-ambuj
Copy link
Author

that-ambuj commented Aug 13, 2023

[START][2023-08-13 12:02:16] LSP logging initiated
[ERROR][2023-08-13 12:02:16] .../vim/lsp/rpc.lua:734	"rpc"	"/home/ambuj/.local/share/nvim/mason/bin/zls"	"stderr"	"info : (config): Using zig executable /usr/bin/zig\n"
[ERROR][2023-08-13 12:02:16] .../vim/lsp/rpc.lua:734	"rpc"	"/home/ambuj/.local/share/nvim/mason/bin/zls"	"stderr"	"info : (config): Using zig lib path '/usr/lib/zig'\n"
[ERROR][2023-08-13 12:02:16] .../vim/lsp/rpc.lua:734	"rpc"	"/home/ambuj/.local/share/nvim/mason/bin/zls"	"stderr"	"info : (server): zls initializing\ninfo : (server): Server.ClientCapabilities{ .supports_snippets = true, .supports_semantic_tokens = true, .supports_inlay_hints = false, .hover_supports_md = true, .completion_doc_supports_md = true, .label_details_support = true, .supports_configuration = true }\ninfo : (server): Using offset encoding: utf16\n"
[ERROR][2023-08-13 12:02:16] .../vim/lsp/rpc.lua:734	"rpc"	"/home/ambuj/.local/share/nvim/mason/bin/zls"	"stderr"	"error: (store ): Failed to execute build runner to collect build configuration, command:\n/usr/bin/zig run /home/ambuj/.cache/zls/build_runner.zig --cache-dir /home/ambuj/.cache/zls --pkg-begin @build@ /home/ambuj/personal-projects/zig-learn/build.zig --pkg-end -- /usr/bin/zig /home/ambuj/personal-projects/zig-learn zig-cache ZLS_DONT_CARE\nError: error: unrecognized parameter: '--pkg-begin'\n\nerror: (store ): Failed to load build configuration for file:///home/ambuj/personal-projects/zig-learn/build.zig (error: error.RunFailed)\n"
[ERROR][2023-08-13 12:02:16] .../vim/lsp/rpc.lua:734	"rpc"	"/home/ambuj/.local/share/nvim/mason/bin/zls"	"stderr"	"info : (server): Setting configuration...\ninfo : (config): Using zig executable /usr/bin/zig\n"
[START][2023-08-13 12:05:56] LSP logging initiated
[ERROR][2023-08-13 12:05:56] .../vim/lsp/rpc.lua:734	"rpc"	"/home/ambuj/.local/share/nvim/mason/bin/zls"	"stderr"	"info : (config): Using zig executable /usr/bin/zig\ninfo : (config): Using zig lib path '/usr/lib/zig'\n"
[ERROR][2023-08-13 12:05:56] .../vim/lsp/rpc.lua:734	"rpc"	"/home/ambuj/.local/share/nvim/mason/bin/zls"	"stderr"	"info : (server): zls initializing\ninfo : (server): Server.ClientCapabilities{ .supports_snippets = true, .supports_semantic_tokens = true, .supports_inlay_hints = false, .hover_supports_md = true, .completion_doc_supports_md = true, .label_details_support = true, .supports_configuration = true }\ninfo : (server): Using offset encoding: utf16\n"
[ERROR][2023-08-13 12:05:56] .../vim/lsp/rpc.lua:734	"rpc"	"/home/ambuj/.local/share/nvim/mason/bin/zls"	"stderr"	"error: (store ): Failed to execute build runner to collect build configuration, command:\n/usr/bin/zig run /home/ambuj/.cache/zls/build_runner.zig --cache-dir /home/ambuj/.cache/zls --pkg-begin @build@ /home/ambuj/personal-projects/zig-learn/build.zig --pkg-end -- /usr/bin/zig /home/ambuj/personal-projects/zig-learn zig-cache ZLS_DONT_CARE\nError: error: unrecognized parameter: '--pkg-begin'\n\nerror: (store ): Failed to load build configuration for file:///home/ambuj/personal-projects/zig-learn/build.zig (error: error.RunFailed)\n"
[ERROR][2023-08-13 12:05:56] .../vim/lsp/rpc.lua:734	"rpc"	"/home/ambuj/.local/share/nvim/mason/bin/zls"	"stderr"	"info : (server): Setting configuration...\ninfo : (config): Using zig executable /usr/bin/zig\n"
[ERROR][2023-08-13 12:06:05] .../vim/lsp/rpc.lua:734	"rpc"	"/home/ambuj/.local/share/nvim/mason/bin/zls"	"stderr"	"<stdin>:507:7: error: expected pointer dereference, optional unwrap, or field access, found '}'\n"

I Hope this is helpful. I'm using neovim with Mason.

AFAIK Mason uses vscode-zig as lsp client unlike zig.vim and Mason seems to use it's own version of zls binary 0.10.0.

@llogick
Copy link
Contributor

llogick commented Aug 13, 2023

AFAIK Mason uses vscode-zig as lsp client unlike zig.vim and Mason seems to use it's own version of zls binary 0.10.0.

Correct, part of the reason to see the logs.

Follow-up question — Does it happen after you type up the for loop or after you save the file?

@that-ambuj
Copy link
Author

It is persistent after saving the file.

If I'm not wrong about Mason, then the error is occurs only on zls 0.10.0 but not on latest commit(0.12.0-dev) when using zig.vim(which uses my systemwide zls binary in my PATH).

@llogick
Copy link
Contributor

llogick commented Aug 13, 2023

It is persistent after saving the file.

Yes, but do you get the error after typing it or after saving the file?

Reason is: some plugins, including zig.vim, do a build_os_save regardless if using a language server or not,
and they use whichever zig they find in PATH.
Do you have any previous zig installations? Check output of zig env in the terminal you use to launch Neovim.

@that-ambuj
Copy link
Author

that-ambuj commented Aug 13, 2023

Just checked, the error happens on typing and before saving the file.

Plus, it compiles without warnings or errors with zig build main.zig.

zig env output:

> zig env
{
 "zig_exe": "/usr/bin/zig",
 "lib_dir": "/usr/lib/zig",
 "std_dir": "/usr/lib/zig/std",
 "global_cache_dir": "/home/ambuj/.cache/zig",
 "version": "0.11.0",
 "target": "x86_64-linux.6.1.39...6.1.39-gnu.2.19"
}

@Techatrix
Copy link
Member

Am I missing something or isn't this issue very simple to explain?

  • Your are using ZLS 0.10.0.
  • ZLS 0.10.0 has been compiled with zig 0.10.0.
  • Therefore, ZLS 0.10.0 is using the standard library zig parser at the time of the zig 0.10.0 release.
  • That parser only accepts syntactically valid zig 0.10.0 code.
  • But your code is only syntactically valid zig 0.11.0 code.

In Short: ZLS 0.10.0 is not compatible with a zig 0.11.0 codebase.
Solution: use a newer ZLS build that is compatible with zig 0.11.0
discussion about ZLS backwards compatibility: #1020

@Techatrix Techatrix closed this as not planned Won't fix, can't repro, duplicate, stale Aug 13, 2023
@that-ambuj
Copy link
Author

I understand that the problem is version mismatch.

But Mason depends on github release binaries for LSP binary and we can't use the latest github source for everyone.

What I am wishing for is to get 0.11.0 release of zls. So, I can bump the version in mason for everyone and it has been almost 9 months since the last release.

@llogick
Copy link
Contributor

llogick commented Aug 13, 2023

Am I missing something or isn't this issue very simple to explain?

In the original version of the issue, the reported Zig Language Server Version was 91974a3. All good now.

@that-ambuj
Copy link
Author

May I know when the next release of zls will happen?

@SuperAuguste
Copy link
Member

It's just been released :)

@that-ambuj
Copy link
Author

Thanks a lot @SuperAuguste, You're a saviour! I was waiting for this moment. Cheers!

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

4 participants