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

Code Action: Warning for camel_case does not show itself as Code Action #2153

Open
eddiebergman opened this issue Jan 27, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@eddiebergman
Copy link

eddiebergman commented Jan 27, 2025

Zig Version

0.14.0-dev.2851+b074fb7dd

ZLS Version

6a16b27

Client / Code Editor / Extensions

Zed (linked to zls 6a16b27), Neovim (linked to zvm -i master --zls)
I should also mention I use the "check" step in my build.zig to enable build_on_save

Steps to Reproduce and Observed Behavior

Here's the script with a non camel case function

const std = @import("std");

fn not_camel_case() u32 {
    return 5;
}

pub fn main() !void {
    const x = not_camel_case();
    _ = x; // autofix
}

As shown in the screenshot, I don't get a suggested code action to fix it.

Image

I wanted to contribute something to zls and actually ended up finding this as a bug.
As a result, I am running off the latest commit on master.


Relevant debugging code:

Notably, the error_bundle.errorMessageCount() is returning 0, meaning it never gets into the point where it can suggest code actions.

pub const Builder = struct {   

    pub fn generateCodeAction(...) error{OutOfMemory}!void {
        //...

        // Below line prints 0
        log.debug("{d}\n", .{error_bundle.errorMessageCount()});
        if (error_bundle.errorMessageCount() == 0) return; // `getMessages` can't be called on an empty ErrorBundle

        // Never Reached!
        // Code actions dispatched down here
        for (error_bundle.getMessages()) |msg_index| {
            log.debug("{s}\n", .{"in here"});
            

Two questions

  1. Before attempting to fix this, is this a configuration issue?
  2. Is there a better way to debug/work on zls that you could recommend, I never managed to find a CONTRIBUTING.md or anything along those lines. I've managed to insert some debugging printing into zls as well as a tail -F ~/.cache/zls/zls.log.

Here is my settings in case it matters:

{
        "$schema": "https://raw.githubusercontent.com/zigtools/zls/master/schema.json",
        "enable_autofix": true,
        "zig_exe_path": "/home/anon/.zvm/bin/zig",
        "enable_snippets": true,
        "enable_argument_placeholders": false,
        "completion_label_details": true,
        "enable_build_on_save": true,
        "build_on_save_args": [],
        "semantic_tokens": "full",
        "inlay_hints_show_variable_type_hints": true,
        "inlay_hints_show_struct_literal_field_type": true,
        "inlay_hints_show_parameter_name": true,
        "inlay_hints_show_builtin": true,
        "inlay_hints_exclude_single_argument": true,
        "inlay_hints_hide_redundant_param_names": false,
        "inlay_hints_hide_redundant_param_names_last_token": false,
        "warn_style": true,
        "highlight_global_var_declarations": true,
        "skip_std_references": true,
        "prefer_ast_check_as_child_process": true
}

Expected Behavior

The expected behavior is to display code actions when requested.

Relevant log output

info  ( main ): Starting ZLS      0.14.0-dev.365+6a16b27 @ '/home/skantify/code/zls/zig-out/bin/zls'
info  ( main ): Log File:         /home/skantify/.cache/zls/zls.log (debug)
info  (server): Client Info:      Zed-0.170.2
info  (server): Autofix Mode:     source.fixall
debug (server): Offset Encoding:  utf-16
info  (server): added Workspace Folder: file:///home/skantify/code/zldb
info  (server): Loaded config:      /home/skantify/.config/zls.json
info  (server): Set config option 'enable_argument_placeholders' to false
info  (server): Set config option 'enable_build_on_save' to true
info  (server): Set config option 'warn_style' to true
info  (server): Set config option 'highlight_global_var_declarations' to true
info  (server): Set config option 'skip_std_references' to true
info  (server): Set config option 'builtin_path' to "/home/skantify/.cache/zls/builtin.zig"
info  (server): Set config option 'zig_lib_path' to "/home/skantify/.zvm/master/lib"
info  (server): Set config option 'zig_exe_path' to "/home/skantify/.zvm/bin/zig"
info  (server): Set config option 'build_runner_path' to "/home/skantify/.cache/zls/build_runner/7180d84475778f22727a41e291f1ec7f/build_runner.zig"
info  (server): Set config option 'global_cache_path' to "/home/skantify/.cache/zls"
debug (server): Took 36ms to process request-0-initialize on Thread 34549
debug (server): Dynamically registering method 'workspace/didChangeConfiguration'
debug (server): Took 1ms to process notification-initialized on Thread 34549
debug (server): Took 1ms to process notification-workspace/didChangeConfiguration on Thread 34549
info  (store ): Loaded build file 'file:///home/skantify/code/zldb/build.zig'
debug (store ): Opened document 'file:///home/skantify/code/zldb/src/main.zig'
debug (server): Took 2ms to process notification-textDocument/didOpen on Thread 34549
debug (server): Took 0ms to process response-"register-workspace/didChangeConfiguration" on Thread 34549
info  (server): trying to start Build-On-Save for 'file:///home/skantify/code/zldb'
debug (server): Took 5ms to process response-"i_haz_configuration" on Thread 34549
debug (server): Took 0ms to process response-"progress" on Thread 34549
debug (server): Took 5ms to process response-"i_haz_configuration" on Thread 34549
debug (server): Took 0ms to process response-"inlay_hints_refresh" on Thread 34549
debug (server): Took 6ms to process request-426-textDocument/inlayHint on Thread 31234
debug (server): Took 12ms to process request-428-textDocument/inlayHint on Thread 31233
debug (inlay_hint): cannot deduce fn expression with tag 'zig.Ast.Node.Tag.enum_literal'
debug (inlay_hint): cannot deduce fn expression with tag 'zig.Ast.Node.Tag.enum_literal'
debug (inlay_hint): cannot deduce fn expression with tag 'zig.Ast.Node.Tag.enum_literal'
debug (inlay_hint): cannot deduce fn expression with tag 'zig.Ast.Node.Tag.enum_literal'
debug (inlay_hint): cannot deduce fn expression with tag 'zig.Ast.Node.Tag.enum_literal'
debug (server): Took 63ms to process request-427-textDocument/inlayHint on Thread 31231
debug (server): Took 0ms to process notification-workspace/didChangeConfiguration on Thread 31230
debug (server): Took 0ms to process notification-workspace/didChangeConfiguration on Thread 31230
debug (server): Took 0ms to process notification-workspace/didChangeConfiguration on Thread 34549
debug (server): Took 8ms to process response-"i_haz_configuration" on Thread 31230
debug (server): Took 0ms to process notification-workspace/didChangeConfiguration on Thread 31230
debug (server): Took 7ms to process response-"i_haz_configuration" on Thread 34549
debug (server): Took 10ms to process response-"i_haz_configuration" on Thread 31230
debug (server): Took 7ms to process response-"i_haz_configuration" on Thread 31230
debug (server): Took 0ms to process request-2-textDocument/documentHighlight on Thread 34552
debug (server): 0

debug (server): Took 18ms to process request-3-textDocument/codeAction on Thread 34553
debug (server): Took 0ms to process request-4-textDocument/documentHighlight on Thread 34551
debug (server): Took 1ms to process request-5-textDocument/documentHighlight on Thread 34550
debug (server): Took 1ms to process request-6-textDocument/documentHighlight on Thread 34552
debug (server): Took 2ms to process request-7-textDocument/documentHighlight on Thread 34553
debug (server): 0

debug (server): Took 16ms to process request-8-textDocument/codeAction on Thread 34551
@eddiebergman eddiebergman added the bug Something isn't working label Jan 27, 2025
@eddiebergman
Copy link
Author

Alright, I did some more digging to see what's going on and I see the /codeAction path depends on zig ast-check, which shows no errors (yet still always gives the import sorting action), while /hover uses the Analyzer for diagnostics which are not from zig ast-check.

I'm not sure that is intentional or not, as doing a full Analyzed check is probably a bit more expensive to do in conjunction with the Analyzer check.

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

1 participant