zls icon indicating copy to clipboard operation
zls copied to clipboard

ZLS does not show function signature

Open noiryuh opened this issue 3 years ago • 5 comments

Zig Version

0.10.0-dev.3685+dae7aeb33

Zig Language Server Version

8cf96fe27cfd235acdf301728f9cce7a7b265ca3

Steps to Reproduce

Use Helix (v22.05), build_runner.zig in the same directory as zls and zls is in $PATH.

ZLS config file:

{
    "zig_exe_path": "/home/noiryuh/.local/bin/zig",
    "enable_snippets": true,
    "enable_unused_variable_warnings": true,
    "enable_import_embedfile_argument_completions": true,
    "warn_style": false,
    "enable_semantic_tokens": true,
    "enable_inlay_hints": true,
    "operator_completions": true,
    "include_at_in_builtins": false,
    "max_detail_length": 1048576
}

Expected Behavior

ZLS should show function signatures for stdlib functions (like for builtin functions). 20220826_14h16m57s_grim

Actual Behavior

ZLS doesn't show function signatures for stdlib. 20220826_14h09m43s_grim

noiryuh avatar Aug 26 '22 07:08 noiryuh

likely client side/plugin

vscode for comparison: zls_completion_screenshot_vscode zls_completion_screenshot_vscode2

llogick avatar Aug 26 '22 16:08 llogick

it's default config in Helix

theme = "tokyonight"

[editor]
line-number = "relative"

[editor.whitespace]
render = "all"

[editor.cursor-shape]
insert = "bar"
normal = "block"

it used to work normally before, the only thing i update was ZLS.

noiryuh avatar Aug 27 '22 07:08 noiryuh

Happening to me on helix too, I just checked and it's happening with the kakoune editor too

DivergentClouds avatar Aug 27 '22 20:08 DivergentClouds

I can confirm that this issue does not happen with the 0.9.0 release of ZLS, so it is definitely on the ZLS end

DivergentClouds avatar Aug 27 '22 20:08 DivergentClouds

edit: There's no official response yet, but one could probably restore the previous functionality by commenting out https://github.com/zigtools/zls/blob/2ac8ab6ce92869c71aaf774417e02ed5bc753c52/src/Server.zig#L1553 As the comments state, labelDetails can be quite lengthy, however, function signatures should probably be presented as they are.

I'd be interested in implementing a "verbose_label_details" config option (for the other cases).

Regards

original post(do not use, not a solution): ok,

I were able to achieve/approximate the functionality with the following changes:

diff --git a/src/Server.zig b/src/Server.zig
index 59eec00..94785a2 100644
--- a/src/Server.zig
+++ b/src/Server.zig
@@ -531,11 +531,15 @@ fn nodeToCompletion(
 
                 const is_type_function = analysis.isTypeFunction(handle.tree, func);
 
+                const fn_sig = analysis.getFunctionSignature(handle.tree, func);
+                const fn_name = handle.tree.tokenSlice(name_token);
+                const fn_name_pos = std.mem.indexOf(u8, fn_sig, fn_name) orelse 0;
+
                 try list.append(allocator, .{
-                    .label = handle.tree.tokenSlice(name_token),
+                    .label = fn_sig[fn_name_pos..],
                     .kind = if (is_type_function) .Struct else .Function,
                     .documentation = doc,
-                    .detail = analysis.getFunctionSignature(handle.tree, func),
+                    .detail = fn_sig,
                     .insertText = insert_text,
                     .insertTextFormat = if (use_snippets) .Snippet else .PlainText,
                 });

or artifacts

but this causes a lot more items to be included in the completion list ?..

llogick avatar Aug 28 '22 01:08 llogick

I sent a PR that should fix this, please test it and let me know if that works in both Helix/Kakoune

ryuukk avatar Oct 13 '22 00:10 ryuukk