nix-community.nixvim/plugins/nvim-lsp/helpers.nix
traxys b1ba5f873e
lsp: add support for several LSP clients (#111)
* nvim-lsp: Allow to pass settings to clients

Some clients (like rust-analyzer, nil_ls, ...) can take settings
specified in the setup function. This commit adds two fields for the
'mkLsp' function to handle this:

- extraOptions: define nix module options
- settings: A function that takes the corresponding lsp module config
  and formats it as a settings object compatible with the server.

* nvim-lsp: Add nil-ls (for Nix)

* nvim-lsp: Add bashls (for Bash)

* nvim-lsp: Add dartls, for dart

Co-authored-by: Pedro Alves <pta2002@users.noreply.github.com>
2023-01-10 22:47:52 +00:00

39 lines
854 B
Nix

{ pkgs, config, lib, ... }:
{
mkLsp =
{ name
, description ? "Enable ${name}."
, serverName ? name
, packages ? [ pkgs.${name} ]
, cmd ? null
, settings ? null
, extraOptions ? { }
, ...
}:
# returns a module
{ pkgs, config, lib, ... }:
with lib;
let
cfg = config.plugins.lsp.servers.${name};
in
{
options = {
plugins.lsp.servers.${name} = {
enable = mkEnableOption description;
} // extraOptions;
};
config = mkIf cfg.enable {
extraPackages = packages;
plugins.lsp.enabledServers = [{
name = serverName;
extraOptions = {
inherit cmd;
settings = if settings != null then settings cfg else { };
};
}];
};
};
}