Sane kak-lsp config/hook

I personally cannot write code without inlay diagnostics feature enabled, which is unfortunately a bit buggy currently. The bug is mostly noticeable in insert mode. So, I created a simple hook which disables inlay diagnostics when in insert mode and enables in normal mode, which is a temporally fix, while this bug isn’t fixed.

hook global WinSetOption filetype=(rust|python|nim|go|javascript|typescript|c|cpp) %{
        lsp-enable-window
	lsp-inlay-diagnostics-enable buffer
	hook buffer ModeChange pop:insert:normal %{ lsp-inlay-diagnostics-enable buffer }
	hook buffer ModeChange push:normal:insert %{ lsp-inlay-diagnostics-disable buffer }
}

The problem now, is that when user wants to disable inlay diagnostics for current buffer, it ill pop back in as soon as it goes to normal mode.

4 Likes

Good point. I still haven’t really used inlay-diagnostics (I tend to use lsp-hover to view diagnostics) but I’d like to.

@raiguard is using a similar hook

We should make this the default behavior, or at least document it.

I used to use lsp-hover, but at least with the Rust language server, the hover text is 90% documentation and 10% diagnostics. There’s apparently an option to disable diagnostics for 100% documentation, but that’s usually the opposite of what I want. Inlay diagnostics lets me see the diagnostics without the documentation, which is very convenient.

(lsp-hover-buffer would be a good choice too, but my little laptop often doesn’t have the screen real-estate for a editing buffer, a documentation browser, a terminal for running tests, and a diagnostics buffer.)

Same, I usually don’t care about hover documentation (go-to-definition is good enough) whereas hover diagnostics are nice because they don’t interrupt flow or editor state

There is an option to make hover show diagnostics only:

set-option global lsp_show_hover_format %{
	printf "Diagnostics:\n%s" "${lsp_diagnostics}"
}

this configuration is probably too obscure. Perhaps we should expose separate commands for documentation/diagnostics.

One disadvantage of hover is that I often don’t know exactly where the error is. I have to run lsp-hover at the correct position within a line to get diagnostics. I guess we can fix that, by making hover requests cover the entire line.

Today I’m still often falling back to *cargo* or *make* buffers for precise diagnostics. Yet, hover and inlay diagnostics are better for quick iteration, so we should make them work out of the box.

with latest git master of Kakoune and kak-lsp, this is now fixed properly; inlay diagnostics no longer jump around and thus also needn’t be hidden in insert mode (see Use `flag-lines -after` for inlay diagnostics by raiguard · Pull Request #714 · kak-lsp/kak-lsp · GitHub)

1 Like