[user/malte] Rework kak-lsp and kakoune settings

This commit is contained in:
Malte Tammena 2022-04-14 08:24:36 +02:00
parent 4d504e7c45
commit 4c2c54c308

View file

@ -5,6 +5,7 @@
...
}: let
# Configuration for kakoune plugins
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
pluginConfigs = with pkgs.kakounePlugins; [
{
# FZF for kakoune
@ -82,6 +83,8 @@
}
];
# Additional mappings for kakoune
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
additionalMappings = [
{
# Switch to last buffer
@ -90,23 +93,172 @@
key = ",";
effect = ":buffer-previous<ret>";
}
{
# Toggle whitespace highlighter
docstring = "Toggle whitespace";
mode = "user";
key = "w";
effect = ":togglewhitespace<ret>";
}
];
# Additional configuration for kakoune
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
additionalConfig = ''
add-highlighter global/ number-lines -relative
add-highlighter global/ wrap -word -indent
add-highlighter global/ regex '\h*(//|#|;|%)\h*(TODO:|FIXME:)([^\n]*)' 2:black,bright-red+Fb 3:default+b
# Highlighter for headers in the nix config
add-highlighter global/ regex '^\h*#\h*([^\n]+)\n\h*#\h*(‾+)$' 1:bright-yellow+bf 2:yellow+bf
face global PrimarySelection rgba:ebdbb2a0,rgba:8ec07c40
face global SecondarySelection rgba:ebdbb2a0,rgba:83a59840
face global MatchingChar rgb:ebdbb2,rgb:3c3836+bf
face global Reference rgb:3c3836
# Do something about tabs..
map global insert <tab> ' '
hook global BufSetOption filetype=nix %{
map buffer insert <tab> ' '
}
set-option global tabstop 4
# Toggle whitespaces!
declare-option -docstring "Whether whitespaces are visible" bool whitespacesshown
define-command -docstring "Toggle whitespace highlighter" togglewhitespace %{
execute-keys %sh{
if [ $kak_opt_whitespacesshown = "true" ]; then
printf ':remove-highlighter buffer/whitespace<ret>'
printf ':set-option buffer whitespacesshown false<ret>'
else
printf ':add-highlighter buffer/whitespace show-whitespaces<ret>'
printf ':set-option buffer whitespacesshown true<ret>'
fi
}
}
'';
# Configuration for kakoune LSP
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
kakLspConfigGen = pkgs.formats.toml {};
kakLspConfig = {
language = {
javascript = {
args = ["lsp"];
command = "${pkgs.flow}/bin/flow";
filetypes = ["javascript"];
roots = [".flowconfig"];
};
latex = {
command = "${pkgs.texlab}/bin/texlab";
filetypes = ["latex"];
roots = [".git" ".hg"];
settings = {
texlab = {
forwardSearch = {
args = [
"%p"
"--synctex-forward"
"%l:1:%f"
"--synctex-editor-command"
''
sh -c '
echo "
evaluate-commands -client $kak_client %{
evaluate-commands -try-client %opt{jumpclient} %{
edit -- %{input} %{line}
}
}
" | kak -p $kak_session
'
''
];
executable = "${pkgs.zathura}/bin/zathura";
};
};
};
settings_section = "texlab";
};
nix = {
command = "${pkgs.rnix-lsp}/bin/rnix-lsp";
filetypes = ["nix"];
roots = ["flake.nix" "shell.nix" ".git" ".hg"];
};
python = {
command = "${pkgs.python3.pkgs.python-lsp-server}/bin/pylsp";
filetypes = ["python"];
roots = ["requirements.txt" "setup.py" ".git" ".hg"];
settings.pylsp.pylsp.configurationSources = ["flake8"];
settings_section = "pylsp";
};
rust = {
command = "${pkgs.rust-analyzer}/bin/rust-analyzer";
filetypes = ["rust"];
roots = ["Cargo.toml"];
settings = {
rust-analyzer = {
cargo = {loadOutDirsFromCheck = true;};
hoverActions = {enable = true;};
procMacro = {enable = true;};
};
};
settings_section = "rust-analyzer";
};
typescript = {
args = ["--stdio" "--tsserver-path=${pkgs.nodePackages.typescript}/lib/node_modules/typescript/lib"];
command = "${pkgs.nodePackages.typescript-language-server}/bin/typescript-language-server";
filetypes = ["typescript"];
roots = ["package.json" "tsconfig.json" ".git" ".hg"];
};
vuejs = {
args = ["--stdio"];
command = "${pkgs.nodePackages.vls}/bin/vls";
filetypes = ["vuejs"];
roots = ["package.json" "tsconfig.json" ".git" ".hg"];
};
};
semantic_tokens = let
mkToken = {
token,
face ? null,
modifiers ? [],
}: {
inherit token modifiers;
face =
if face != null
then face
else token;
};
in [
(mkToken {token = "comment";})
(mkToken {token = "function";})
(mkToken {token = "keyword";})
(mkToken {token = "operator";})
(mkToken {token = "string";})
(mkToken {token = "type";})
(mkToken {token = "variable";})
{
face = "module";
token = "namespace";
}
{
face = "documentation";
modifiers = ["documentation"];
token = "comment";
}
{
face = "default+d";
modifiers = ["readonly"];
token = "variable";
}
{
face = "default+d";
modifiers = ["constant"];
token = "variable";
}
];
};
selectOr = attr: default: map (conf: conf.${attr} or default) pluginConfigs;
selectList = attr: lib.flatten (selectOr attr []);
in {
@ -129,149 +281,10 @@ in {
plugins = map (conf: conf.pkg) pluginConfigs;
};
home.packages = with pkgs; [
# For Nix
rnix-lsp
# For Rust
rust-analyzer-nightly
# For Python
python3.pkgs.python-lsp-server
# For TypeScript
nodePackages.typescript
nodePackages.typescript-language-server
# For JavaScript
flow
];
xdg.configFile."kak-lsp/kak-lsp.toml".text = ''
[language.rust]
filetypes = ["rust"]
roots = ["Cargo.toml"]
command = "${pkgs.rust-analyzer-nightly}/bin/rust-analyzer"
settings_section = "rust-analyzer"
[language.rust.settings.rust-analyzer]
hoverActions.enable = true # kak-lsp doesn't support this at the moment
procMacro.enable = true
cargo.loadOutDirsFromCheck = true
[language.nix]
filetypes = ["nix"]
roots = ["flake.nix", "shell.nix", ".git", ".hg"]
command = "${pkgs.rnix-lsp}/bin/rnix-lsp"
[language.python]
filetypes = ["python"]
roots = ["requirements.txt", "setup.py", ".git", ".hg"]
command = "${pkgs.python3.pkgs.python-lsp-server}/bin/pylsp"
settings_section = "pylsp"
[language.python.settings.pylsp]
pylsp.configurationSources = ["flake8"]
[language.latex]
filetypes = ["latex"]
roots = [".git", ".hg"]
command = "${pkgs.texlab}/bin/texlab"
settings_section = "texlab"
[language.latex.settings.texlab]
# See https://github.com/latex-lsp/texlab/blob/master/docs/options.md
#
# Preview configuration for zathura with SyncTeX search.
# For other PDF viewers see https://github.com/latex-lsp/texlab/blob/master/docs/previewing.md
forwardSearch.executable = "${pkgs.zathura}/bin/zathura"
forwardSearch.args = [
"%p",
"--synctex-forward", # Support texlab-forward-search
"%l:1:%f",
"--synctex-editor-command", # use Control+Left-Mouse-Button to jump to source.
"""
sh -c '
echo "
evaluate-commands -client $kak_client %{
evaluate-commands -try-client %opt{jumpclient} %{
edit -- %{input} %{line}
}
}
" | kak -p $kak_session
'
""",
]
[language.typescript]
filetypes = ["typescript"]
roots = ["package.json", "tsconfig.json", ".git", ".hg"]
command = "${pkgs.nodePackages.typescript-language-server}/bin/typescript-language-server"
args = [
"--stdio",
"--tsserver-path=${pkgs.nodePackages.typescript}/lib/node_modules/typescript/lib"
]
[language.javascript]
filetypes = ["javascript"]
roots = [".flowconfig"]
command = "${pkgs.flow}/bin/flow"
args = ["lsp"]
[language.vuejs]
filetypes = ["vuejs"]
roots = ["package.json", "tsconfig.json", ".git", ".hg"]
command = "${pkgs.nodePackages.vls}/bin/vls"
args = [
"--stdio"
]
# Semantic tokens support
[[semantic_tokens]]
token = "comment"
face = "documentation"
modifiers = ["documentation"]
[[semantic_tokens]]
token = "comment"
face = "comment"
[[semantic_tokens]]
token = "function"
face = "function"
[[semantic_tokens]]
token = "keyword"
face = "keyword"
[[semantic_tokens]]
token = "namespace"
face = "module"
[[semantic_tokens]]
token = "operator"
face = "operator"
[[semantic_tokens]]
token = "string"
face = "string"
[[semantic_tokens]]
token = "type"
face = "type"
[[semantic_tokens]]
token = "variable"
face = "default+d"
modifiers = ["readonly"]
[[semantic_tokens]]
token = "variable"
face = "default+d"
modifiers = ["constant"]
[[semantic_tokens]]
token = "variable"
face = "variable"
'';
home.sessionVariables = {
EDITOR = "${pkgs.kakoune}/bin/kak";
VISUAL = "${pkgs.kitty}/bin/kitty ${pkgs.kakoune}/bin/kak";
};
xdg.configFile."kak-lsp/kak-lsp.toml".source = kakLspConfigGen.generate "kak-lsp.toml" kakLspConfig;
}