plugins/nixd: Adapt to new options

Note that due to the structure of the code we can't introduce
deprecation warnings, it results in:

  cannot find attribute `plugins.lsp.servers.nixd.settings.XXX`
This commit is contained in:
traxys 2024-05-05 19:08:52 +02:00
parent 2fd3a0493c
commit 908932b53c
3 changed files with 55 additions and 59 deletions

View file

@ -4,11 +4,13 @@
config, config,
pkgs, pkgs,
... ...
}: }@args:
with lib; with lib;
let let
lspHelpers = import ../helpers.nix { inherit lib config pkgs; }; lspHelpers = import ../helpers.nix { inherit lib config pkgs; };
nixdSettings = import ./nixd.nix args;
servers = [ servers = [
{ {
name = "ansiblels"; name = "ansiblels";
@ -408,6 +410,7 @@ let
description = "nixd for Nix"; description = "nixd for Nix";
package = pkgs.nixd; package = pkgs.nixd;
settings = cfg: { nixd = cfg; }; settings = cfg: { nixd = cfg; };
settingsOptions = nixdSettings.options;
} }
{ {
name = "nushell"; name = "nushell";
@ -660,10 +663,11 @@ in
imports = lib.lists.map lspHelpers.mkLsp servers ++ [ imports = lib.lists.map lspHelpers.mkLsp servers ++ [
./ccls.nix ./ccls.nix
./efmls-configs.nix ./efmls-configs.nix
./nixd.nix
./pylsp.nix ./pylsp.nix
./rust-analyzer.nix ./rust-analyzer.nix
./svelte.nix ./svelte.nix
./vls.nix ./vls.nix
]; ];
config = lib.mkMerge [ nixdSettings.config ];
} }

View file

@ -10,52 +10,52 @@ let
cfg = config.plugins.lsp.servers.nixd; cfg = config.plugins.lsp.servers.nixd;
in in
{ {
# Options: https://github.com/nix-community/nixd/blob/main/docs/user-guide.md#configuration # Options:
options.plugins.lsp.servers.nixd.settings = { # - https://github.com/nix-community/nixd/blob/main/nixd/docs/configuration.md
# The evaluation section, provide auto completion for dynamic bindings. # - https://github.com/nix-community/nixd/blob/main/nixd/include/nixd/Controller/Configuration.h
eval = { options = {
target = {
args = helpers.defaultNullOpts.mkNullable (with types; listOf str) "[]" ''
Accept args as "nix eval".
'';
installable = helpers.defaultNullOpts.mkStr "" ''
"nix eval"
'';
};
depth = helpers.defaultNullOpts.mkInt 0 "Extra depth for evaluation";
workers = helpers.defaultNullOpts.mkInt 3 "The number of workers for evaluation task.";
};
formatting = { formatting = {
command = helpers.defaultNullOpts.mkStr "nixpkgs-fmt" '' command = helpers.defaultNullOpts.mkListOf types.str ''[ "nixpkgs-fmt" ]'' ''
Which command you would like to do formatting. Which command you would like to do formatting.
Explicitly set to `"nixpkgs-fmt"` will automatically add `pkgs.nixpkgs-fmt` to the nixvim Explicitly set to `["nixpkgs-fmt"]` will automatically add `pkgs.nixpkgs-fmt` to the nixvim
environment. environment.
''; '';
}; };
options = { options =
enable = helpers.defaultNullOpts.mkBool true '' let
Enable option completion task. provider = types.submodule {
If you are writing a package, disable this options = {
expr = mkOption {
type = types.str;
description = "Expression to eval. Select this attrset as eval .options";
};
};
};
in
helpers.mkNullOrOption (with helpers.nixvimTypes; attrsOf (maybeRaw provider)) ''
Tell the language server your desired option set, for completion.
This is lazily evaluated.
''; '';
target = { nixpkgs =
args = helpers.defaultNullOpts.mkNullable (with types; listOf str) "[]" '' let
Accept args as "nix eval". provider = types.submodule {
''; options = {
expr = mkOption {
installable = helpers.defaultNullOpts.mkStr "" '' type = types.str;
"nix eval" description = "Expression to eval. Treat it as `import <nixpkgs> { }`";
''; };
}; };
}; };
in
helpers.mkNullOrOption (helpers.nixvimTypes.maybeRaw provider) ''
This expression will be interpreted as "nixpkgs" toplevel
Nixd provides package, lib completion/information from it.
'';
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable {
extraPackages = optional (cfg.settings.formatting.command == "nixpkgs-fmt") pkgs.nixpkgs-fmt; extraPackages = optional (cfg.settings.formatting.command == [ "nixpkgs-fmt" ]) pkgs.nixpkgs-fmt;
}; };
} }

View file

@ -7,30 +7,22 @@
enable = true; enable = true;
settings = { settings = {
eval = { nixpkgs.expr = ''
target = { import (builtins.getFlake "/home/lyc/workspace/CS/OS/NixOS/flakes").inputs.nixpkgs { }
args = [ '';
"foo"
"bar"
];
installable = "";
};
depth = 0;
workers = 3;
};
formatting = { formatting = {
command = "nixpkgs-fmt"; command = [ "nixpkgs-fmt" ];
}; };
options = { options = {
enable = true; nixos.expr = ''
target = { (builtins.getFlake "/home/lyc/flakes").nixosConfigurations.adrastea.options
args = [ '';
"yes"
"no" home-manager.expr = ''
"maybe" (builtins.getFlake "/home/lyc/flakes").homeConfigurations."lyc@adrastea".options
]; '';
installable = "";
};
}; };
}; };
}; };