Kak-lsp completion key

Hi! I’ve been enjoying Kakoune for the past few days and plan on using it for quite a while longer, but there is one small thing that I cannot seem to find the solution to. I’m using kak-lsp, and some completions expand out after hovering over them when I don’t want them to. For example, take this file:

class Foo:
    def __i|

where | is the cursor in insert mode. When hovering over the __init__ completion entry, it updates to def __init__ as expected, but any further keypresses will expand it out into the full

    def __init__(self) -> None:
        pass

or even

    def __init__(self, *args: object) -> None:
        super().__init__(*args)

in one of my recent projects.

I am personally not a fan of hidden behavior, and I have always set hovering over an entry to insert exactly what it shows with an explicit key (<C-f>) to expand out the full thing in other editors, but I cannot figure out how to achieve this in Kakoune.

I already have set-option global lsp_snippet_support false which fixed a few issues in Zig, but it doesn’t seem to help in this case. Is there anything else that I could try? I understand that this request is hyperspecific, so if any further clarification or information is needed, I would be happy to provide.

(As an extra request, is it possible to show information about the completion entry I am hovering on? I have found that LSP window shopping is a really good way to learn a new language/library, and miss it a lot.)

Thank you so much to anyone willing to help!

I can’t reproduce; which server are you using?
The default (pylsp) does seem to provide similar snippets but only expands to def __init__()in this case, placing the cursor between the parentheses. That can be annoying, especially because for some reason there is no final placeholder after the closing parenthesis, so one can’t use <tab> (assuming the kakoune-lsp recommended mappings) to jump to after the snippet.

But it does sound like the same problem, so setting lsp_snippet_support and restarting the LSP server should fix it, unless the server is buggy.

I don’t know if it’s easy to change kakoune-lsp to expand snippets eagerly, because the Kakoune completion framework imposes some assumptions.

is it possible to show information about the completion entry I am hovering on

yes, that’s the default behavior. For example with pylsp:

FWIW the completion-candidate-specific information is displayed by what’s documented as <select cmd> in doc options; exec /^completions<ret>vv

I am using pyright with the config below. Attached is also a video of the exact behavior.

eval %sh{kak-lsp}

set-option global lsp_snippet_support false
remove-hooks global lsp-filetype-.*

lsp-enable
lsp-inlay-diagnostics-enable global
lsp-auto-hover-enable

set-option global modelinefmt "%opt{lsp_modeline} %opt{modelinefmt}"

# various maps

hook global -group lsp-filetype-python BufSetOption filetype=python %{
    set-option buffer lsp_servers %{
        [pyright-langserver]
        args = ["--stdio"]
        root_globs = ["pyproject.toml", "setup.py", "poetry.lock", "pyrightconfig.json", ".git"]

        [ruff]
        args = ["server", "--quiet"]
        root_globs = ["pyproject.toml", "setup.py", "poetry.lock", ".git"]
        settings_section = "_"
        [ruff.settings._.globalSettings]
        organizeImports = true
        fixAll = true
    }
}

# various lsps for other languages

asciicast

is it possible to show information about the completion entry I am hovering on

pushed a fix: Fix completion item menu text not showing · kakoune-lsp/kakoune-lsp@59d3108 · GitHub


Maybe the above fix is already enough for both issues. If not, read on:

If I do set-option global lsp-debug true,
I see that pyright-langserver sends

{
  "jsonrpc": "2.0",
  "id": 108,
  "result": {
    "data": {
      "funcParensDisabled": true,
      "position": {
        "character": 11,
        "line": 59
      },
      "symbolLabel": "__init__",
      "uri": "file:///home/johannes/git/kakoune-lsp/t/test.py"
    },
    "kind": 2,
    "label": "__init__",
    "sortText": "13.9999.__init__",
    "textEdit": {
      "newText": "__init__(self) -> None:\n    pass",
      "range": {
        "end": {
          "character": 11,
          "line": 59
        },
        "start": {
          "character": 8,
          "line": 59
        }
      }
    },
    "documentation": {
      "kind": "markdown",
      "value": "```python\ndef __init__(self: Self@object) -> None\n```"
    }
  }
}

So there are no snippets but the completion label is __init__ and the textEdit inserts the whole function stub.
So kak-lsp is doing exactly as told.

I don’t think there’s a capability in LSP to indicated whether text edits are desired/supported.
We could add a knob to kak-lsp to make it ignore the textEdit field.
However adding this workaround should be the last resort, because it means that every editor still has this problem.
Maybe better file an issue with your language server asking for different kinds of completions.

As for the precedent for such a knob, I think the reason why lsp_snippet_support exists is because snippets used to be kind of broken.
So I’m sure a lot of people still have lsp_snippet_support set to false even though they would be okay with using snippets.

Maybe we should rename lsp_snippet_support to lsp_completion_enable_snippets (causing people who try to set lsp_snippet_support to get an error) and then maybe add lsp_completion_enable_text_edit.

After looking at both Helix and VSCode’s implementations, it appears that the kak-lsp behavior is the norm and I had just gotten too used to cmp.nvim’s behavior. I’ll try to get used to kak-lsp and see if it’s really that big of a deal.
One thing that I really appreciate from both VSCode and Helix are that they show a preview of what the resulting code will be, although I’m guessing this can be resolved with the completion menu fix. I tried building it and updating my config to utilize the new binary, but I still have the same issue. Where would I be able to find applicable logs for debugging this?
Thank you so much for the support, and for making such a wonderful piece of software in the first place :slight_smile:

although I’m guessing this can be resolved with the completion
menu fix.

yeah

I tried building it and updating my config to utilize the new
binary, but I still have the same issue.

Make sure you’re actually running the new binary

ps -eo exe,args | grep kak-lsp

Where would I be able to
find applicable logs for debugging this?

In the *debug* buffer, see GitHub - kakoune-lsp/kakoune-lsp: Kakoune Language Server Protocol Client · GitHub

After <c-n>, the response to completionItem/resolve should contain the documentation field.

Oops- it appears that just having eval %sh{~/git/kakoune-lsp/target/release/kak-lsp} wasn’t enough and I had to uninstall my system version of kak-lsp. It is now working as expected! :grinning_face_with_smiling_eyes:

Yeah you need to either make sure it’s first in $PATH (such as in ~/.cargo/bin) or set lsp_cmd though that’d be a workaround because it doesn’t help other editors