config/modules/kak/kakrc.nix

169 lines
4.1 KiB
Nix
Raw Normal View History

2022-05-15 23:32:21 +02:00
# Defines the kakrc.
{
# Feature flags
typescript ? false,
haskell ? false,
python ? false,
rust ? false,
nix ? true,
# Color theme
theme,
# Build tools
pkgs,
lib,
}:
2022-05-16 17:44:49 +02:00
let keybinds = ''
map global insert <a-tab> <esc>:buffer-next<ret>
map global normal <a-tab> :buffer-next<ret>
'';
# Initialization code for IDE mode needed for every supported
# language.
ide-init = ''
eval %sh{ kak-lsp --kakoune -s $kak_session }
lsp-enable-window
'';
# Implies `ide-init`. Adds inlay diagnostics support, code actions
# and hover.
ide-core = ''
${ide-init}
2022-05-15 23:32:21 +02:00
2022-05-16 17:44:49 +02:00
lsp-inlay-diagnostics-enable window
hook window ModeChange .*:.*:insert %{
remove-highlighter window/lsp_diagnostics
}
hook window ModeChange .*:insert:normal %{
lsp-inlay-diagnostics-enable window
}
map buffer normal <tab> ': lsp-code-actions<ret>'
map buffer normal <ret> ': lsp-hover<ret>'
2022-05-15 23:32:21 +02:00
'';
2022-05-16 17:44:49 +02:00
# Implies `ide-core`, which implies `ide-init`.
ide-full = ''
${ide-core}
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
}
map global normal <a-down> ': lsp-next-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-right> ': lsp-next-location *goto*<ret>'
''; in
# Nix hacking-related configuration. Nix has a very weak language
# server, and it basically only supports `ide-init` (for completions).
let nix-config = (lib.optionalString nix ''
hook global WinSetOption filetype=nix %{
${ide-init}
}
'');
2022-05-15 23:32:21 +02:00
2022-05-16 17:44:49 +02:00
# Sometimes work requires me to touch the frontend. Ew. `ide-core`
# suffices here.
typescript-config = (lib.optionalString typescript ''
hook global WinSetOption filetype=(javascript|typescript) %{
${ide-core}
}
2022-05-15 23:32:21 +02:00
'');
2022-05-16 17:44:49 +02:00
# Python-related config. Python does not support more features than
# those in `ide-core`.
python-config = (lib.optionalString python ''
hook global WinSetOption filetype=python %{
${ide-core}
2022-05-15 23:32:21 +02:00
2022-05-16 17:44:49 +02:00
face window keyword rgb:${green.bright}
face window meta keyword
}
2022-05-15 23:32:21 +02:00
'');
2022-05-16 17:44:49 +02:00
# Haskell development. Haskell has a language server with
# the features in `ide-full`.
2022-05-15 23:32:21 +02:00
haskell-config = (lib.optionalString haskell ''
2022-05-16 17:44:49 +02:00
hook global WinSetOption filetype=haskell %{
2022-05-15 23:32:21 +02:00
2022-05-16 17:44:49 +02:00
${ide-full}
set-option buffer tabstop 2
2022-05-15 23:32:21 +02:00
2022-05-16 17:44:49 +02:00
face global variable rgb:${purple.normal}
face global attribute keyword
face global operator keyword
face global keyword rgb:${blue.bright}
face global value string
face global meta rgb:${pink.normal}
2022-05-15 23:32:21 +02:00
2022-05-16 17:44:49 +02:00
}
2022-05-15 23:32:21 +02:00
'');
2022-05-16 17:44:49 +02:00
# Rust development. Rust's language servers all support the
# `ide-full` features.
2022-05-15 23:32:21 +02:00
rust-config = (lib.optionalString rust ''
2022-05-16 17:44:49 +02:00
hook global WinSetOption filetype=rust %{
2022-05-15 23:32:21 +02:00
2022-05-16 17:44:49 +02:00
${ide-full}
hook global -group yeet ModuleLoaded rust %{
2022-05-15 23:32:21 +02:00
2022-05-16 17:44:49 +02:00
# Override the Rust highlighting with semantic
# tokens supplied by the LSP client
remove-hooks global rust-highlight
remove-highlighter shared/rust
2022-05-15 23:32:21 +02:00
2022-05-16 17:44:49 +02:00
# Request tokens
lsp-semantic-tokens
# Self-destruct this hook (it should only run once)
remove-hooks global yeet
}
}
2022-05-15 23:32:21 +02:00
'');
in pkgs.writeTextFile (rec {
name = "kakrc.kak";
destination = "/share/kak/autoload/${name}";
text = with theme; ''
2022-05-16 17:44:49 +02:00
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
2022-05-15 23:32:21 +02:00
'' ++ keybinds
++ typescript-config
++ haskell-config
++ python-config
++ rust-config
++ nix-config;
})