kakoune-lsp / kakoune-lsp

Kakoune Language Server Protocol Client

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Snippets not prompting for input

UltraBlackLinux opened this issue · comments

Hey there,
I recently found this project called lua-language-server. It works pretty well, though I'm experiencing an issue with snippets: Where they should prompt the user to enter some e.g. variable names, they instead don't and I get the following output:

in ${1:pairs(${2:t})} do
	$0
end

it should have requested some input here, but it did not.
Is that a problem of the language server itself? I doubt it, but I can't be sure.
Thanks!

when I type in<c-n>foo I get

in foo)} do
	 
end

so it replaces some of the snippet placeholder but not all. If you see something different, you might have outdated kak/kak-lsp or a broken config.

Still, there is something to fix here.
completion.rs uses a regex to parse the placeholders. Here the placeholders are nested so a single regex does not cut it.
We should probably implement a proper parser.
I think the behavior would be:

  • the first tab moves the cursor to 1
    1. if the user starts typing, replace the entire thing
    2. else if the user presses tab again, replace it with pairs() where the cursors is inside the parens
  • the next tab moves the cursor to ($0)

This workaround implements 1. More work is necessary to implement 2 as well, both on the Rust side and in lsp.kak

diff --git a/rc/lsp.kak b/rc/lsp.kak
index d19bf14..68acb4b 100644
--- a/rc/lsp.kak
+++ b/rc/lsp.kak
@@ -2265,7 +2265,7 @@ define-command lsp-snippets-insert -hidden -params 1 %[
             # select things that look like placeholders
             # this regex is not as bad as it looks
             evaluate-commands -draft %[
-                execute-keys s((?<lt>!\\)(\\\\)*|\A)\K(\$(\d+|\{(\d+(:(\\\}|[^}])*)?)\}))<ret>
+                execute-keys s((?<lt>!\\)(\\\\)*|\A)\K(\$(\d+|\{(\d+(:(\\\}|\S)*)?)\}))<ret>
                 # tests
                 # $1                - ok
                 # ${2}              - ok

My kak-lsp is up-to-date as I got it from arch's community repos. My kak-lsp config itself is very unlikely to cause issues.

Since you are mentioning tab, there might be something with that. I don't really know what to look for, so maybe you can find something in my config? https://chonkyrabbit.eu/git/dotfiles.git/tree/dotconfig/kak/kakrc

From testing I just noticed that the completion menu does not close when I press tab, and I have to instead close it manually. Maybe that is the issue?

<tab> is the recommended mapping to cycle through snippet placeholders, see the readme

The completion menu is closed by typing any key. I'm not sure why in<c-n>foo shows a different result for you, maybe check if lsp-snippets-insert is actually run

check if lsp-snippets-insert is actually run

how could I do that? I'm not super familiar with the inner workings of kakoune

Also do you know if there is a thing that I can run which will close the completion popup? I could not find anything on that.