lsp: added packageoption to basic lsp servers (#61)

* nvim-lsp: added package options for basic servers

* nvim-lsp: updated package options

* nvim-lsp: added cmd to plugins that share dependency
This commit is contained in:
Alexander Nortung 2023-01-19 10:36:56 +00:00 committed by GitHub
parent 50bda39cd2
commit 2180675750
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 35 deletions

View file

@ -6,22 +6,23 @@ let
{
name = "bashls";
description = "Enable bashls, for bash.";
packages = [ pkgs.nodePackages.bash-language-server ];
package = pkgs.nodePackages.bash-language-server;
}
{
name = "clangd";
description = "Enable clangd LSP, for C/C++.";
packages = [ pkgs.clang-tools ];
package = pkgs.clang-tools;
}
{
name = "cssls";
description = "Enable cssls, for CSS";
packages = [ pkgs.nodePackages.vscode-langservers-extracted ];
package = pkgs.nodePackages.vscode-langservers-extracted;
cmd = cfg: [ "${cfg.package}/bin/vscode-css-language-server" "--stdio" ];
}
{
name = "dartls";
description = "Enable dart language-server, for dart";
packages = [ pkgs.dart ];
package = pkgs.dart;
extraOptions = {
analysisExcludedFolders = mkOption {
type = types.nullOr (types.listOf types.str);
@ -112,23 +113,24 @@ let
{
name = "denols";
description = "Enable denols, for Deno";
packages = [ pkgs.deno ];
package = pkgs.deno;
}
{
name = "eslint";
description = "Enable eslint";
packages = [ pkgs.nodePackages.vscode-langservers-extracted ];
package = pkgs.nodePackages.vscode-langservers-extracted;
cmd = cfg: [ "${cfg.package}/bin/vscode-eslint-langauge-server" "--stdio" ];
}
{
name = "elixirls";
description = "Enable elixirls";
packages = [ ];
cmd = [ "${pkgs.elixir_ls}/bin/elixir-ls" ];
package = pkgs.elixir_ls;
cmd = cfg: ["${cfg.package}/bin/elixir-ls"];
}
{
name = "gdscript";
description = "Enable gdscript, for Godot";
packages = [ ];
package = null;
}
{
name = "gopls";
@ -137,17 +139,19 @@ let
{
name = "html";
description = "Enable html, for HTML";
packages = [ pkgs.nodePackages.vscode-langservers-extracted ];
package = pkgs.nodePackages.vscode-langservers-extracted;
cmd = cfg: [ "${cfg.package}/bin/vscode-html-language-server" "--stdio" ];
}
{
name = "jsonls";
description = "Enable jsonls, for JSON";
packages = [ pkgs.nodePackages.vscode-langservers-extracted ];
package = pkgs.nodePackages.vscode-langservers-extracted;
cmd = cfg: [ "${cfg.package}/bin/vscode-json-language-server" "--stdio" ];
}
{
name = "nil_ls";
description = "Enable nil, for Nix";
packages = [ pkgs.nil ];
package = pkgs.nil;
extraOptions = {
formatting.command = mkOption {
type = types.nullOr (types.listOf types.str);
@ -197,25 +201,21 @@ let
{
name = "tailwindcss";
description = "Enable tailwindcss language server, for tailwindcss";
packages = [ pkgs.nodePackages."@tailwindcss/language-server" ];
package = pkgs.nodePackages."@tailwindcss/language-server";
}
{
name = "texlab";
description = "Enable texlab language server, for LaTeX";
packages = [ pkgs.texlab ];
}
{
name = "tsserver";
description = "Enable tsserver for typescript";
packages = with pkgs; [
nodePackages.typescript
nodePackages.typescript-language-server
];
package = pkgs.nodePackages.typescript-language-server;
}
{
name = "vuels";
description = "Enable vuels, for Vue";
packages = [ pkgs.nodePackages.vls ];
package = pkgs.nodePackages.vue-language-server;
}
{
name = "zls";
@ -224,8 +224,8 @@ let
{
name = "hls";
description = "Enable haskell language server";
packages = [ pkgs.haskell-language-server ];
cmd = [ "haskell-language-server-wrapper" ];
package = pkgs.haskell-language-server;
cmd = cfg: [ "haskell-language-server-wrapper" ];
}
];
in

View file

@ -5,9 +5,10 @@
{ name
, description ? "Enable ${name}."
, serverName ? name
, packages ? [ pkgs.${name} ]
, cmd ? null
, settings ? null
, package ? pkgs.${name}
, extraPackages ? { }
, cmd ? (cfg: null)
, settings ? (cfg: { })
, extraOptions ? { }
, ...
}:
@ -16,22 +17,32 @@
with lib;
let
cfg = config.plugins.lsp.servers.${name};
packageOption =
if package != null then {
package = mkOption {
default = package;
type = types.nullOr types.package;
};
} else { };
in
{
options = {
plugins.lsp.servers.${name} = {
enable = mkEnableOption description;
} // extraOptions;
} // packageOption // extraOptions;
};
config = mkIf cfg.enable {
extraPackages = packages;
config = mkIf cfg.enable
{
extraPackages = (optional (package != null) cfg.package) ++
(mapAttrsToList (name: _: cfg."${name}Package") extraPackages);
plugins.lsp.enabledServers = [{
name = serverName;
extraOptions = {
inherit cmd;
settings = if settings != null then settings cfg else { };
cmd = cmd cfg;
settings = settings cfg;
};
}];
};