Kak-lsp for julia LanguageServer.jl

Hey there,
I’m a complete newbie in Kakoune but I try to setup the lsp for julia. In nvim the server can be configured as follows:

let g:LanguageClient_serverCommands = {
\   'julia': ['julia', '--startup-file=no', '--history-file=no', '-e', '
\       using LanguageServer;
\       using Pkg;
\       import StaticLint;
\       import SymbolServer;
\       env_path = dirname(Pkg.Types.Context().env.project_file);
\       
\       server = LanguageServer.LanguageServerInstance(stdin, stdout, env_path, "");
\       server.runlinter = true;
\       run(server);
\   ']
\ }

So I edited the following in my ~/.config/kak-lsp/kak-lsp.toml

[language.julia]
filetypes = ["julia"]
command = "julia --startup-file=no --history-file=no -e "using LanguageServer; using Pkg; import StaticLint; import SymbolServer; env_path = dirname(Pkg.Types.Context().env.project_file); server = LanguageServer.LanguageServerInstance(stdin, stdout, env_path, \"\"); server.runlinter = true; run(server);""

I didn’t expect that it works on the first try, but I’d like to see errors, however, in the debug buffer there is nothing. Can you point me in the right directions to get debug messages or to get this thing working?

Okay, so curiously, kak-lsp is completely silent about the missing roots field.
This is needed to find the project root.

First I added the roots = [".git"] and added -vvv --log=my-log-file to kak-lsp’s parameters. The log contains this error after running :lsp-enable:

ERRO panic: panicked at 'Failed to start language server: Os { code: 36, kind: Other, message: "File name too long" }

This is because command is only the language server executable - in this case julia; the arguments are in a separate array. Also it looks like you are missing escapes for the inner double quotes - for example, you’d need to write something like "print(\"hello\")" but only if the string were actually interpreted by the shell, which it isn’t. So it’s much simpler:

[language.julia]
filetypes = ["julia"]
roots = [".git"]
command = "julia"
args = [
	"--startup-file=no",
	"--history-file=no",
	"-e",
	"""
		using LanguageServer;
		using Pkg;
		import StaticLint;
		import SymbolServer;
		env_path = dirname(Pkg.Types.Context().env.project_file);

		server = LanguageServer.LanguageServerInstance(stdin, stdout, env_path, "");
		server.runlinter = true;
		run(server);
	""",
	]

Go-to-definition (g+d) works, apparently there are 37 definitions of print() in the stdlib :astonished:

5 Likes

Oh wow, first of all thank you for help. Secondly, excuse me for derping with the strings, but I kinda forgot that it’s just normal toml format.

I’ll try to reproduce it tomorrow. Sorry for asking this naive question but where do I have to include the -vvv exactly? In case I have to debug.

Generally speaking I think kakoune can acquire a lot of users from Julia if the LSP integration works!

1 Like

You can pass custom options to kak-lsp like this in your kakrc:

eval %sh{kak-lsp --kakoune -s $kak_session}
set-option global lsp_cmd "kak-lsp -s %val{session} --log /tmp/kak-lsp-%val{session}.log -vvv"
lsp-enable

The log file is necessary because the language server is started with all output redirected to /dev/null because it needs to run in the background.
I guess it would be nice if we could make error messages show up in the *debug* buffer.

If you have a good default config for Julia, feel free to submit it to kak-lsp :wink:

I noticed the language server takes a few seconds to be ready, that’s probably okay.

I copied your toml and kakrc lines, but when I run a verbose debug session of kak-lsp with kak-lsp -s soomesessionname -vvv and open a .jl file with kak -s somesessionname somefile.jl I see that the LanguageServer starts but does nothing due to the following error:

Nov 24 11:19:16.979 ERRO Language server error: ERROR: MethodError: Cannot convert an object of type Nothing to an object of type Bool

I know that this is a Problem related to the server, i.e. julia specific, but I’m wondering why it works for you :thinking:

I’m on arch, julia 1.5.3, kak v2020.09.01 and kak-lsp 8.0.0 finstalled via pacman/yay

Edit: I guess related to https://github.com/kak-lsp/kak-lsp/issues/357

Edit 2: Indeed the problem is fixed with this PR https://github.com/kak-lsp/kak-lsp/pull/336, I installed kak-lsp-git instead of kak-lsp and now it works flawless. I will test around, optimize the setup and will make a request to add it in kak-lsp and LanguageServer.jl

2 Likes

Sounds great! The new release should come real soon :wink:


Kakoune is now listed with a wiki entry :slight_smile:
3 Likes