2024-05-14 15:44:12 +02:00
|
|
|
#########
|
|
|
|
# mkLsp #
|
|
|
|
#########
|
|
|
|
#
|
|
|
|
# Helper function that returns the Nix module `plugins.lsp.servers.<name>`.
|
|
|
|
#
|
|
|
|
{
|
|
|
|
name,
|
|
|
|
description ? "Enable ${name}.",
|
|
|
|
serverName ? name,
|
2024-10-10 19:43:40 +01:00
|
|
|
package ? null,
|
2024-09-01 09:43:53 +01:00
|
|
|
url ? null,
|
2024-05-14 15:44:12 +02:00
|
|
|
cmd ? (cfg: null),
|
|
|
|
settings ? (cfg: cfg),
|
|
|
|
settingsOptions ? { },
|
|
|
|
extraConfig ? cfg: { },
|
2024-05-14 16:18:57 +02:00
|
|
|
extraOptions ? { },
|
2024-05-14 15:44:12 +02:00
|
|
|
...
|
2024-09-01 09:43:53 +01:00
|
|
|
}@args:
|
2024-05-14 15:44:12 +02:00
|
|
|
# returns a module
|
|
|
|
{
|
|
|
|
pkgs,
|
|
|
|
config,
|
2024-09-01 09:43:53 +01:00
|
|
|
options,
|
2024-05-14 15:44:12 +02:00
|
|
|
helpers,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
cfg = config.plugins.lsp.servers.${name};
|
2024-11-19 13:55:33 +00:00
|
|
|
opts = options.plugins.lsp.servers.${name};
|
2024-11-19 11:36:31 +01:00
|
|
|
|
|
|
|
enabled = config.plugins.lsp.enable && cfg.enable;
|
2024-05-14 15:44:12 +02:00
|
|
|
in
|
|
|
|
{
|
2024-06-07 21:33:16 +01:00
|
|
|
meta.nixvimInfo = {
|
|
|
|
# TODO: description
|
2024-11-19 13:55:33 +00:00
|
|
|
url = args.url or opts.package.default.meta.homepage or null;
|
2024-06-07 21:33:16 +01:00
|
|
|
path = [
|
|
|
|
"plugins"
|
|
|
|
"lsp"
|
|
|
|
"servers"
|
|
|
|
name
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2024-05-14 15:44:12 +02:00
|
|
|
options = {
|
|
|
|
plugins.lsp.servers.${name} = {
|
|
|
|
enable = mkEnableOption description;
|
|
|
|
|
2024-09-01 09:43:53 +01:00
|
|
|
package =
|
|
|
|
if lib.isOption package then
|
|
|
|
package
|
2024-10-10 19:43:40 +01:00
|
|
|
else if args ? package then
|
2024-09-01 09:43:53 +01:00
|
|
|
lib.mkPackageOption pkgs name {
|
|
|
|
nullable = true;
|
|
|
|
default = package;
|
2024-10-10 19:43:40 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
# If we're not provided a package, we should provide a no-default option
|
|
|
|
lib.mkOption {
|
|
|
|
type = types.nullOr types.package;
|
|
|
|
description = ''
|
|
|
|
The package to use for ${name}. Has no default, but can be set to null.
|
|
|
|
'';
|
2024-09-01 09:43:53 +01:00
|
|
|
};
|
2024-05-14 15:44:12 +02:00
|
|
|
|
|
|
|
cmd = mkOption {
|
|
|
|
type = with types; nullOr (listOf str);
|
2024-10-05 15:55:49 +02:00
|
|
|
default =
|
2024-10-10 19:43:40 +01:00
|
|
|
# TODO: do we really only want the default `cmd` when `package` is non-null?
|
2024-11-19 13:55:33 +00:00
|
|
|
if !(opts.package.isDefined or false) then
|
2024-10-10 19:43:40 +01:00
|
|
|
null
|
|
|
|
else if cfg.package == null then
|
|
|
|
null
|
|
|
|
else if builtins.isFunction cmd then
|
|
|
|
cmd cfg
|
|
|
|
else
|
|
|
|
cmd;
|
2024-06-09 23:04:27 +02:00
|
|
|
description = ''
|
|
|
|
A list where each entry corresponds to the blankspace delimited part of the command that
|
|
|
|
launches the server.
|
|
|
|
|
|
|
|
The first entry is the binary used to run the language server.
|
|
|
|
Additional entries are passed as arguments.
|
|
|
|
'';
|
2024-05-14 15:44:12 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
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.";
|
|
|
|
};
|
2024-05-14 16:18:57 +02:00
|
|
|
} // extraOptions;
|
2024-05-14 15:44:12 +02:00
|
|
|
};
|
|
|
|
|
2024-11-19 11:36:31 +01:00
|
|
|
config = mkIf enabled {
|
2024-05-14 15:44:12 +02:00
|
|
|
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
|
|
|
|
''
|
|
|
|
);
|
2024-12-18 22:12:51 +00:00
|
|
|
settings = lib.nixvim.plugins.utils.applyExtraConfig {
|
2024-11-19 13:55:33 +00:00
|
|
|
extraConfig = settings;
|
|
|
|
cfg = cfg.settings;
|
|
|
|
opts = opts.settings;
|
|
|
|
enabled = true;
|
|
|
|
};
|
2024-05-14 15:44:12 +02:00
|
|
|
} // cfg.extraOptions;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
2024-06-02 18:58:06 +01:00
|
|
|
|
2024-05-14 15:44:12 +02:00
|
|
|
imports =
|
|
|
|
let
|
2024-06-02 18:58:06 +01:00
|
|
|
basePath = [
|
2024-05-14 15:44:12 +02:00
|
|
|
"plugins"
|
|
|
|
"lsp"
|
|
|
|
"servers"
|
|
|
|
];
|
2024-06-02 18:58:06 +01:00
|
|
|
basePluginPath = basePath ++ [ name ];
|
2024-05-14 15:44:12 +02:00
|
|
|
basePluginPathString = concatStringsSep "." basePluginPath;
|
|
|
|
in
|
|
|
|
[
|
|
|
|
(mkRemovedOptionModule (
|
|
|
|
basePluginPath ++ [ "extraSettings" ]
|
|
|
|
) "You can use `${basePluginPathString}.extraOptions.settings` instead.")
|
2024-06-02 18:58:06 +01:00
|
|
|
]
|
2024-11-19 13:55:33 +00:00
|
|
|
++ lib.optional (args ? extraConfig) (
|
2024-12-18 22:12:51 +00:00
|
|
|
lib.nixvim.plugins.utils.applyExtraConfig {
|
2024-11-19 13:55:33 +00:00
|
|
|
inherit
|
|
|
|
extraConfig
|
|
|
|
cfg
|
|
|
|
opts
|
|
|
|
enabled
|
|
|
|
;
|
|
|
|
}
|
|
|
|
)
|
2024-06-02 18:58:06 +01:00
|
|
|
# Add an alias (with warning) for the lspconfig server name, if different to `name`.
|
|
|
|
# Note: users may use lspconfig's docs to guess the `plugins.lsp.servers.*` name
|
|
|
|
++ (optional (name != serverName) (
|
|
|
|
mkRenamedOptionModule (basePath ++ [ serverName ]) basePluginPath
|
|
|
|
));
|
2024-05-14 15:44:12 +02:00
|
|
|
}
|