Retab kak config

This commit is contained in:
Riley Apeldoorn 2022-05-23 13:17:26 +02:00
parent f398775552
commit 11e08fc437
3 changed files with 157 additions and 167 deletions

View File

@ -3,50 +3,50 @@
with pkgs.kakouneUtils; with pkgs.kakouneUtils;
let cfg = config.riley.kak; let cfg = config.riley.kak;
theme = config.riley.theme; theme = config.riley.theme;
kak-crosshairs = buildKakounePlugin (rec { kak-crosshairs = buildKakounePlugin (rec {
name = "kak-crosshairs"; name = "kak-crosshairs";
src = (pkgs.fetchFromGitHub { src = (pkgs.fetchFromGitHub {
owner = "insipx"; owner = "insipx";
repo = name; repo = name;
rev = "7edba13c535ce1bc67356b1c9461f5d261949d29"; rev = "7edba13c535ce1bc67356b1c9461f5d261949d29";
sha256 = "sha256-VOn9GGHludJasEwcCv6t1Q3/63w9139MCEkdRDnTw6E"; sha256 = "sha256-VOn9GGHludJasEwcCv6t1Q3/63w9139MCEkdRDnTw6E";
}); });
}); });
in in
with lib; { with lib; {
options.riley = { options.riley.kak = {
kak.enable = (mkEnableOption "kakoune editor") // { default = true; }; enable = (mkEnableOption "kakoune editor") // { default = true; };
kak.rust = mkEnableOption "Rust support in Kakoune"; rust = mkEnableOption "Rust support in Kakoune";
kak.ts = mkEnableOption "TypeScript support in Kakoune"; ts = mkEnableOption "TypeScript support in Kakoune";
kak.haskell = mkEnableOption "Haskell support in Kakoune"; haskell = mkEnableOption "Haskell support in Kakoune";
kak.python = mkEnableOption "Python 3.9 support in Kakoune"; python = mkEnableOption "Python 3.9 support in Kakoune";
kak.nix = (mkEnableOption "Nix support in Kakoune") // { default = true; }; nix = (mkEnableOption "Nix support in Kakoune") // { default = true; };
}; };
config = mkIf (cfg.enable) { config = mkIf (cfg.enable) {
environment.systemPackages = [ environment.systemPackages = [
(import ./kakoune.nix { (import ./kakoune.nix {
typescript = cfg.ts; typescript = cfg.ts;
haskell = cfg.haskell; haskell = cfg.haskell;
python = cfg.python; python = cfg.python;
rust = cfg.rust; rust = cfg.rust;
nix = cfg.nix; nix = cfg.nix;
inherit kak-crosshairs; inherit kak-crosshairs;
inherit pkgs lib theme; inherit pkgs lib theme;
})
];
})
];
}; };
} }

View File

@ -15,97 +15,100 @@ with lib;
with pkgs; with pkgs;
let semantic-tokens = let semantic-tokens =
let mk = (name: value: '' let mk = (name: value: ''
[[semantic_tokens]] [[semantic_tokens]]
token = "${name}" token = "${name}"
face = "${value}" face = "${value}"
''); in concatStringsSep "\n" (mapAttrsToList mk { ''); in concatStringsSep "\n" (mapAttrsToList mk {
"enumMember" = "variant"; "enumMember" = "variant";
"enum" = "enum"; "enum" = "enum";
"union" = "union"; "union" = "union";
"struct" = "struct"; "struct" = "struct";
"typeAlias" = "alias"; "typeAlias" = "alias";
"builtinType" = "primitive"; "builtinType" = "primitive";
"trait" = "trait"; "trait" = "trait";
"interface" = "trait"; "interface" = "trait";
"method" = "method"; "method" = "method";
"function" = "function"; "function" = "function";
"namespace" = "module"; "namespace" = "module";
"boolean" = "literal"; "boolean" = "literal";
"character" = "literal"; "character" = "literal";
"number" = "literal"; "number" = "literal";
"string" = "string"; "string" = "string";
"keyword" = "keyword"; "keyword" = "keyword";
"documentation" = "comment"; "documentation" = "comment";
"comment" = "comment"; "comment" = "comment";
"escapeSequence" = "format"; "escapeSequence" = "format";
"formatSpecifier" = "format"; "formatSpecifier" = "format";
"operator" = "operator"; "operator" = "operator";
"arithmetic" = "operator"; "arithmetic" = "operator";
"bitwise" = "operator"; "bitwise" = "operator";
"comparison" = "operator"; "comparison" = "operator";
"logical" = "operator"; "logical" = "operator";
"macro" = "macro"; "macro" = "macro";
"lifetime" = "lifetime"; "lifetime" = "lifetime";
"variable" = "variable"; "variable" = "variable";
"attribute" = "attribute"; "attribute" = "attribute";
"punctuation" = "punctuation"; "punctuation" = "punctuation";
}); });
kak-lsp-config-text = concatStringsSep "\n" ( kak-lsp-config-text = concatStringsSep "\n" (
(optional (rust || haskell) semantic-tokens) (optional (rust || haskell) semantic-tokens)
++ (optional rust '' ++ (optional rust ''
[language.rust] [language.rust]
filetypes = [ "rust" ] filetypes = [ "rust" ]
roots = [ "Cargo.toml" ] roots = [ "Cargo.toml" ]
command = "rust-analyzer" command = "rust-analyzer"
[language.rust.settings.rust-analyzer] [language.rust.settings.rust-analyzer]
semanticTokens = true semanticTokens = true
diagnostics.enabled = [ "unresolved-proc-macro" ] diagnostics.enabled = [ "unresolved-proc-macro" ]
cargo.loadOutDirsFromCheck = true cargo.loadOutDirsFromCheck = true
procMacro.enable = false procMacro.enable = false
'') '')
++ (optional nix '' ++ (optional nix ''
[language.nix] [language.nix]
filetypes = [ "nix" ] filetypes = [ "nix" ]
roots = [ "flake.nix", "shell.nix", ".git", ".hg" ] roots = [ "flake.nix", "shell.nix", ".git", ".hg" ]
command = "rnix-lsp" command = "rnix-lsp"
'') '')
++ (optional haskell '' ++ (optional haskell ''
[language.haskell] [language.haskell]
filetypes = [ "haskell" ] filetypes = [ "haskell" ]
roots = [ "Setup.hs", "stack.yaml", "*.cabal" ] roots = [ "Setup.hs", "stack.yaml", "*.cabal" ]
command = "haskell-language-server-wrapper" command = "haskell-language-server-wrapper"
args = [ "--lsp" ] args = [ "--lsp" ]
'') '')
++ (optional python '' ++ (optional python ''
[language.python] [language.python]
filetypes = [ "python" ] filetypes = [ "python" ]
roots = [ "setup.py", ".git", ".hg" ] roots = [ "setup.py", ".git", ".hg" ]
command = "pylsp" command = "pylsp"
'') '')
++ (optional typescript '' ++ (optional typescript ''
[language.typescript] [language.typescript]
filetypes = ["typescript", "javascript"] filetypes = ["typescript", "javascript"]
roots = ["package.json"] roots = ["package.json"]
command = "rslint-lsp" command = "rslint-lsp"
'')); ''));
kak-lsp-config = (pkgs.writeTextFile (rec { kak-lsp-config = (pkgs.writeTextFile (rec {
name = "kak-lsp.toml"; name = "kak-lsp.toml";
destination = "/share/kak-lsp/${name}"; destination = "/share/kak-lsp/${name}";
text = kak-lsp-config-text; text = kak-lsp-config-text;
})); }));
in (symlinkJoin { in (symlinkJoin {
paths = with kakounePlugins; [
# The language server client
kak-lsp
# Overwrite kak-lsp.toml name = "kak-lsp-${kak-lsp.version}";
kak-lsp-config nativeBuildInputs = [ makeWrapper ];
paths = with kakounePlugins; [
# The language server client
kak-lsp
# Overwrite kak-lsp.toml
kak-lsp-config
] ++ (optional nix rnix-lsp) ] ++ (optional nix rnix-lsp)
++ (optional typescript rslint) ++ (optional typescript rslint)
@ -113,9 +116,8 @@ in (symlinkJoin {
++ (optional python python39Packages.python-lsp-server) ++ (optional python python39Packages.python-lsp-server)
++ (optional rust rust-analyzer); ++ (optional rust rust-analyzer);
name = "kak-lsp-${kak-lsp.version}"; postBuild = ''
nativeBuildInputs = [ makeWrapper ]; wrapProgram $out/bin/kak-lsp --add-flags "--config $out/share/kak-lsp/kak-lsp.toml"
postBuild = '' '';
wrapProgram $out/bin/kak-lsp --add-flags "--config $out/share/kak-lsp/kak-lsp.toml"
'';
}) })

View File

@ -18,57 +18,49 @@
let keybinds = '' let keybinds = ''
map global insert <a-tab> <esc>:buffer-next<ret> map global insert <a-tab> <esc>:buffer-next<ret>
map global normal <a-tab> :buffer-next<ret> map global normal <a-tab> :buffer-next<ret>
''; '';
# Initialization code for IDE mode needed for every supported # Initialization code for IDE mode needed for every supported
# language, and inlay diagnostics. # language, and inlay diagnostics.
ide-init = '' ide-init = ''
eval %sh{ kak-lsp --kakoune -s $kak_session } eval %sh{ kak-lsp --kakoune -s $kak_session }
lsp-enable-window lsp-enable-window
lsp-inlay-diagnostics-enable window lsp-inlay-diagnostics-enable window
hook window ModeChange .*:.*:insert %{
remove-highlighter window/lsp_diagnostics
}
hook window ModeChange .*:insert:normal %{
lsp-inlay-diagnostics-enable window
}
hook window ModeChange .*:.*:insert %{ remove-highlighter window/lsp_diagnostics }
hook window ModeChange .*:insert:normal %{ lsp-inlay-diagnostics-enable window }
''; '';
# Implies `ide-init`. Adds code actions and hover. # Implies `ide-init`. Adds code actions and hover.
ide-core = '' ide-core = ''
${ide-init} ${ide-init}
map buffer normal <tab> ': lsp-code-actions<ret>' map buffer normal <tab> ': lsp-code-actions<ret>'
map buffer normal <ret> ': lsp-hover<ret>' map buffer normal <ret> ': lsp-hover<ret>'
''; '';
# Implies `ide-core`, which implies `ide-init`. # Implies `ide-core`, which implies `ide-init`.
ide-full = '' ide-full = ''
${ide-core} ${ide-core}
hook window -group semtok BufReload .* lsp-semantic-tokens hook window -group semtok BufReload .* lsp-semantic-tokens
hook window -group semtok NormalIdle .* lsp-semantic-tokens hook window -group semtok NormalIdle .* lsp-semantic-tokens
hook window -group semtok InsertIdle .* lsp-semantic-tokens hook window -group semtok InsertIdle .* lsp-semantic-tokens
hook -once -always window WinSetOption filetype=.* %{ hook -once -always window WinSetOption filetype=.* %{ remove-hooks window semtok }
remove-hooks window semtok
}
map global normal <a-down> ': lsp-next-function<ret>' map global normal <a-down> ': lsp-next-function<ret>'
map global normal <a-up> ': lsp-previous-function<ret>' map global normal <a-up> ': lsp-previous-function<ret>'
map global normal <a-left> ': lsp-previous-location *goto*<ret>' map global normal <a-left> ': lsp-previous-location *goto*<ret>'
map global normal <a-right> ': lsp-next-location *goto*<ret>' map global normal <a-right> ': lsp-next-location *goto*<ret>'
''; in ''; in
# Nix hacking-related configuration. Nix has a very weak language # Nix hacking-related configuration. Nix has a very weak language
@ -81,7 +73,7 @@ let nix-config = (lib.optionalString nix ''
# Sometimes work requires me to touch the frontend. Ew. `ide-core` # Sometimes work requires me to touch the frontend. Ew. `ide-core`
# suffices here. # suffices here.
typescript-config = (lib.optionalString typescript '' typescript-config = (lib.optionalString typescript ''
hook global WinSetOption filetype=(javascript|typescript) %{ hook global WinSetOption filetype=(javascript|typescript) %{
${ide-core} ${ide-core}
} }
@ -90,24 +82,24 @@ let nix-config = (lib.optionalString nix ''
# Python-related config. Python does not support more features than # Python-related config. Python does not support more features than
# those in `ide-core`. # those in `ide-core`.
python-config = (lib.optionalString python '' python-config = (lib.optionalString python ''
hook global WinSetOption filetype=python %{ hook global WinSetOption filetype=python %{
${ide-core} ${ide-core}
face window keyword rgb:${theme.green.bright} face window keyword rgb:${theme.green.bright}
face window meta keyword face window meta keyword
} }
''); '');
# Haskell development. Haskell has a language server with # Haskell development. Haskell has a language server with
# the features in `ide-full`. # the features in `ide-full`.
haskell-config = (lib.optionalString haskell '' haskell-config = (lib.optionalString haskell ''
hook global WinSetOption filetype=haskell %{ hook global WinSetOption filetype=haskell %{
${ide-full} ${ide-full}
set-option buffer tabstop 2 set-option buffer tabstop 2
face global variable rgb:${theme.purple.normal} face global variable rgb:${theme.purple.normal}
face global attribute keyword face global attribute keyword
@ -116,52 +108,50 @@ let nix-config = (lib.optionalString nix ''
face global value string face global value string
face global meta rgb:${theme.pink.normal} face global meta rgb:${theme.pink.normal}
} }
''); '');
# Rust development. Rust's language servers all support the # Rust development. Rust's language servers all support the
# `ide-full` features. # `ide-full` features.
rust-config = (lib.optionalString rust '' rust-config = (lib.optionalString rust ''
hook global WinSetOption filetype=rust %{ hook global WinSetOption filetype=rust %{
${ide-full} ${ide-full}
hook global -group yeet ModuleLoaded rust %{ hook global -group yeet ModuleLoaded rust %{
# Override the Rust highlighting with semantic # Override the Rust highlighting with semantic
# tokens supplied by the LSP client # tokens supplied by the LSP client
remove-hooks global rust-highlight remove-hooks global rust-highlight
remove-highlighter shared/rust remove-highlighter shared/rust
# Request tokens # Request tokens
lsp-semantic-tokens lsp-semantic-tokens
# Self-destruct this hook (it should only run once)
remove-hooks global yeet
} # Self-destruct this hook (it should only run once)
remove-hooks global yeet
} }
}
''); '');
in pkgs.writeTextFile (rec { in pkgs.writeTextFile (rec {
name = "kakrc.kak"; name = "kakrc.kak";
destination = "/share/kak/autoload/${name}"; destination = "/share/kak/autoload/${name}";
text = '' text = ''
colorscheme colors;
set global tabstop 4
colorscheme colors; add-highlighter global/ number-lines -separator ' ' -hlcursor
add-highlighter global/ number-lines -separator ' ' -hlcursor
set global tabstop 4 face global InlayHint rgb:828282
face global InlayDiagnosticWarning rgb:a39e31+f
face global InlayDiagnosticError rgb:ad494f+f
face global InlayDiagnosticHint rgb:4d965a+f
face global InlayDiagnosticInfo rgb:4d965a+f
face global InlayHint rgb:828282 ${keybinds}
face global InlayDiagnosticWarning rgb:a39e31+f
face global InlayDiagnosticError rgb:ad494f+f
face global InlayDiagnosticHint rgb:4d965a+f
face global InlayDiagnosticInfo rgb:4d965a+f
${keybinds}
${typescript-config} ${typescript-config}
${haskell-config} ${haskell-config}
@ -169,8 +159,6 @@ in pkgs.writeTextFile (rec {
${rust-config} ${rust-config}
${nix-config} ${nix-config}
hook global KakBegin .* %{ hook global KakBegin .* %{ cursorline }
cursorline
}
''; '';
}) })