Turn kak-lsp configuration into module

This commit is contained in:
Natsu Kagami 2021-11-09 15:59:22 -05:00
parent a6bf01e8ee
commit e1f37a8e30
Signed by: nki
GPG key ID: 7306B3D3C3AD6E51
3 changed files with 272 additions and 188 deletions

View file

@ -1,5 +1,6 @@
{ config, pkgs, lib, ... }: { config, pkgs, lib, ... }:
with lib;
let let
rev = "3586feab17000f6ef526b2f9f6a11e008512b3e8"; rev = "3586feab17000f6ef526b2f9f6a11e008512b3e8";
version = "r${builtins.substring 0 6 rev}"; version = "r${builtins.substring 0 6 rev}";
@ -24,13 +25,258 @@ let
); );
}); });
}); });
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" ];
};
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" ];
roots = [ ".git" ];
settings_section = "texlab";
settings.texlab.build = {
args = [ "%f" "--synctex" "--keep-logs" "--keep-intermediates" "-Zsearch-path=${config.home.homeDirectory}/texmf" "-Zshell-escape" ];
executable = "tectonic";
};
};
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" ];
};
};
semantic_scopes = {
entity_name_function = "function";
entity_name_namespace = "module";
entity_name_type = "type";
variable = "variable";
variable_other_enummember = "variable";
};
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;
in in
{ {
options.programs.kak-lsp = {
enable = mkEnableOption "Enable kak-lsp support";
package = mkOption {
type = types.derivation;
default = kak-lsp;
};
enableSnippets = mkOption {
type = types.bool;
default = false;
description = "Enable snippet support";
};
semanticScopes = mkOption {
type = types.attrsOf types.str;
default = lspConfig.semantic_scopes;
description = "The semantic scopes mapping given to kak";
};
serverTimeout = mkOption {
type = types.int;
default = 1000;
description = "Server timeout";
};
languages = mkOption {
type = types.attrsOf languageOption;
default = lspConfig.language;
description = "The language options";
};
};
config = mkIf cfg.enable {
home.packages = [ kak-lsp ]; home.packages = [ kak-lsp ];
# Configurations # Configurations
home.file."kakoune/kak-lsp.toml" = { xdg.configFile."kak-lsp/kak-lsp.toml" = {
source = ./. + "/kak-lsp.toml"; source = pkgs.runCommand "config.toml"
target = ".config/kak-lsp/kak-lsp.toml"; {
buildInputs = [ pkgs.yj ];
preferLocalBuild = true;
} ''
yj -jt -i \
< ${
pkgs.writeText "config.json" (builtins.toJSON {
semantic_scopes = cfg.semanticScopes;
server.timeout = cfg.serverTimeout;
snippet_support = cfg.enableSnippets;
verbosity = 255;
language = cfg.languages;
})
} \
> $out
'';
}; };
};
} }

View file

@ -1,165 +0,0 @@
snippet_support = false
verbosity = 255
[semantic_scopes]
# Map textmate scopes to kakoune faces for semantic highlighting
# the underscores are translated to dots, and indicate nesting.
# That is, if variable_other_field is omitted, it will try the face for
# variable_other and then variable
#
# To see a list of available scopes in the debug buffer, run lsp-semantic-available-scopes
variable="variable"
entity_name_function="function"
entity_name_type="type"
variable_other_enummember="variable"
entity_name_namespace="module"
[server]
# exit session if no requests were received during given period in seconds
# works only in unix sockets mode (-s/--session)
# set to 0 to disable
timeout = 1800 # seconds = 30 minutes
[language.rust]
filetypes = ["rust"]
roots = ["Cargo.toml"]
command = "rust-analyzer"
args = []
[language.crystal]
filetypes = ["crystal"]
roots = ["shard.yml"]
command = "scry"
[language.javascript]
filetypes = ["javascript"]
roots = [".flowconfig"]
command = "flow"
args = ["lsp"]
[language.json]
filetypes = ["json"]
roots = ["package.json"]
command = "json-languageserver"
args = ["--stdio"]
[language.css]
filetypes = ["css"]
roots = ["package.json"]
command = "css-languageserver"
args = ["--stdio"]
[language.html]
filetypes = ["html"]
roots = ["package.json"]
command = "html-languageserver"
args = ["--stdio"]
[language.ocaml]
filetypes = ["ocaml"]
roots = ["Makefile", "opam", "*.opam", "dune", ".merlin", ".ocamlformat"]
command = "ocamllsp"
args = []
[language.reason]
filetypes = ["reason"]
roots = ["package.json", "Makefile", ".git", ".hg"]
command = "ocaml-language-server"
args = ["--stdio"]
[language.ruby]
filetypes = ["ruby"]
roots = ["Gemfile"]
command = "solargraph"
args = ["stdio"]
[language.python]
filetypes = ["python"]
roots = ["requirements.txt", "setup.py", ".git", ".hg"]
command = "pyls"
offset_encoding = "utf-8"
[language.c_cpp]
filetypes = ["c", "cpp"]
roots = ["compile_commands.json", ".cquery", ".git"]
command = "ccls"
args = ["-v=2", "-log-file=/tmp/ccls.log"]
[language.haskell]
filetypes = ["haskell"]
roots = ["Setup.hs", "stack.yaml", "*.cabal"]
command = "haskell-language-server-wrapper"
args = ["--lsp"]
[language.go]
filetypes = ["go"]
roots = ["Gopkg.toml", "go.mod", ".git", ".hg"]
command = "gopls"
offset_encoding = "utf-8"
settings_section = "gopls"
[language.go.settings.gopls]
semanticTokens = true
hoverKind = "SynopsisDocumentation"
[language.bash]
filetypes = ["sh"]
roots = [".git", ".hg"]
command = "bash-language-server"
args = ["start"]
[language.dart]
filetypes = ["dart"]
roots = ["pubspec.yaml", ".git"]
command = "dart_language_server"
[language.d]
filetypes = ["d", "di"]
roots = [".git", "dub.sdl", "dub.json"]
command = "dls"
[language.php]
filetypes = ["php"]
roots = [".htaccess", "composer.json"]
command = "intelephense"
args = ["--stdio"]
[language.nim]
filetypes = ["nim"]
roots = ["*.nimble", ".git"]
command = "nimlsp"
[language.elm]
filetypes = ["elm"]
roots = ["elm.json"]
command = "elm-language-server"
args = ["--stdio"]
# [language.elm.initialization_options]
# runtime = "node"
# elmPath = "elm"
# elmFormatPath = "elm-format"
# elmTestPath = "elm-test"
[language.latex]
filetypes = ["latex"]
roots = [".git"]
command = "texlab"
[language.racket]
filetypes = ["racket"]
roots = [".git"]
command = "racket"
args = ["-l", "racket-langserver"]
[language.fsharp]
filetypes = ["fsharp"]
roots = [".git", "*.fsx"]
command = "FSharpLanguageServer"
# command = "dotnet"
# args = ["/home/natsukagami/Projects/FsAutoComplete/bin/release_netcore/fsautocomplete.dll", "--background-service-enabled"]
[language.nix]
filetypes = ["nix"]
roots = ["flake.nix", "shell.nix", ".git"]
command = "rnix-lsp"

View file

@ -40,6 +40,9 @@ in
# Enable the kakoune package. # Enable the kakoune package.
home.packages = [ kakounePkg ]; home.packages = [ kakounePkg ];
# Enable kak-lsp
programs.kak-lsp.enable = true;
# Source the kakrc we have here. # Source the kakrc we have here.
home.file = builtins.listToAttrs (map kakouneFile [ home.file = builtins.listToAttrs (map kakouneFile [
"kakrc" "kakrc"