{ lib, pkgs, config, ... }: let kakrc = pkgs.writeTextFile (rec { name = "kakrc.kak"; destination = "/share/kak/autoload/${name}"; text = with (import ../../colors.nix)."dark"; '' # Line numbering add-highlighter global/ number-lines -separator ' │ ' -hlcursor # Setting the tabstop to 4 (even though I have an ultrawide monitor) set-option global tabstop 4 set global ui_options ncurses_assistant=cat # Use Alt-Tab to switch between open buffers map global insert :buffer-next map global normal :buffer-next colorscheme common face global LineNumbers rgb:${background.slight} face global BufferPadding rgb:${background.slight} face global LineNumberCursor rgb:${foreground.primary} face global crosshairs_line "default,rgb:${background.normal}" face global MenuForeground "default,blue" face global MenuBackground "default,rgb:313131" face global InlayHint rgb:828282 face global comment rgb:${foreground.slight} '' + (lib.optionalString (config.riley.ide) '' eval %sh{ kak-lsp --kakoune -s $kak_session } hook global -group yeet ModuleLoaded rust %{ # Override the Rust highlighting with semantic # tokens supplied by the LSP client remove-hooks global rust-highlight remove-highlighter shared/rust # Request tokens lsp-semantic-tokens # Self-destruct this hook (it should only run once) remove-hooks global yeet } # Load language-specific color schemes hook global WinSetOption filetype=(haskell) %{ colorscheme haskell lsp-enable-window lsp-inlay-diagnostics-enable global map global ': lsp-code-actions' map global ': lsp-hover' } hook global WinSetOption filetype=(rust) %{ lsp-enable-window lsp-inlay-diagnostics-enable window colorscheme rust hook window -group semtok BufReload .* lsp-semantic-tokens hook window -group semtok NormalIdle .* lsp-semantic-tokens hook window -group semtok InsertIdle .* lsp-semantic-tokens hook -once -always window WinSetOption filetype=.* %{ remove-hooks window semtok } hook window ModeChange .*:.*:insert %{ remove-highlighter window/lsp_diagnostics } hook window ModeChange .*:insert:normal %{ lsp-inlay-diagnostics-enable window } set global lsp_inlay_diagnostic_sign '>' map global normal ': lsp-code-actions' map global normal ': lsp-hover' } hook global WinSetOption filetype=(nix) %{ colorscheme nix lsp-enable-window } face global InlayDiagnosticWarning rgb:a39e31+f face global InlayDiagnosticError rgb:ad494f+f face global InlayDiagnosticHint rgb:4d965a+f ''); }); # Syntax colors colors = (import ./colors { theme = (import ../../colors.nix)."dark"; inherit lib pkgs; }); # Config for kak-lsp kak-lsp-config = pkgs.writeTextFile (rec { name = "kak-lsp.toml"; destination = "/share/kak-lsp/${name}"; text = let semTok = (name: value: '' [[semantic_tokens]] token = "${name}" face = "${value}" ''); in '' [language.rust] filetypes = [ "rust" ] roots = [ "Cargo.toml" ] command = "rust-analyzer" [language.rust.settings.rust-analyzer] semanticTokens = true diagnostics.enabled = [ "unresolved-proc-macro" ] cargo.loadOutDirsFromCheck = true procMacro.enable = false [language.haskell] filetypes = [ "haskell" ] roots = [ "Setup.hs", "stack.yaml", "*.cabal" ] command = "haskell-language-server-wrapper" args = [ "--lsp" ] [language.nix] filetypes = [ "nix" ] roots = [ "flake.nix", "shell.nix", ".git", ".hg" ] command = "rnix-lsp" ${lib.concatStringsSep "\n" (lib.mapAttrsToList semTok { "enumMember" = "variant"; "enum" = "enum"; "union" = "union"; "struct" = "struct"; "typeAlias" = "alias"; "builtinType" = "primitive"; "trait" = "trait"; "interface" = "trait"; "method" = "method"; "function" = "function"; "namespace" = "module"; "boolean" = "literal"; "character" = "literal"; "number" = "literal"; "string" = "string"; "keyword" = "keyword"; "documentation" = "comment"; "comment" = "comment"; "escapeSequence" = "format"; "formatSpecifier" = "format"; "operator" = "operator"; "arithmetic" = "operator"; "bitwise" = "operator"; "comparison" = "operator"; "logical" = "operator"; "macro" = "macro"; "lifetime" = "lifetime"; "variable" = "variable"; "attribute" = "attribute"; "punctuation" = "punctuation"; }) } ''; }); in { environment.systemPackages = with pkgs; [ (pkgs.kakoune.override { plugins = with kakounePlugins; [ # Custom config kakrc # Kakoune language server support (symlinkJoin { paths = [ # The language server client kak-lsp # Include default language servers rnix-lsp haskell-language-server # Overwrite kak-lsp.toml kak-lsp-config ]; name = "kak-lsp-${kak-lsp.version}"; nativeBuildInputs = [ makeWrapper ]; postBuild = '' wrapProgram $out/bin/kak-lsp --add-flags "--config $out/share/kak-lsp/kak-lsp.toml" ''; }) ] ++ colors; }) ]; }