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

Check diagnostics not highlighting full type issue #2060

Open
iamcdonald opened this issue Oct 25, 2024 · 3 comments
Open

Check diagnostics not highlighting full type issue #2060

iamcdonald opened this issue Oct 25, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@iamcdonald
Copy link

iamcdonald commented Oct 25, 2024

Zig Version

0.14.0-dev.2034+56996a280

ZLS Version

0.14.0-dev.179+5acc066

Client / Code Editor / Extensions

Zed 0.158.2

Steps to Reproduce and Observed Behavior

Can recreate with this repo.

  • open test.zig
  • change i32 to another wrong type i.e. i24
  • only the i of the wrong type (i32) is highlighted rather than the full type

I'm finding this behavior is the same for all diagnostic responses i.e. any issue is apportioned to only one character of the offending token.

Expected Behavior

I expected the entire i32 to be underlined but only the first character is.
My assumption would be that the end in the diagnostics message should maybe be {"line":3,"character":37} but I could be wrong.

Relevant log output

debug (message): received: {"jsonrpc":"2.0","method":"textDocument/didSave","params":{"textDocument":{"uri":"file:///Users/ooooo/Documents/code/zig-audio/zed-syntax-highlighting-test/src/test.zig"},"text":"const std = @import(\"std\");\n\ntest \"test\" {\n    const x: i16 = std.math.maxInt(i24);\n    _ = x;\n}\n"}}
debug (server): Took 0ms to process notification-textDocument/didSave on Thread 1781099
info  ( diag ): Running build-on-save: file:///Users/ooooo/Documents/code/zig-audio/zed-syntax-highlighting-test/build.zig (check)
debug (message): sent: {"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":"file:///Users/ooooo/Documents/code/zig-audio/zed-syntax-highlighting-test/src/test.zig","diagnostics":[{"range":{"start":{"line":3,"character":35},"end":{"line":3,"character":35}},"severity":1,"code":"zig_build","source":"zls","message":"type 'i16' cannot represent integer value '8388607'","relatedInformation":[]}]}}

Further Digging

From looking through the zls code the culprit appears to be here.

As mentioned in the comment it would appear that (given we're interpreting the zig build check output) a fix would be

  • read the src file
  • tokenize using std.zig.Tokenizer
  • find the token that corresponds to the line/character
  • set range to the range of the token

I'm happy to take a look at getting a PR together if this would work for folk but wanted to check before hand.

@Techatrix
Copy link
Member

I plan to do some internal changes to how ZLS aquires build-on-save diagnostics from ZLS (related: #2006, #2001). Zig generates diagnostics as std.zig.ErrorBundle which contains the necessary information to figure out the end position of the diagnostic without having to read the source file itself.

@iamcdonald
Copy link
Author

Makes sense, if there's anything I can help on with regards to #2006 , #2001 I'd be happy to help.

@Techatrix
Copy link
Member

I am going to reopen this so that it can be closed once the issue has actually been resolved.

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