I have no idea if kak-lsp is running

I’ve setup kak-lsp like so

plug "ul/kak-lsp" do %{
    cargo build --release --locked
    cargo install --force --path . --locked
    cargo clean
} config %{
	
    set-option global lsp_cmd "kak-lsp --kakoune -vvv -c $HOME/.config/kak-lsp/kak-lsp.toml -s %val{session} --log $HOME/.config/kak-lsp/kak-lsp.log"

    define-command lsp-restart %{ lsp-stop; lsp-start }

    set-option global lsp_completion_trigger "execute-keys 'h<a-h><a-k>\S[^\s,=;*(){}\[\]]\z<ret>'"
    set-option global lsp_diagnostic_line_error_sign "!"
    set-option global lsp_diagnostic_line_warning_sign "?"
    hook global WinSetOption filetype=(c|cpp|objc|d|rust|haskell|nim|elixir|latex|javascript) %{

        lsp-start 
        # ^ I'm apparently need to use this and not an `eval %sh{}`, because it will gripe in *debug*
        #    that  "command lsp-start already exists" or something like that.
    	lsp-enable-window
    	echo -debug "Enabling LSP for filtetype %opt{filetype}"
    	
    	lsp-auto-hover-enable
    	lsp-auto-hover-insert-mode-disable
    	set-option global lsp_auto_highlight_references true
    	set-option global lsp_hover_anchor true
    	
    	# Semantic highlighting
    	hook window -group semantic-tokens BufReload .* lsp-semantic-tokens
    	hook window -group semantic-tokens NormalIdle .* lsp-semantic-tokens
    	hook window -group semantic-tokens InsertIdle .* lsp-semantic-tokens
    	hook -once -always window WinSetOption filetype=.* %{
    		 remove-hooks window semantic-tokens
    	}
    	
    	# Other things
    	#hook window BufWritePre .* lsp-formatting-sync # this breaks shit
    	hook window BufWritePost .* lsp-diagnostics
    	hook -always global KakEnd .* lsp-exit
        hook global WinSetOption filetype=rust %{
            set-option window lsp_server_configuration rust.clippy_preference="on"
        }
    }
}

And my kak-lsp.toml

lsp_hover_anchor=true
lsp_hover_max_lines=6
snippet_support = true
verbosity = 3

[semantic_scopes]
# Map textmate scopes to kakoune faces for semantic highlighting
# the underscores are translated to dots, and indicate nesting.
# That is, if variable_other_field is omitted, it will try the face for
# variable_other and then variable
#
# To see a list of available scopes in the debug buffer, run lsp-semantic-available-scopes
variable = "variable"
entity_name_function = "function"
entity_name_type = "type"
variable_other_enummember = "variable"
entity_name_namespace = "module"

# Semantic tokens support
# See https://github.com/microsoft/vscode-languageserver-node/blob/8c8981eb4fb6adec27bf1bb5390a0f8f7df2899e/client/src/semanticTokens.proposed.ts#L288
# for token/modifier types.

[semantic_tokens]
type = "type"
variable = "variable"
namespace = "module"
function = "function"
string = "string"
keyword = "keyword"
operator = "operator"
comment = "comment"

[semantic_modifiers]
documentation = "documentation"
readonly = "default+d"

[server]
# exit session if no requests were received during given period in seconds
# works only in unix sockets mode (-s/--session)
# set to 0 to disable
timeout = 1800 # seconds = 30 minutes

[language.c_cpp]
filetypes = ["c", "cpp", "objc", "objcpp", "cuda"]
roots = [".ccls", "compile_commands.json"]
command = "ccls"

[language.d]
filetypes = ["d", "di"]
roots = [".git", "dub.sdl", "dub.json"]
command = "dls"

[language.rust]
filetypes = ["rust"]
roots = ["Cargo.toml"]
command = "rls"

[language.haskell]
filetypes = ["haskell"]
roots = ["Setup.hs", "stack.yaml", "*.cabal"]
command = "haskell-language-server-wrapper"
args = ["--lsp"]

[language.nim]
filetypes = ["nim"]
roots = ["*.nimble", ".git"]
command = "nimlsp"

[language.elixir]
filetypes = ["elixir", "exs", "eex"]
roots = ["mix.exs"]
command = "~/Tools/Elixir/elixir-ls/release/language_server.sh"

[language.latex]
filetypes = ["latex"]
roots = [".git"]
command = "texlab"

[language.javascript]
filetypes = ["javascript"]
roots = ["package.json", "jsconfig.json"]
command = "tsserver"

[language.typescript]
filetypes = ["typescript"]
roots = ["package.json", "tsconfig.json"]
command = "tsserver"

But when I open up a Typescript project, I’ve yet to see anything that indicates kak-lsp has started. I can’t find it as a running process, nor can I find tsserver running. There’s no hovering, or any completion outside of what is in the buffer. This is the same with other language servers.

What exactly am I missing?

EDIT: ~/.cargo/bin is in my path for the shell I use (fish-shell), but does it need to be in the path for plain sh as well?

Ah, I see this issue is that I have to actually have the kak-lsp command ran with eval %sh{}, and that in the kak-lsp.toml I have to have the field filetypes not fileTYPE. I’ve fixed them in this post as well.

1 Like

you can check :lsp-capabilities. If it shows something then the server is running.

Does your „edit“ mean you solved it? Or do you still need help?

Next kak-lsp feature, config validation? :slight_smile:

Uh well I solved a problem.

The issue now is that I don’t see the lsp providing any hovering or diagnostics. The completions just seems to be stuff that’s in the file as well.

I know for sure ccls can do all of that, but there’s nothing there that really indicates ccls is being used. Like it would in Emacs.

I ran :lsp-capabilities like @andreyorst said in a little C project that has the files necessary for ccls (and *debug* even shows that supposedly ccls was enabled), but nothing popped up.

Does anyone else have this issue? Because if not, I’m unsure as to why it’s just me.

1 Like

Can you give us:

  • kak-lsp -V or if you build from source git show in the directory.

  • kak -version (has the git in it if you built from source)

kak-lsp -V: kak-lsp 8.0.0-snapshot
kak -version: Kakoune v2020.01.16-273-g74e3e5ef

The kak-lsp -V isn’t very helpful, but if it helps it was just updated a few minutes ago when I ran plug-update. So whatever the most recent update to master was, I guess?

what about other servers, like RLS for Rust - does it work? Have you tried other than ccls server for C/C++, like clangd?

пн, 15 июн. 2020 г., 17:58 Alec Stewart via Kakoune Community Hub <noreply@discuss.kakoune.com>:

I’d tried in total ccls for C, dls for D, nimlsp for Nim, elixir_ls for Elixir, and tsserver for Javascript and Typescript.

All the same results of no hover, diagnostics, or any completion outside of what was in the buffer.

I have yet to try rls for Rust, texlab for LaTeX, or haskell-language-server-wrapper for Haskell.

Well rls didn’t work either. I’m going to guess the others aren’t either.

Is it something silly like I need to set my PATH for plain sh? All the language server commands are in my PATH for fish.

I wouldn’t be so concerned about this issue if others were having the same problem.

Yes, Kakoune doesn’t use fish at all, unless you explicitly say it to (but then everything will break), so you probably have to maintain POSIX complaint $PATH variable.

Well running :eval %sh{ echo $PATH } shows the PATH that I’ve set in fish that contains the paths to the corresponding executables. Kakoune must run /bin/sh interactively, which is why the $PATH variable is set like it is in fish. EDIT: I mean that would make the most sense anyway.

I would also think kak-lsp should throw an error saying it couldn’t find the corresponding executables for the LSPs if that was the issue.

This issue is really bugging me, because I feel like there’s one small dumb thing I did that causing me all of this trouble.

I got in trouble once by not remembering that OS-X uses a very different directory for the kak-lsp config than Linux (I switch between). You aren’t on OS-X and using like ~/.config/… are you?

Nope.

I’m on Linux and everything is in ~/.config.

EDIT: I’m putting this on kak-lsp github page as an issue. I’m trying to look over everything to see if this is something on my part.

EDIT: YESSSSS! I’ve got it working and what’s more, it’s working beautifully. Now all that remains is to set it up for the umpteen languages I wanna program in! Whoever wrote that nice piece in the manual about how to set up debug messaging in terminal, thanks from the bottom of my heart!

How to easily see (and fix) what's going on with your kak-lsp:

Add this to your kakrc file, as the next command after wherever you’ve put lsp-enable or lsp-enable-window:

set global lsp_cmd "kak-lsp -s %val{session} -vvv --log /tmp/kak-lsp.log"

Then, saving this, close kak and open a terminal in another window. Run:

kak-lsp -s main

from that window, then start kakoune back up again in its usual window. You’ll now see extremely helpful error messages pop up in the second terminal window whenever kak-lsp errors, or (more usually) when it finds an error with the LSP you’re trying to use.

Note that you’ll see errors produced by either of the mistakes below if you’ve set up your terminal for debugging correctly.

Two important warnings!

Firstly, mind where you put your config file (your kak-lsp.toml). The default path to the kak-lsp config file might not be where you think it is. In the kak-lsp readme, there is at least one line that say you should create your config file at kak-lsp/kak-lsp.toml .

That is only half of the story!. You don’t go to the existing folder at {OS-specific config dir}/kak/plugins/kak-lsp, – but rather, you must create a completely new folder in which to place a new config file, at {OS-specific config dir}/kak-lsp/. So, on your basic Linux set up, that path would look like: ~/.config/kak-lsp/kak-lsp.toml. Altering the config file inside the plugin folder doesn’t seem to do anything, so be sure to either create that new folder or change the option for the config path manually.

Secondly, mind how you enter your language server info into the kak-lsp.toml config file. First time around, I had foolishly added something like the following:

[language.javascript]
filetypes = ["javascript"]
roots = ["package.json"]
command = "typescript-language-server --stdio"

But that didn’t work, as kak-lsp doesn’t know how to handle the long-form command correctly. Instead, you need to make sure anything extraneous to the main command name goes into the ‘args’ field:

[language.javascript]
filetypes = ["javascript"]
roots = ["package.json"]
command = "typescript-language-server"
args = ["--stdio"]

A word of caution here, too. When I tried the above, my initial mistake was to put args = [" --stdio"], with an extra space – but even that small bit of whitespace was enough to make kak-lsp crash instead of correctly loading the LSP. Finally, with all that confusion out of the way, however, my kak-lsp is running beautifully!

2 Likes

Have you run it manually from the console? I don’t use any of the built-in install stuff. Can you just run kak-lsp directly?

Add the commands described in GitHub - ocaml/ocaml-lsp: OCaml Language Server Protocol implementation
to your kakrc. If the lsp-* commands are available, then kak-lsp was loaded successfully.
Which language server do you intend to use?

I’m so happy that kak-lsp is working now. Scroll up for my mini kak-lsp debugging guide :relaxed:

I wonder if kak-lsp should just display a prominent error if command contains a space. You’re not the first one to fall in this trap :wink:
The error would show up as popup inside Kakoune.
I don’t think there is a realistic need for spaces inside command names, is there?

I think that’s a great idea – when your extension / open source project has good error messages and can gently guide even the most clueless user (i.e. me!) toward correct usage, that’s one of the things that can really help your work to stand out from the pack :grinning: