config/modules/kak/kak-lsp.nix

133 lines
4.1 KiB
Nix
Raw Normal View History

2022-05-16 17:44:49 +02:00
{
# Feature flags
typescript ? false,
haskell ? false,
2022-06-22 16:51:02 +02:00
clojure ? false,
2022-05-16 17:44:49 +02:00
python ? false,
rust ? false,
nix ? true,
# Build context
pkgs,
lib
}:
with lib;
with pkgs;
let semantic-tokens =
2022-05-23 13:17:26 +02:00
let mk = (name: value: ''
[[semantic_tokens]]
token = "${name}"
face = "${value}"
''); in concatStringsSep "\n" (mapAttrsToList mk {
"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";
2022-06-18 10:00:51 +02:00
"macroBang" = "macro";
2022-05-23 13:17:26 +02:00
"lifetime" = "lifetime";
"variable" = "variable";
"attribute" = "attribute";
"punctuation" = "punctuation";
});
2022-05-16 17:44:49 +02:00
2022-05-23 13:17:26 +02:00
kak-lsp-config-text = concatStringsSep "\n" (
2022-06-22 16:51:02 +02:00
(optional (rust || haskell || clojure) semantic-tokens)
2022-05-19 19:58:26 +02:00
++ (optional rust ''
2022-05-23 13:17:26 +02:00
[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
'')
++ (optional nix ''
2022-05-16 17:44:49 +02:00
[language.nix]
filetypes = [ "nix" ]
roots = [ "flake.nix", "shell.nix", ".git", ".hg" ]
command = "rnix-lsp"
2022-05-23 13:17:26 +02:00
'')
++ (optional haskell ''
2022-05-16 17:44:49 +02:00
[language.haskell]
filetypes = [ "haskell" ]
roots = [ "Setup.hs", "stack.yaml", "*.cabal" ]
command = "haskell-language-server-wrapper"
args = [ "--lsp" ]
2022-05-23 13:17:26 +02:00
'')
2022-06-22 16:51:02 +02:00
++ (optional clojure ''
[language.clojure]
filetypes = ["clojure"]
roots = ["project.clj", "deps.edn", ".lsp/config.edn", ".git/"]
command = "clojure-lsp"
'')
2022-05-23 13:17:26 +02:00
++ (optional python ''
2022-05-16 17:44:49 +02:00
[language.python]
filetypes = [ "python" ]
roots = [ "setup.py", ".git", ".hg" ]
command = "pylsp"
2022-05-23 13:17:26 +02:00
'')
++ (optional typescript ''
2022-05-16 17:44:49 +02:00
[language.typescript]
filetypes = ["typescript", "javascript"]
roots = ["package.json"]
command = "rslint-lsp"
2022-05-23 13:17:26 +02:00
''));
2022-05-16 17:44:49 +02:00
2022-05-23 13:17:26 +02:00
kak-lsp-config = (pkgs.writeTextFile (rec {
name = "kak-lsp.toml";
destination = "/share/kak-lsp/${name}";
text = kak-lsp-config-text;
}));
2022-05-16 17:44:49 +02:00
in (symlinkJoin {
2022-05-23 13:17:26 +02:00
name = "kak-lsp-${kak-lsp.version}";
nativeBuildInputs = [ makeWrapper ];
paths = with kakounePlugins; [
2022-05-16 17:44:49 +02:00
2022-05-23 13:17:26 +02:00
# The language server client
kak-lsp
2022-05-16 17:44:49 +02:00
2022-05-23 13:17:26 +02:00
# Overwrite kak-lsp.toml
kak-lsp-config
2022-05-16 17:44:49 +02:00
] ++ (optional nix rnix-lsp)
++ (optional typescript rslint)
++ (optional haskell haskell-language-server)
2022-06-22 16:51:02 +02:00
++ (optional clojure clojure-lsp)
2022-05-16 17:44:49 +02:00
++ (optional python python39Packages.python-lsp-server)
++ (optional rust rust-analyzer);
2022-05-23 13:17:26 +02:00
postBuild = ''
wrapProgram $out/bin/kak-lsp --add-flags "--config $out/share/kak-lsp/kak-lsp.toml"
'';
2022-05-16 17:44:49 +02:00
})