-
-
Notifications
You must be signed in to change notification settings - Fork 336
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
ParseError for textDocument/codeAction
with 1-line file
#2211
Comments
I have tested this with Zig 0.14.0 and ZLS 0.14.0-dev.412+81407cd and while I did not encounter a panic, ZLS still exited with an error because of a parsing error. After tracing the received messages, the cause is the code action request which looked like this: {
"params": {
"context": { "only": ["source.organizeImports"] },
"textDocument": { "uri": "file:///home/techatrix/repos/zls/sample.zig" },
"range": {
"start": { "character": 0, "line": 0 },
"end": { "character": 0, "line": 0 }
}
},
"jsonrpc": "2.0",
"id": 5,
"method": "textDocument/codeAction"
} This is invalid according to the LSP Specification because CodeActionContext must have a The following change has fixed the issue for me: - params.context = { only = { "source.organizeImports" } }
+ params.context = { only = { "source.organizeImports" }, diagnostics = {} } |
That certainly fixed the ParseError for me.
Thank you for helping me debug this! For the future, what's the best way to enable and check debug logs for ZLS in Neovim? It didn't seem to be in settings, so I was just going to patch ZLS in my Nix config... diff --git a/build.zig b/build.zig
index 07c35fd..d70a4dc 100644
--- a/build.zig
+++ b/build.zig
@@ -37,7 +37,7 @@ pub fn build(b: *Build) !void {
const single_threaded = b.option(bool, "single-threaded", "Build a single threaded Executable");
const pie = b.option(bool, "pie", "Build a Position Independent Executable");
- const enable_tracy = b.option(bool, "enable_tracy", "Whether tracy should be enabled.") orelse false;
+ const enable_tracy = b.option(bool, "enable_tracy", "Whether tracy should be enabled.") orelse true;
const enable_tracy_allocation = b.option(bool, "enable_tracy_allocation", "Enable using TracyAllocator to monitor allocations.") orelse enable_tracy;
const enable_tracy_callstack = b.option(bool, "enable_tracy_callstack", "Enable callstack graphs.") orelse enable_tracy;
const test_filters = b.option([]const []const u8, "test-filter", "Skip tests that do not match filter") orelse &[0][]const u8{}; And then look in |
To put it briefly, ZLS should fix its own issues and the editor should fix their issues. This situation here is a big unique since the cause is not in neovim itself but the user config. Writing custom handling for code actions instead of vim.lsp.buf.code_action is a comparatively advanced use case though. Workarounds like this come into play when one side can't easily or quickly fix their issue. But in this case, only a single had to be changed.
Do you mean that you want to wait until nixpkgs has updated to Zig and ZLS 0.14.0? If so, feel free to do so and report back later.
This should be covered by the logging guide for ZLS. Be aware that the Also, enabling support for the Tracy profiler is unrelated to log messages. |
Zig Version
0.13.0
ZLS Version
0.13.0
Client / Code Editor / Extensions
neovim 10.4 using zls via nvim-lspconfig
Steps to Reproduce and Observed Behavior
In neovim 10.4, using zls via nvim-lspconfig, write a file containing only:
With the
BufWritePre
callback set to:On write, ZLS panics:
And the callback fails:
I have found that including any additional lines of code to the file (const decl or function) will not trigger this panic, so it seems to be related to the edge case of a single-line file.
Expected Behavior
No change to the file (code action should do nothing). It should have the same effect as running the code action on a two-line file like:
Relevant log output
The text was updated successfully, but these errors were encountered: