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

function snippet seems broken by PR #3005 in non released latest master (after v3.13.5) #3021

Open
tomlau10 opened this issue Jan 3, 2025 · 3 comments · May be fixed by #3022
Open

function snippet seems broken by PR #3005 in non released latest master (after v3.13.5) #3021

tomlau10 opened this issue Jan 3, 2025 · 3 comments · May be fixed by #3022

Comments

@tomlau10
Copy link
Contributor

tomlau10 commented Jan 3, 2025

How are you using the lua-language-server?

Visual Studio Code Extension (sumneko.lua)

Which OS are you using?

MacOS

What is the issue affecting?

Completion

Expected Behaviour

local t = {}

table.sort(t, |) -- trigger completion at `|` will show `fun(a: <T>, b: <T>):boolean`
-- and choosing it should complete as

table.sort(t, function (a, b)
    
end)

Actual Behaviour

but now it becomes something like this

local t = {}

table.sort(t, function (${1:a}, ${2:b})
    $0
end)

Reproduction steps

local t = {}

table.sort(t, |) -- trigger completion at `|` and choose the first provided function snippet

Additional Notes

I just checked out latest master (cb964c6 as of the time being) and found this issue.
After doing git bisect, it points to the following commit which is #3005 by @andrewbraxton

a3dd298664a55be46a2603642559eb91656ba18e is the first bad commit
commit a3dd298664a55be46a2603642559eb91656ba18e
Author: Andrew Braxton <[email protected]>
Date:   Tue Dec 24 22:21:01 2024 -0500

    Send the correct `insertTextFormat`
    
    Per LSP specification, `insertTextFormat` should be `2` for snippets and
    `1` for plain text. Using `2` unconditionally can make clients behave in
    unexpected ways.
    
    The code calling into `provider.lua` sets `insertTextFormat` to 2 for
    all snippets and leaves it nil for other types, so we can reuse that
    information in `provider.lua` to make sure we send the correct value.

 script/provider/provider.lua | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Maybe the change works for neovim, but it's definitely broken for doc.type.function snippet in vscode 😕
(for others snippet like repeat .. until it works normally)

Log File

No response

@tomlau10
Copy link
Contributor Author

tomlau10 commented Jan 3, 2025

After some investigation, seems now a completion entry needs to specify insertTextFormat = 2 itself if it is snippet rather than plaintext.
Changing the following line resolves this issue 🤔

enums[#enums+1] = {
label = vm.getInfer(src):view(state.uri),
description = description,
kind = define.CompletionItemKind.Function,
insertText = insertText,
}

  • add insertTextFormat = 2 in this object

@andrewbraxton
Copy link
Contributor

Hmm, my PR assumed that all snippets properly set insertTextFormat to 2 because the ones I happened to test did but that may not have been the case for all of them.

@tomlau10
Copy link
Contributor Author

tomlau10 commented Jan 3, 2025

Would you please open another PR to fix this? 😂 @andrewbraxton

andrewbraxton added a commit to andrewbraxton/lua-language-server that referenced this issue Jan 3, 2025
The PR LuaLS#3005 assumed that all snippets were setting `insertTextFormat`
to 2 and leaving plaintext completions nil, but that was not the case.
Function completions need to be marked as snippets too.

fixes LuaLS#3021
@andrewbraxton andrewbraxton linked a pull request Jan 3, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants