From 908932b53c8e501eb7b56d35476754fbdb126f5e Mon Sep 17 00:00:00 2001 From: traxys Date: Sun, 5 May 2024 19:08:52 +0200 Subject: [PATCH] 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` --- plugins/lsp/language-servers/default.nix | 8 ++- plugins/lsp/language-servers/nixd.nix | 72 +++++++++---------- .../plugins/lsp/language-servers/nixd.nix | 34 ++++----- 3 files changed, 55 insertions(+), 59 deletions(-) diff --git a/plugins/lsp/language-servers/default.nix b/plugins/lsp/language-servers/default.nix index 85a6ff98..942c8753 100644 --- a/plugins/lsp/language-servers/default.nix +++ b/plugins/lsp/language-servers/default.nix @@ -4,11 +4,13 @@ config, pkgs, ... -}: +}@args: with lib; let lspHelpers = import ../helpers.nix { inherit lib config pkgs; }; + nixdSettings = import ./nixd.nix args; + servers = [ { name = "ansiblels"; @@ -408,6 +410,7 @@ let description = "nixd for Nix"; package = pkgs.nixd; settings = cfg: { nixd = cfg; }; + settingsOptions = nixdSettings.options; } { name = "nushell"; @@ -660,10 +663,11 @@ in imports = lib.lists.map lspHelpers.mkLsp servers ++ [ ./ccls.nix ./efmls-configs.nix - ./nixd.nix ./pylsp.nix ./rust-analyzer.nix ./svelte.nix ./vls.nix ]; + + config = lib.mkMerge [ nixdSettings.config ]; } diff --git a/plugins/lsp/language-servers/nixd.nix b/plugins/lsp/language-servers/nixd.nix index f4e338a1..1fcf766a 100644 --- a/plugins/lsp/language-servers/nixd.nix +++ b/plugins/lsp/language-servers/nixd.nix @@ -10,52 +10,52 @@ let cfg = config.plugins.lsp.servers.nixd; in { - # Options: https://github.com/nix-community/nixd/blob/main/docs/user-guide.md#configuration - options.plugins.lsp.servers.nixd.settings = { - # The evaluation section, provide auto completion for dynamic bindings. - eval = { - 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."; - }; - + # Options: + # - https://github.com/nix-community/nixd/blob/main/nixd/docs/configuration.md + # - https://github.com/nix-community/nixd/blob/main/nixd/include/nixd/Controller/Configuration.h + options = { formatting = { - command = helpers.defaultNullOpts.mkStr "nixpkgs-fmt" '' + command = helpers.defaultNullOpts.mkListOf types.str ''[ "nixpkgs-fmt" ]'' '' 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. ''; }; - options = { - enable = helpers.defaultNullOpts.mkBool true '' - Enable option completion task. - If you are writing a package, disable this + options = + let + provider = types.submodule { + 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 = { - args = helpers.defaultNullOpts.mkNullable (with types; listOf str) "[]" '' - Accept args as "nix eval". - ''; - - installable = helpers.defaultNullOpts.mkStr "" '' - "nix eval" - ''; - }; - }; + nixpkgs = + let + provider = types.submodule { + options = { + expr = mkOption { + type = types.str; + description = "Expression to eval. Treat it as `import { }`"; + }; + }; + }; + 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 { - extraPackages = optional (cfg.settings.formatting.command == "nixpkgs-fmt") pkgs.nixpkgs-fmt; + extraPackages = optional (cfg.settings.formatting.command == [ "nixpkgs-fmt" ]) pkgs.nixpkgs-fmt; }; } diff --git a/tests/test-sources/plugins/lsp/language-servers/nixd.nix b/tests/test-sources/plugins/lsp/language-servers/nixd.nix index 1ae8c59d..0e2723aa 100644 --- a/tests/test-sources/plugins/lsp/language-servers/nixd.nix +++ b/tests/test-sources/plugins/lsp/language-servers/nixd.nix @@ -7,30 +7,22 @@ enable = true; settings = { - eval = { - target = { - args = [ - "foo" - "bar" - ]; - installable = ""; - }; - depth = 0; - workers = 3; - }; + nixpkgs.expr = '' + import (builtins.getFlake "/home/lyc/workspace/CS/OS/NixOS/flakes").inputs.nixpkgs { } + ''; + formatting = { - command = "nixpkgs-fmt"; + command = [ "nixpkgs-fmt" ]; }; + options = { - enable = true; - target = { - args = [ - "yes" - "no" - "maybe" - ]; - installable = ""; - }; + nixos.expr = '' + (builtins.getFlake "/home/lyc/flakes").nixosConfigurations.adrastea.options + ''; + + home-manager.expr = '' + (builtins.getFlake "/home/lyc/flakes").homeConfigurations."lyc@adrastea".options + ''; }; }; };