mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-25 02:08:40 +02:00
plugins/lsp/language-servers: harmless refactor
This commit is contained in:
parent
4530a35bad
commit
2705ce0ec6
3 changed files with 145 additions and 138 deletions
|
@ -1,128 +0,0 @@
|
||||||
{ pkgs, ... }:
|
|
||||||
{
|
|
||||||
mkLsp =
|
|
||||||
{
|
|
||||||
name,
|
|
||||||
description ? "Enable ${name}.",
|
|
||||||
serverName ? name,
|
|
||||||
package ? pkgs.${name},
|
|
||||||
cmd ? (cfg: null),
|
|
||||||
settings ? (cfg: cfg),
|
|
||||||
settingsOptions ? { },
|
|
||||||
extraConfig ? cfg: { },
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
# returns a module
|
|
||||||
{
|
|
||||||
pkgs,
|
|
||||||
config,
|
|
||||||
helpers,
|
|
||||||
lib,
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
with lib;
|
|
||||||
let
|
|
||||||
cfg = config.plugins.lsp.servers.${name};
|
|
||||||
in
|
|
||||||
{
|
|
||||||
options = {
|
|
||||||
plugins.lsp.servers.${name} = {
|
|
||||||
enable = mkEnableOption description;
|
|
||||||
|
|
||||||
package = mkOption {
|
|
||||||
default = package;
|
|
||||||
type = types.nullOr types.package;
|
|
||||||
description = "Which package to use for ${name}.";
|
|
||||||
};
|
|
||||||
|
|
||||||
cmd = mkOption {
|
|
||||||
type = with types; nullOr (listOf str);
|
|
||||||
default = if (cfg.package or null) != null then cmd cfg else null;
|
|
||||||
};
|
|
||||||
|
|
||||||
filetypes = helpers.mkNullOrOption (types.listOf types.str) ''
|
|
||||||
Set of filetypes for which to attempt to resolve {root_dir}.
|
|
||||||
May be empty, or server may specify a default value.
|
|
||||||
'';
|
|
||||||
|
|
||||||
autostart = helpers.defaultNullOpts.mkBool true ''
|
|
||||||
Controls if the `FileType` autocommand that launches a language server is created.
|
|
||||||
If `false`, allows for deferring language servers until manually launched with
|
|
||||||
`:LspStart` (|lspconfig-commands|).
|
|
||||||
'';
|
|
||||||
|
|
||||||
rootDir = helpers.defaultNullOpts.mkLuaFn "nil" ''
|
|
||||||
A function (or function handle) which returns the root of the project used to
|
|
||||||
determine if lspconfig should launch a new language server, or attach a previously
|
|
||||||
launched server when you open a new buffer matching the filetype of the server.
|
|
||||||
'';
|
|
||||||
|
|
||||||
onAttach = helpers.mkCompositeOption "Server specific on_attach behavior." {
|
|
||||||
override = mkOption {
|
|
||||||
type = types.bool;
|
|
||||||
default = false;
|
|
||||||
description = "Override the global `plugins.lsp.onAttach` function.";
|
|
||||||
};
|
|
||||||
|
|
||||||
function = mkOption {
|
|
||||||
type = types.lines;
|
|
||||||
description = ''
|
|
||||||
Body of the on_attach function.
|
|
||||||
The argument `client` and `bufnr` is provided.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
settings = helpers.mkSettingsOption {
|
|
||||||
description = "The settings for this LSP.";
|
|
||||||
options = settingsOptions;
|
|
||||||
};
|
|
||||||
|
|
||||||
extraOptions = mkOption {
|
|
||||||
default = { };
|
|
||||||
type = types.attrsOf types.anything;
|
|
||||||
description = "Extra options for the ${name} language server.";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
|
||||||
extraPackages = [ cfg.package ];
|
|
||||||
|
|
||||||
plugins.lsp.enabledServers = [
|
|
||||||
{
|
|
||||||
name = serverName;
|
|
||||||
extraOptions = {
|
|
||||||
inherit (cfg) cmd filetypes autostart;
|
|
||||||
root_dir = cfg.rootDir;
|
|
||||||
on_attach = helpers.ifNonNull' cfg.onAttach (
|
|
||||||
helpers.mkRaw ''
|
|
||||||
function(client, bufnr)
|
|
||||||
${optionalString (!cfg.onAttach.override) config.plugins.lsp.onAttach}
|
|
||||||
${cfg.onAttach.function}
|
|
||||||
end
|
|
||||||
''
|
|
||||||
);
|
|
||||||
settings = settings cfg.settings;
|
|
||||||
} // cfg.extraOptions;
|
|
||||||
}
|
|
||||||
];
|
|
||||||
};
|
|
||||||
imports =
|
|
||||||
let
|
|
||||||
basePluginPath = [
|
|
||||||
"plugins"
|
|
||||||
"lsp"
|
|
||||||
"servers"
|
|
||||||
name
|
|
||||||
];
|
|
||||||
basePluginPathString = concatStringsSep "." basePluginPath;
|
|
||||||
in
|
|
||||||
[
|
|
||||||
(mkRemovedOptionModule (
|
|
||||||
basePluginPath ++ [ "extraSettings" ]
|
|
||||||
) "You can use `${basePluginPathString}.extraOptions.settings` instead.")
|
|
||||||
(extraConfig cfg)
|
|
||||||
];
|
|
||||||
};
|
|
||||||
}
|
|
131
plugins/lsp/language-servers/_mk-lsp.nix
Normal file
131
plugins/lsp/language-servers/_mk-lsp.nix
Normal file
|
@ -0,0 +1,131 @@
|
||||||
|
#########
|
||||||
|
# mkLsp #
|
||||||
|
#########
|
||||||
|
#
|
||||||
|
# Helper function that returns the Nix module `plugins.lsp.servers.<name>`.
|
||||||
|
#
|
||||||
|
{ pkgs, ... }:
|
||||||
|
{
|
||||||
|
name,
|
||||||
|
description ? "Enable ${name}.",
|
||||||
|
serverName ? name,
|
||||||
|
package ? pkgs.${name},
|
||||||
|
cmd ? (cfg: null),
|
||||||
|
settings ? (cfg: cfg),
|
||||||
|
settingsOptions ? { },
|
||||||
|
extraConfig ? cfg: { },
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
# returns a module
|
||||||
|
{
|
||||||
|
pkgs,
|
||||||
|
config,
|
||||||
|
helpers,
|
||||||
|
lib,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
with lib;
|
||||||
|
let
|
||||||
|
cfg = config.plugins.lsp.servers.${name};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options = {
|
||||||
|
plugins.lsp.servers.${name} = {
|
||||||
|
enable = mkEnableOption description;
|
||||||
|
|
||||||
|
package = mkOption {
|
||||||
|
default = package;
|
||||||
|
type = types.nullOr types.package;
|
||||||
|
description = "Which package to use for ${name}.";
|
||||||
|
};
|
||||||
|
|
||||||
|
cmd = mkOption {
|
||||||
|
type = with types; nullOr (listOf str);
|
||||||
|
default = if (cfg.package or null) != null then cmd cfg else null;
|
||||||
|
};
|
||||||
|
|
||||||
|
filetypes = helpers.mkNullOrOption (types.listOf types.str) ''
|
||||||
|
Set of filetypes for which to attempt to resolve {root_dir}.
|
||||||
|
May be empty, or server may specify a default value.
|
||||||
|
'';
|
||||||
|
|
||||||
|
autostart = helpers.defaultNullOpts.mkBool true ''
|
||||||
|
Controls if the `FileType` autocommand that launches a language server is created.
|
||||||
|
If `false`, allows for deferring language servers until manually launched with
|
||||||
|
`:LspStart` (|lspconfig-commands|).
|
||||||
|
'';
|
||||||
|
|
||||||
|
rootDir = helpers.defaultNullOpts.mkLuaFn "nil" ''
|
||||||
|
A function (or function handle) which returns the root of the project used to
|
||||||
|
determine if lspconfig should launch a new language server, or attach a previously
|
||||||
|
launched server when you open a new buffer matching the filetype of the server.
|
||||||
|
'';
|
||||||
|
|
||||||
|
onAttach = helpers.mkCompositeOption "Server specific on_attach behavior." {
|
||||||
|
override = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = false;
|
||||||
|
description = "Override the global `plugins.lsp.onAttach` function.";
|
||||||
|
};
|
||||||
|
|
||||||
|
function = mkOption {
|
||||||
|
type = types.lines;
|
||||||
|
description = ''
|
||||||
|
Body of the on_attach function.
|
||||||
|
The argument `client` and `bufnr` is provided.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
settings = helpers.mkSettingsOption {
|
||||||
|
description = "The settings for this LSP.";
|
||||||
|
options = settingsOptions;
|
||||||
|
};
|
||||||
|
|
||||||
|
extraOptions = mkOption {
|
||||||
|
default = { };
|
||||||
|
type = types.attrsOf types.anything;
|
||||||
|
description = "Extra options for the ${name} language server.";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = mkIf cfg.enable {
|
||||||
|
extraPackages = [ cfg.package ];
|
||||||
|
|
||||||
|
plugins.lsp.enabledServers = [
|
||||||
|
{
|
||||||
|
name = serverName;
|
||||||
|
extraOptions = {
|
||||||
|
inherit (cfg) cmd filetypes autostart;
|
||||||
|
root_dir = cfg.rootDir;
|
||||||
|
on_attach = helpers.ifNonNull' cfg.onAttach (
|
||||||
|
helpers.mkRaw ''
|
||||||
|
function(client, bufnr)
|
||||||
|
${optionalString (!cfg.onAttach.override) config.plugins.lsp.onAttach}
|
||||||
|
${cfg.onAttach.function}
|
||||||
|
end
|
||||||
|
''
|
||||||
|
);
|
||||||
|
settings = settings cfg.settings;
|
||||||
|
} // cfg.extraOptions;
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
|
imports =
|
||||||
|
let
|
||||||
|
basePluginPath = [
|
||||||
|
"plugins"
|
||||||
|
"lsp"
|
||||||
|
"servers"
|
||||||
|
name
|
||||||
|
];
|
||||||
|
basePluginPathString = concatStringsSep "." basePluginPath;
|
||||||
|
in
|
||||||
|
[
|
||||||
|
(mkRemovedOptionModule (
|
||||||
|
basePluginPath ++ [ "extraSettings" ]
|
||||||
|
) "You can use `${basePluginPathString}.extraOptions.settings` instead.")
|
||||||
|
(extraConfig cfg)
|
||||||
|
];
|
||||||
|
}
|
|
@ -7,8 +7,6 @@
|
||||||
}@args:
|
}@args:
|
||||||
with lib;
|
with lib;
|
||||||
let
|
let
|
||||||
lspHelpers = import ../helpers.nix { inherit lib config pkgs; };
|
|
||||||
|
|
||||||
nixdSettings = import ./nixd.nix args;
|
nixdSettings = import ./nixd.nix args;
|
||||||
|
|
||||||
servers = [
|
servers = [
|
||||||
|
@ -660,14 +658,20 @@ let
|
||||||
];
|
];
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
imports = lib.lists.map lspHelpers.mkLsp servers ++ [
|
imports =
|
||||||
./ccls.nix
|
let
|
||||||
./efmls-configs.nix
|
mkLsp = import ./_mk-lsp.nix { inherit lib config pkgs; };
|
||||||
./pylsp.nix
|
lspModules = map mkLsp servers;
|
||||||
./rust-analyzer.nix
|
in
|
||||||
./svelte.nix
|
lspModules
|
||||||
./vls.nix
|
++ [
|
||||||
];
|
./ccls.nix
|
||||||
|
./efmls-configs.nix
|
||||||
|
./pylsp.nix
|
||||||
|
./rust-analyzer.nix
|
||||||
|
./svelte.nix
|
||||||
|
./vls.nix
|
||||||
|
];
|
||||||
|
|
||||||
config = lib.mkMerge [ nixdSettings.config ];
|
config = lib.mkMerge [ nixdSettings.config ];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue