plugins/nvim-lsp: add extraOptions for nvim-lsp language servers (#351)

This commit is contained in:
Gaétan Lepage 2023-04-28 12:17:05 +02:00 committed by GitHub
parent 7f36532bdb
commit 3014192cdc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 14 deletions

View file

@ -20,6 +20,7 @@
pkgs,
config,
lib,
options,
...
}:
with lib; let
@ -84,6 +85,12 @@
Extra settings for the ${name} language server.
'';
};
extraOptions = mkOption {
default = {};
type = types.attrs;
description = "Extra options for the ${name} language server.";
};
}
// packageOption;
};
@ -98,22 +105,35 @@
plugins.lsp.enabledServers = [
{
name = serverName;
extraOptions = {
inherit (cfg) cmd filetypes autostart;
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.extraSettings;
};
extraOptions =
{
inherit (cfg) cmd filetypes autostart;
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.extraSettings;
}
// cfg.extraOptions;
}
];
warnings = let
extraSettingsOption = options.plugins.lsp.servers.${name}.extraSettings;
in
optional
(extraSettingsOption.isDefined)
(
let
optionPrefix = "plugins.lsp.servers.${name}";
in "The `${optionPrefix}.extraSettings` option is deprecated in favor of `${optionPrefix}.extraOptions.settings`."
);
};
};
}

View file

@ -33,6 +33,12 @@
};
nil_ls.enable = true;
rust-analyzer.enable = true;
ruff-lsp = {
enable = true;
extraOptions = {
init_options.settings.args = ["--config=/path/to/config.toml"];
};
};
pylsp = {
enable = true;
filetypes = ["python"];