diff --git a/user/kakoune/default.nix b/user/kakoune/default.nix index a1f7a92..4bb91f5 100644 --- a/user/kakoune/default.nix +++ b/user/kakoune/default.nix @@ -7,6 +7,9 @@ in config = { programs.kakoune = { enable = true; + plugins = with pkgs.kakounePlugins; [ + kak-lsp + ]; extraConfig = let colors = lib.mapAttrs (_: lib.replaceStrings [ "#" ] [ "rgb:" ]) { @@ -27,6 +30,7 @@ in ./indent.kak ./keys.kak ./plug.kak + ./lsp.kak ./usermode.kak ./git-mode.kak ] ++ lib.optional (dmenu == "rofi") ./rofi-commands.kak)) + '' @@ -131,7 +135,6 @@ in }; home.file = { ".config/kak-lsp/kak-lsp.toml".source = ./kak-lsp.toml; }; home.packages = with pkgs; [ - kakoune terminal ranger bmenu @@ -145,8 +148,8 @@ in ]; home.activation = { update_kakoune = lib.hm.dag.entryAfter [ "writeBoundary" ] '' - $DRY_RUN_CMD kak -clear && - $DRY_RUN_CMD kak -l | xargs -r -n1 kak -e "config-source;quit" -ui dummy -c || + $DRY_RUN_CMD timeout 5s kak -clear && + $DRY_RUN_CMD timeout 5s kak -l | xargs -r -n1 timeout 5s kak -e "config-source;quit" -ui dummy -c || $DRY_RUN_CMD true ''; }; diff --git a/user/kakoune/lsp.kak b/user/kakoune/lsp.kak new file mode 100644 index 0000000..92fcf3c --- /dev/null +++ b/user/kakoune/lsp.kak @@ -0,0 +1,62 @@ +hook global BufCreate .* -once %{ + +map global normal ': lsp-rename-prompt' +set global lsp_hover_max_lines 10 +set global lsp_auto_highlight_references true +set global lsp_inlay_diagnostic_sign "●" +set global lsp_diagnostic_line_error_sign "●" + +hook global BufCreate .* %{try lsp-enable} + +define-command -override -hidden lsp-next-placeholder-bind %{ + map global normal ': try lsp-snippets-select-next-placeholders catch %{ execute-keys -with-hooks tab> }' -docstring 'Select next snippet placeholder' + map global insert ': try lsp-snippets-select-next-placeholders catch %{ execute-keys -with-hooks tab> }' -docstring 'Select next snippet placeholder' +} +lsp-next-placeholder-bind +map global insert ": lsp-code-action-sync Fill" + +define-command -override -hidden lsp-enable-decals %{ + lsp-inlay-diagnostics-enable global + lsp-inlay-hints-enable global +} + +define-command -override -hidden lsp-disable-decals %{ + lsp-inlay-diagnostics-disable global + lsp-inlay-hints-disable global +} +lsp-enable-decals + +hook global ModeChange '.*:insert:normal' %{lsp-enable-decals} +hook global ModeChange '.*:normal:insert' %{lsp-disable-decals} + +hook global WinSetOption filetype=(c|cpp|rust) %{ + 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 + } + decl -hidden -docstring "Timestamp of the last check" int last_modified + hook window RawKey .* %{ + eval %sh{ + if [ "${kak_opt_last_modified}" != "${kak_timestamp}" ]; then + echo "unset-option buffer lsp_inlay_diagnostics" + echo "unset-option buffer lsp_inlay_hints" + fi + } + set current last_modified %val{timestamp} + } +} + +declare-option -hidden str modeline_progress "" +define-command -hidden -params 6 -override lsp-handle-progress %{ + set global modeline_progress %sh{ + if ! "$6"; then + echo "$2${5:+" ($5%)"}${4:+": $4"}" + fi + } +} + +set global modelinefmt "%%opt{modeline_progress} %opt{modelinefmt}" + +} diff --git a/user/kakoune/plug.kak b/user/kakoune/plug.kak index 9cd6bea..95867b6 100644 --- a/user/kakoune/plug.kak +++ b/user/kakoune/plug.kak @@ -36,68 +36,3 @@ plug 'lelgenio/kak-crosshairs' config %{ plug "natasky/kakoune-multi-file" plug "lelgenio/kakoune-colemak-neio" - -plug 'kak-lsp/kak-lsp' do %{ - rustup target add x86_64-unknown-linux-musl - cargo install --locked --force --path . --target x86_64-unknown-linux-musl -} config %{ - map global normal ': lsp-rename-prompt' - set global lsp_hover_max_lines 10 - set global lsp_auto_highlight_references true - set global lsp_inlay_diagnostic_sign "●" - set global lsp_diagnostic_line_error_sign "●" - - hook global BufCreate .* %{try lsp-enable} - - define-command -override -hidden lsp-next-placeholder-bind %{ - map global normal ': try lsp-snippets-select-next-placeholders catch %{ execute-keys -with-hooks tab> }' -docstring 'Select next snippet placeholder' - map global insert ': try lsp-snippets-select-next-placeholders catch %{ execute-keys -with-hooks tab> }' -docstring 'Select next snippet placeholder' - } - lsp-next-placeholder-bind - map global insert ": lsp-code-action-sync Fill" - - define-command -override -hidden lsp-enable-decals %{ - lsp-inlay-diagnostics-enable global - lsp-inlay-hints-enable global - } - - define-command -override -hidden lsp-disable-decals %{ - lsp-inlay-diagnostics-disable global - lsp-inlay-hints-disable global - } - lsp-enable-decals - - hook global ModeChange '.*:insert:normal' %{lsp-enable-decals} - hook global ModeChange '.*:normal:insert' %{lsp-disable-decals} - - hook global WinSetOption filetype=(c|cpp|rust) %{ - 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 - } - decl -hidden -docstring "Timestamp of the last check" int last_modified - hook window RawKey .* %{ - eval %sh{ - if [ "${kak_opt_last_modified}" != "${kak_timestamp}" ]; then - echo "unset-option buffer lsp_inlay_diagnostics" - echo "unset-option buffer lsp_inlay_hints" - fi - } - set current last_modified %val{timestamp} - } - } - - declare-option -hidden str modeline_progress "" - define-command -hidden -params 6 -override lsp-handle-progress %{ - set global modeline_progress %sh{ - if ! "$6"; then - echo "$2${5:+" ($5%)"}${4:+": $4"}" - fi - } - } - - set global modelinefmt "%%opt{modeline_progress} %opt{modelinefmt}" -} -