Skip to content
Soc Virnyl S. Estela edited this page Jun 8, 2024 · 4 revisions

Kakoune with LSP Integration for Julia

Blog Posts

Goal (2020)

kak-lsp

Requirements

  • Julia specific
    • LanguageServer.jl
    • StaticLint.jl
    • SymbolServer.jl
  • Kakoune
  • kak-lsp later than v8.0.0

Install a recent version of kakoune and kak-lsp. Note that in kak-lsp v8.0.0 and prior the LSP Integration won't work. Therefore, build the new-release v9.0.0 or use any dev version after v8.0.0.

Configure

Specify the Julia Language Server

  • Create the file ~/.config/kak-lsp/kak-lsp.toml and insert
[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);
        """,
        ]

In your kakrc append the following slightly adapted default config

plug "kak-lsp/kak-lsp" do %{
    cargo build --release --locked
    cargo install --force --path .
} config %{

    # uncomment to enable debugging
    # eval %sh{echo ${kak_opt_lsp_cmd} >> /tmp/kak-lsp.log}
    # set global lsp_cmd "kak-lsp -s %val{session} -vvv --log /tmp/kak-lsp.log"

    # this is not necessary; the `lsp-enable-window` will take care of it
    # eval %sh{${kak_opt_lsp_cmd} --kakoune -s $kak_session}

    set global lsp_diagnostic_line_error_sign '║'
    set global lsp_diagnostic_line_warning_sign '┊'
    set global lsp_hover_max_lines 40
    define-command ne -docstring 'go to next error/warning from lsp' %{ lsp-find-error --include-warnings }
    define-command pe -docstring 'go to previous error/warning from lsp' %{ lsp-find-error --previous --include-warnings }
    define-command ee -docstring 'go to current error/warning from lsp' %{ lsp-find-error --include-warnings; lsp-find-error --previous --include-warnings }

    define-command lsp-restart -docstring 'restart lsp server' %{ lsp-stop; lsp-start }
    hook global WinSetOption filetype=(c|cpp|cc|rust|javascript|typescript|julia) %{
        set-option window lsp_hover_anchor false
        lsp-auto-hover-enable
        echo -debug "Enabling LSP for filtetype %opt{filetype}"
        lsp-enable-window
    }

    hook global KakEnd .* lsp-exit
}

Test

  • Open a julia file of your choice, wait for a few secs and try g r which corresponds to goto references
  • If this doesn't work, check the comment lines in the kakrc config