Last active
March 13, 2024 15:19
-
-
Save igor-ramazanov/c34db533697f3d58f69b36364f547c0e to your computer and use it in GitHub Desktop.
kakoune-lsp config, save it as `~/.config/kak/autoload/lsp.kak`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
eval %sh{kak-lsp/target/release/kak-lsp --kakoune --session $kak_session} | |
hook global WinSetOption filetype=(scala|java|nix|rust|smithy|terraform|c|python|nu|unison|cpp) %{ | |
lsp-enable-window | |
# Show signature in the insert mode. | |
lsp-auto-signature-help-enable | |
# Indent guides | |
# WIP: https://github.com/kakoune-lsp/kakoune-lsp/pull/720 | |
# lsp-indent-guides-enable window | |
# Sticky contexts | |
# WIP: https://github.com/kakoune-lsp/kakoune-lsp/pull/721 | |
# lsp-sticky-contexts-enable window | |
# Inlay Code lenses (run tests, etc.) | |
lsp-inlay-code-lenses-enable window | |
# In-editor error/warning messages. | |
lsp-inlay-diagnostics-enable window | |
# Types, implicits, worksheets output. | |
lsp-inlay-hints-enable window | |
# IDE-like completion with LSP. | |
set-option -remove window completers filename word=all | |
# Auto-formatting | |
hook window BufWritePre .*\.(scala|sbt|sc|nix|rs|py) lsp-formatting-sync | |
# Right-side panel with hover documentation. | |
nop %sh{ | |
if [ -z "$(tmux list-panes -af "#{==:$kak_session,#{@kak_session_lsp}}")" ] | |
then | |
PANE_ID="$(tmux splitw -Phdl 25% -F '#{pane_id}' -- "kak -c $kak_session -e 'rename-client hover'")" | |
tmux set -pt "$PANE_ID" "@kak_session_lsp" "$kak_session" | |
fi | |
} | |
map window normal <c-down> :lsp-next-symbol<ret> | |
map window normal <c-up> :lsp-previous-symbol<ret> | |
# Press <c-o> to hide completion menu. | |
# When the menus hides, and there snippets available, use tab to iterate across placeholders. | |
hook window InsertCompletionHide .* %{ | |
map window insert <tab> '<a-;>:lsp-snippets-select-next-placeholders<ret>' | |
} | |
hook window InsertCompletionShow .* %{ | |
unmap window insert <tab> '<a-;>:lsp-snippets-select-next-placeholders<ret>' | |
} | |
} | |
# Focus the selected location from the goto-like buffer and show a preview in the side panel. | |
define-command lsp-focus-in-hover %{ | |
execute-keys xs^[^\s]+<ret> | |
evaluate-commands -client hover %sh{ | |
if [ -n $kak_selection ] | |
then | |
FILE=$(echo $kak_selection | cut -d: -f1) | |
LINE=$(echo $kak_selection | cut -d: -f2) | |
if [ -n $FILE ] && [ -n $LINE ] | |
then | |
echo "edit $FILE $LINE; execute-keys x" | |
fi | |
fi | |
} | |
} | |
hook global WinDisplay \*(goto|symbols|diagnostics)\* %{ | |
hook window NormalKey (j|<down>) lsp-focus-in-hover | |
hook window NormalKey (k|<up>) lsp-focus-in-hover | |
} | |
# Close the side panel on exit. | |
hook global ClientClose client0 %{nop %sh{ | |
PANE_ID="$(tmux list-panes -af "#{==:$kak_session,#{@kak_session_lsp}}" -F '#{pane_id}')" | |
if [ -n "$PANE_ID" ] | |
then | |
tmux killp -t "$PANE_ID" | |
fi | |
}} | |
set-option global lsp_auto_highlight_references true | |
set-option global lsp_auto_show_code_actions true | |
set-option global lsp_hover_anchor false | |
set-option global lsp_hover_max_lines 0 | |
set-option global lsp_insert_spaces true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment