dotfiles/.config/kak/autoload/lsp.kak

148 lines
5 KiB
Text

# load plugin
eval %sh{kak-lsp}
# mappings
map global user l ': enter-user-mode lsp<ret>' -docstring 'LSP mode'
map global insert <tab> '<a-;>:try lsp-snippets-select-next-placeholders catch %{ execute-keys -with-hooks <lt>tab> }<ret>' -docstring 'Select next snippet placeholder'
map global object a '<a-semicolon>lsp-object<ret>' -docstring 'LSP any symbol'
map global object <a-a> '<a-semicolon>lsp-object<ret>' -docstring 'LSP any symbol'
map global object f '<a-semicolon>lsp-object Function Method<ret>' -docstring 'LSP function or method'
map global object t '<a-semicolon>lsp-object Class Interface Struct<ret>' -docstring 'LSP class interface or struct'
map global object d '<a-semicolon>lsp-diagnostic-object --include-warnings<ret>' -docstring 'LSP errors and warnings'
map global object D '<a-semicolon>lsp-diagnostic-object<ret>' -docstring 'LSP errors'
# override the code actions icon in the modeline
define-command -hidden -override lsp-show-code-actions -params 1.. %{
set-option buffer lsp_modeline_code_actions ""
}
define-command -hidden -override lsp-hide-code-actions %{
set-option buffer lsp_modeline_code_actions ""
}
# Server Config
set-option global lsp_debug false
# list of filetypes for which LSP will be activated in the window scope
declare-option str-list lsp_filetypes python go rust bash fish c cpp typst markdown yaml json jsonc bash sh typescript javascript
declare-option -hidden bool inlay_enabled false
define-command -hidden inlay-on %{
lsp-inlay-hints-enable window
set-option window inlay_enabled true
}
define-command -hidden inlay-off %{
lsp-inlay-hints-disable window
set-option window inlay_enabled false
}
define-command -hidden inlay-toggle %{
evaluate-commands %sh{
if [ "$kak_opt_inlay_enabled" = "true" ]; then
echo "inlay-off"
else
echo "inlay-on"
fi
}
}
declare-option -hidden bool diagnostics_enabled false
define-command -hidden diagnostics-on %{
lsp-inlay-diagnostics-enable window
set-option window diagnostics_enabled true
}
define-command -hidden diagnostics-off %{
lsp-inlay-diagnostics-disable window
set-option window diagnostics_enabled false
}
define-command -hidden diagnostics-toggle %{
evaluate-commands %sh{
if [ "$kak_opt_diagnostics_enabled" = "true" ]; then
echo "diagnostics-off"
else
echo "diagnostics-on"
fi
}
}
define-command -hidden lsp-filetype-hooks-update %{
try %{ remove-hooks global lsp-filetypes }
# convert the str-list into regex of form (a|b|c|...)
hook -group lsp-filetypes global WinSetOption %exp~filetype=%sh{
printf '%s\n' "($kak_opt_lsp_filetypes)" | sed 's/ /|/g'
}~ %{
# commands to execute for lsp window settings
lsp-enable-window
inlay-on
try %{
# only map to UI mode if that module is available
map -docstring 'toggle inlay hints' window ui h ': inlay-toggle<ret>'
map -docstring 'toggle inlay diagnostics' window ui d ': diagnostics-toggle<ret>'
} catch %{
map -docstring 'toggle inlay hints' window lsp <a-h> ': inlay-toggle<ret>'
map -docstring 'toggle inlay diagnostics' window lsp <a-d> ': diagnostics-toggle<ret>'
}
}
}
lsp-filetype-hooks-update
hook global WinSetOption lsp_filetypes=.* lsp-filetype-hooks-update
hook global BufSetOption lsp_filetypes=.* lsp-filetype-hooks-update
hook global GlobalSetOption lsp_filetypes=.* lsp-filetype-hooks-update
remove-hooks global lsp-filetype-python
hook -group lsp-filetype-python global BufSetOption filetype=python %{
set-option buffer lsp_servers %{
[basedpyright-langserver]
root_globs = ["requirements.txt", "setup.py", "pyproject.toml", "pyrightconfig.json", ".git", ".hg"]
args = ["--stdio"]
settings_section = "basedpyright"
[basedpyright-langserver.settings.basedpyright.analysis]
typeCheckingMode = "standard"
inlayHints.genericTypes = true
}
}
remove-hooks global lsp-filetype-javascript
hook -group lsp-filetype-javascript global BufSetOption filetype=(?:javascript|typescript) %{
set-option buffer lsp_servers %{
[typescript-language-server]
root_globs = ["package.json", "tsconfig.json", "jsconfig.json", ".git", ".hg"]
args = ["--stdio"]
settings_section = "_"
[typescript-language-server.settings._]
# quotePreference = "double"
# typescript.format.semicolons = "insert"
}
}
# use our custom fish-lsp wrapper because it sets env vars
hook -group lsp-filetype-fish global BufSetOption filetype=fish %{
set-option buffer lsp_servers %{
[fish-lsp]
root_globs = [".git"]
args = ["start"]
command = "/home/fic/.config/kak/scripts/fish-lsp.fish"
}
}
remove-hooks global lsp-filetype-markdown
hook -group lsp-filetype-markdown global BufSetOption filetype=markdown %{
set-option buffer lsp_servers %{
[marksman]
root_globs = [".marksman.toml", ".git"]
args = ["server"]
[harper-ls]
root_globs = ["*"]
args = ["--stdio"]
command = "harper-ls"
[harper-ls.settings.harper-ls.linters]
LongSentences = false
}
}