nix-home/home/modules/programs/my-kakoune/kak-lsp.nix

289 lines
8.6 KiB
Nix
Raw Normal View History

2021-09-30 19:31:57 +00:00
{ config, pkgs, lib, ... }:
2021-11-09 20:59:22 +00:00
with lib;
2021-09-30 19:31:57 +00:00
let
2021-11-09 20:59:22 +00:00
lspConfig =
{
language = {
bash = {
args = [ "start" ];
command = "bash-language-server";
filetypes = [ "sh" ];
roots = [ ".git" ".hg" ];
};
c_cpp = {
args = [ "-v=2" "-log-file=/tmp/ccls.log" ];
command = "ccls";
filetypes = [ "c" "cpp" ];
roots = [ "compile_commands.json" ".cquery" ".git" ];
};
crystal = {
command = "scry";
filetypes = [ "crystal" ];
roots = [ "shard.yml" ];
};
css = {
args = [ "--stdio" ];
command = "css-languageserver";
filetypes = [ "css" ];
roots = [ "package.json" ];
};
d = {
command = "dls";
filetypes = [ "d" "di" ];
roots = [ ".git" "dub.sdl" "dub.json" ];
};
dart = {
command = "dart_language_server";
filetypes = [ "dart" ];
roots = [ "pubspec.yaml" ".git" ];
};
elm = {
args = [ "--stdio" ];
command = "elm-language-server";
filetypes = [ "elm" ];
roots = [ "elm.json" ];
};
fsharp = {
command = "FSharpLanguageServer";
filetypes = [ "fsharp" ];
roots = [ ".git" "*.fsx" ];
};
go = {
command = "gopls";
filetypes = [ "go" ];
offset_encoding = "utf-8";
roots = [ "Gopkg.toml" "go.mod" ".git" ".hg" ];
settings = { gopls = { hoverKind = "SynopsisDocumentation"; semanticTokens = true; }; };
settings_section = "gopls";
};
haskell = {
args = [ "--lsp" ];
command = "haskell-language-server-wrapper";
filetypes = [ "haskell" ];
roots = [ "Setup.hs" "stack.yaml" "*.cabal" "package.yaml" ];
settings_section = "haskell";
2021-11-09 20:59:22 +00:00
};
html = {
args = [ "--stdio" ];
command = "html-languageserver";
filetypes = [ "html" ];
roots = [ "package.json" ];
};
javascript = {
args = [ "lsp" ];
command = "flow";
filetypes = [ "javascript" ];
roots = [ ".flowconfig" ];
};
json = {
args = [ "--stdio" ];
command = "json-languageserver";
filetypes = [ "json" ];
roots = [ "package.json" ];
};
latex = {
command = "texlab";
filetypes = [ "latex" ];
2022-01-11 19:11:40 +00:00
roots = [ ".git" "main.tex" "all.tex" ];
2022-01-11 20:17:47 +00:00
settings_section = "texlab";
settings.texlab = {
build.executable = "latexmk";
build.args = [ "-pdf" "-shell-escape" "-interaction=nonstopmode" "-synctex=1" "%f" ];
build.forwardSearchAfter = true;
build.onSave = true;
forwardSearch = {
executable = "/Applications/Skim.app/Contents/SharedSupport/displayline";
args = [ "-r" "-g" "%l" "%p" "%f" ];
};
};
2021-11-09 20:59:22 +00:00
};
nim = {
command = "nimlsp";
filetypes = [ "nim" ];
roots = [ "*.nimble" ".git" ];
};
nix = {
command = "rnix-lsp";
filetypes = [ "nix" ];
roots = [ "flake.nix" "shell.nix" ".git" ];
};
ocaml = {
args = [ ];
command = "ocamllsp";
filetypes = [ "ocaml" ];
roots = [ "Makefile" "opam" "*.opam" "dune" ".merlin" ".ocamlformat" ];
};
php = {
args = [ "--stdio" ];
command = "intelephense";
filetypes = [ "php" ];
roots = [ ".htaccess" "composer.json" ];
};
python = {
command = "pyls";
filetypes = [ "python" ];
offset_encoding = "utf-8";
roots = [ "requirements.txt" "setup.py" ".git" ".hg" ];
};
racket = {
args = [ "-l" "racket-langserver" ];
command = "racket";
filetypes = [ "racket" ];
roots = [ ".git" ];
};
reason = {
args = [ "--stdio" ];
command = "ocaml-language-server";
filetypes = [ "reason" ];
roots = [ "package.json" "Makefile" ".git" ".hg" ];
};
ruby = {
args = [ "stdio" ];
command = "solargraph";
filetypes = [ "ruby" ];
roots = [ "Gemfile" ];
};
rust = {
args = [ ];
command = "rust-analyzer";
filetypes = [ "rust" ];
roots = [ "Cargo.toml" ];
};
};
2022-05-06 17:40:27 +00:00
semantic_tokens.faces = [
## Items
# (Rust) Macros
{ face = "attribute"; token = "attribute"; }
{ face = "attribute"; token = "derive"; }
{ face = "macro"; token = "macro"; } # Function-like Macro
# Keyword and Fixed Tokens
{ face = "keyword"; token = "keyword"; }
{ face = "operator"; token = "operator"; }
# Functions and Methods
{ face = "function"; token = "function"; }
{ face = "method"; token = "method"; }
# Constants
{ face = "string"; token = "string"; }
{ face = "format_specifier"; token = "formatSpecifier"; }
# Variables
{ face = "mutable_variable"; token = "variable"; modifiers = [ "mutable" ]; }
{ face = "variable"; token = "variable"; }
{ face = "module"; token = "namespace"; }
{ face = "variable"; token = "type_parameter"; }
{ face = "class"; token = "enum"; }
{ face = "class"; token = "struct"; }
{ face = "class"; token = "trait"; }
{ face = "class"; token = "union"; }
2023-04-11 09:50:17 +00:00
{ face = "class"; token = "class"; }
2022-05-06 17:40:27 +00:00
## Comments
{ face = "documentation"; token = "comment"; modifiers = [ "documentation" ]; }
{ face = "comment"; token = "comment"; }
];
2021-11-09 20:59:22 +00:00
server = { timeout = 1800; };
snippet_support = false;
verbosity = 255;
};
languageOption = types.submodule {
options = {
filetypes = mkOption {
type = types.listOf types.str;
description = "The list of filetypes to assign the language to";
};
roots = mkOption {
type = types.listOf types.str;
description = "The list of root filenames that are used to determine the project root";
};
command = mkOption {
type = types.str;
description = "The LSP server command to be called.";
};
args = mkOption {
type = types.listOf types.str;
default = [ ];
description = "The arguments passed onto the LSP server.";
};
offset_encoding = mkOption {
type = types.nullOr (types.enum [ "utf-8" ]);
default = null;
description = "The offset encoding used by the LSP server.";
};
settings_section = mkOption {
type = types.nullOr types.str;
default = null;
description = "The settings section to be sent to LSP server.";
};
settings = mkOption {
type = types.nullOr (types.attrsOf types.anything);
default = null;
description = "Additional settings to be passed to the LSP server.";
};
};
};
cfg = config.programs.kak-lsp;
2021-09-30 19:31:57 +00:00
in
{
2021-11-09 20:59:22 +00:00
options.programs.kak-lsp = {
enable = mkEnableOption "Enable kak-lsp support";
package = mkOption {
2022-01-12 20:55:53 +00:00
type = types.package;
default = pkgs.kak-lsp;
2021-11-09 20:59:22 +00:00
};
enableSnippets = mkOption {
type = types.bool;
default = false;
description = "Enable snippet support";
};
2022-05-06 17:40:27 +00:00
semanticTokens.faces = mkOption {
type = types.listOf types.anything;
default = lspConfig.semantic_tokens.faces;
description = "The semantic tokens faces mapping given to kak";
2021-11-09 20:59:22 +00:00
};
serverTimeout = mkOption {
type = types.int;
default = 1000;
description = "Server timeout";
};
languages = mkOption {
type = types.attrsOf languageOption;
2022-02-25 19:45:06 +00:00
default = { };
2021-11-09 20:59:22 +00:00
description = "The language options";
};
};
config = mkIf cfg.enable {
2022-01-12 20:55:53 +00:00
home.packages = [ cfg.package ];
2021-09-30 19:31:57 +00:00
# Configurations
2021-11-09 20:59:22 +00:00
xdg.configFile."kak-lsp/kak-lsp.toml" = {
source = pkgs.runCommand "config.toml"
{
buildInputs = [ pkgs.yj ];
preferLocalBuild = true;
} ''
yj -jt -i \
< ${
pkgs.writeText "config.json" (builtins.toJSON {
2022-05-06 17:40:27 +00:00
semantic_tokens.faces = cfg.semanticTokens.faces;
2021-11-09 20:59:22 +00:00
server.timeout = cfg.serverTimeout;
snippet_support = cfg.enableSnippets;
verbosity = 255;
2022-02-09 20:21:25 +00:00
language = lspConfig.language // cfg.languages;
2021-11-09 20:59:22 +00:00
})
} \
> $out
'';
2021-09-30 19:31:57 +00:00
};
2021-11-09 20:59:22 +00:00
};
2021-09-30 19:31:57 +00:00
}