diff options
Diffstat (limited to 'autoload')
| -rw-r--r-- | autoload/+init.kak | 34 | ||||
| -rw-r--r-- | autoload/formatter.kak | 24 | ||||
| -rw-r--r-- | autoload/lsp-config.kak | 54 |
3 files changed, 81 insertions, 31 deletions
diff --git a/autoload/+init.kak b/autoload/+init.kak index b7e7d27..f9ca258 100644 --- a/autoload/+init.kak +++ b/autoload/+init.kak @@ -1,7 +1,8 @@ # Link builtin autoloads nop %sh{ ln -sf "$kak_runtime/rc" "$kak_config/autoload/standard-library" 2>/dev/null || true } -evaluate-commands %sh{kcr init kakoune} -evaluate-commands %sh{kak-tree-sitter -dksvv --init "${kak_session}" --with-highlighting --with-text-objects} + +eval %sh{kak-tree-sitter -dksvv --init "${kak_session}" --with-highlighting --with-text-objects} +eval %sh{kcr init kakoune} hook global KakBegin .* %{ require-module luar @@ -18,7 +19,7 @@ set-option global startup_info_version 20250603 set-option global scrolloff 10,3 set-option -add global ui_options terminal_enable_mouse=false terminal_set_title=true set-option global modelinefmt \ -'{StatusLineDetails}{{context_info}} {{mode_info}} +'%opt{lsp_modeline_progress} {StatusLineDetails}{{context_info}} {{mode_info}} %val{cursor_line}/%val{buf_line_count}:%val{cursor_char_column} {StatusLineBufname}%sh{echo "$kak_bufname" | awk -F/ "{if (NF >= 2) {print \$(NF-1) \"/\" \$NF} else {print \$NF}}"}' @@ -49,10 +50,12 @@ map global user p "<a-!> xclip -selection clipboard -o<ret>" -docstring "paste t declare-user-mode system map global user q ': enter-user-mode system<ret>' -docstring 'System mode' -map global system o ':echo %opt{}<left>' -map global system v ':echo %val{}<left>' -map global system d ':buffer *debug*<ret>' -map global system f ':fennel %{()}<left><left>' +map global system o ':echo %opt{}<left>' -docstring 'Print opt' +map global system v ':echo %val{}<left>' -docstring 'Print value' +map global system d ': buffer *debug*<ret>' -docstring 'Switch to debug buffer' +map global system f ':set buffer filetype ' -docstring 'Set filetype' +map global system m ':set buffer makecmd ""<left>' -docstring 'Set compile command' +map global system p ': info %val{buffile}<ret>' -docstring 'Print file path' # Preserve count for user modes (look for alternatives) # TODO: Reset count on modechange? @@ -64,15 +67,20 @@ define-command enter-user-mode-with-count -params 1 %{ # Code mode declare-user-mode code -map global user c ':enter-user-mode code<ret>' -docstring 'Code mode' -map global code c :comment-line<ret> -docstring 'Comment/uncomment lines' -map global code f :format<ret> -docstring 'Format buffer' +map global user c ': enter-user-mode code<ret>' -docstring 'Code mode' +map global code c ': comment-line<ret>' -docstring 'Comment/uncomment lines' +map global code f ': apply-formatting<ret>' -docstring 'Apply configured formatter' def casecamel %{ exec '`s[-_<space>]<ret>d~<a-i>w' } def casesnake %{ exec '<a-:><a-;>s-|[a-z][A-Z]<ret>;a<space><esc>s[-\s]+<ret>c_<esc><a-i>w`' } def casekebab %{ exec '<a-:><a-;>s_|[a-z][A-Z]<ret>;a<space><esc>s[_\s]+<ret>c-<esc><a-i>w`' } -map global code <a-minus> :casekebab<ret> -docstring 'kebab-casing' -map global code <a-_> :casesnake<ret> -docstring 'snake_casing' -map global code <a-c> :casecamel<ret> -docstring 'camelCasing' +map global code <a-minus> ': casekebab<ret>' -docstring 'kebab-casing' +map global code <a-_> ': casesnake<ret>' -docstring 'snake_casing' +map global code <a-c> ': casecamel<ret>' -docstring 'camelCasing' + +declare-user-mode ai +map global code a ': enter-user-mode ai<ret>' -docstring 'AI' +map global ai ! '!ai ""<left>' -docstring 'Insert output' +map global ai | '|ai ""<left>' -docstring 'Replace output' # Editorconfig hook global BufOpenFile .* %{ try %{ editorconfig-load } } diff --git a/autoload/formatter.kak b/autoload/formatter.kak index 6012604..955ad14 100644 --- a/autoload/formatter.kak +++ b/autoload/formatter.kak @@ -1,20 +1,34 @@ +declare-option str formatlspserver; + hook global BufSetOption filetype=json %{ set-option buffer formatcmd "jq" } hook global BufSetOption filetype=fennel %{ set-option buffer formatcmd "fnlfmt -" } hook global BufSetOption filetype=nix %{ set-option buffer formatcmd "nixfmt -" } +hook global BufSetOption filetype=ruby %{ set-option buffer formatlspserver rubocop } + hook global BufSetOption filetype=(?:javascript|typescript) %{ evaluate-commands %sh{ if [ -f "$PWD/biome.json" ]; then - echo "set-option buffer formatcmd %{npx biome check --fix --stdin-file-path=$kak_buffile 2>/dev/null}" + echo "set-option buffer formatlspserver biome" + else + echo "set-option buffer formatlspserver typescript-language-server" fi } } +define-command biome -docstring 'Format file on disk using biome' %{ + nop %sh{ npx biome check --fix --stdin-file-path=$kak_buffile } +} -hook global BufSetOption filetype=(?:ruby) %{ - evaluate-commands %sh{ - echo "set-option buffer formatcmd %{rubocop -x --stderr -s '$kak_buffile'}" +define-command apply-formatting -docstring 'Apply formatting with formatcmd or lsp' %{ + eval %sh{ + if [ -n "$kak_opt_formatcmd" ]; then + echo format-buffer + elif [ -n "$kak_opt_formatlspserver" ]; then + echo "lsp-formatting-sync $kak_opt_formatlspserver" + else + echo lsp-formatting-sync + fi } } - diff --git a/autoload/lsp-config.kak b/autoload/lsp-config.kak index c9af393..2851011 100644 --- a/autoload/lsp-config.kak +++ b/autoload/lsp-config.kak @@ -1,4 +1,10 @@ eval %sh{kak-lsp} +# Disable default server configs +remove-hooks global lsp-filetype-javascript +remove-hooks global lsp-filetype-c-family +remove-hooks global lsp-filetype-ruby +remove-hooks global lsp-filetype-haskell + set-option global lsp_file_watch_support true set-option global lsp_snippet_support true set-option global lsp_diagnostic_line_error_sign '' @@ -23,27 +29,33 @@ hook global InsertCompletionHide .* %{ map global insert <c-n> '<a-;>: lsp-snippets-select-next-placeholders<ret>' -docstring 'Select next snippet placeholder' } -hook global BufSetOption filetype=(?:javascript|typescript) %{ +hook global BufSetOption filetype=(?:javascript|typescript|tsx|jsx) %{ set-option buffer lsp_servers %{ [typescript-language-server] - root_globs = ["package.json", "tsconfig.json", "jsconfig.json", ".git"] args = ["--stdio"] + root_globs = ["package.json", "tsconfig.json", "jsconfig.json", ".git"] + settings_section = "_" + [typescript-language-server.settings] + format = { enable = false } + [typescript-language-server.settings._] + quotePreference = "single" + [tailwindcss-language-server] - root_globs = ["tailwind.*", "postcss.*"] args = ["--stdio"] + root_globs = ["tailwind.*", "postcss.config.*"] [tailwindcss-language-server.settings.tailwindCSS] editor = {} - # [biome] - # root_globs = ["biome.json", "package.json", "tsconfig.json", "jsconfig.json"] - # args = ["lsp-proxy"] + + [biome] + args = ["lsp-proxy"] + root_globs = ["biome.json"] } } -remove-hooks global lsp-filetype-c-family hook global BufSetOption filetype=(?:c|cpp|objc) %{ set-option buffer lsp_servers %{ [clangd] - args = ["--log=error"] + args = [ "--log=info", "--clang-tidy" ] root_globs = ["compile_commands.json", ".clangd", ".git"] } } @@ -51,8 +63,27 @@ hook global BufSetOption filetype=(?:c|cpp|objc) %{ hook global BufSetOption filetype=ruby %{ set-option buffer lsp_servers %{ [ruby-lsp] - root_globs = ["Gemfile"] args = ["stdio"] + root_globs = ["Gemfile"] + + [rubocop] + command = "bundle" + args = ["exec", "rubocop", "--lsp"] + root_globs = ["Gemfile", ".git"] + } +} + +hook -group lsp-filetype-haskell global BufSetOption filetype=haskell %{ + set-option buffer lsp_servers %{ + [haskell-language-server] + command = "haskell-language-server-wrapper" + args = ["--lsp"] + root_globs = ["hie.yaml", "cabal.project", "Setup.hs", "stack.yaml", "*.cabal"] + settings_section = "_" + [haskell-language-server.settings] + hlintOn = true + [haskell-language-server.settings._] + haskell.formattingProvider = "ormolu" } } @@ -60,9 +91,7 @@ hook global WinSetOption filetype=.* %{ 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 - } + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window semantic-tokens } set-option window lsp_semantic_tokens %{ [ @@ -81,4 +110,3 @@ hook global WinSetOption filetype=.* %{ ] } } - |
