From ba293d36403c39c22dbb9a928f9af4d0df54b79f Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Thu, 23 May 2024 19:41:41 -0500 Subject: [PATCH] plugins/lsp/language-servers/nil_ls: improve settings options --- plugins/lsp/language-servers/default.nix | 37 +---------- .../lsp/language-servers/nil_ls-settings.nix | 63 +++++++++++++++++++ .../plugins/lsp/language-servers/nil-ls.nix | 33 ++++++++++ 3 files changed, 98 insertions(+), 35 deletions(-) create mode 100644 plugins/lsp/language-servers/nil_ls-settings.nix create mode 100644 tests/test-sources/plugins/lsp/language-servers/nil-ls.nix diff --git a/plugins/lsp/language-servers/default.nix b/plugins/lsp/language-servers/default.nix index b789af90..03fd8c66 100644 --- a/plugins/lsp/language-servers/default.nix +++ b/plugins/lsp/language-servers/default.nix @@ -361,41 +361,8 @@ let name = "nil_ls"; description = "nil for Nix"; package = pkgs.nil; - settingsOptions = { - formatting.command = mkOption { - type = types.nullOr (types.listOf types.str); - default = null; - description = '' - External formatter command (with arguments). - It should accepts file content in stdin and print the formatted code into stdout. - ''; - }; - diagnostics = { - ignored = mkOption { - type = types.listOf types.str; - default = [ ]; - description = '' - Ignored diagnostic kinds. - The kind identifier is a snake_cased_string usually shown together - with the diagnostic message. - ''; - }; - excludedFiles = mkOption { - type = types.listOf types.str; - default = [ ]; - description = '' - Files to exclude from showing diagnostics. Useful for generated files. - It accepts an array of paths. Relative paths are joint to the workspace root. - Glob patterns are currently not supported. - ''; - }; - }; - }; - settings = cfg: { - nil = { - inherit (cfg) formatting diagnostics; - }; - }; + settingsOptions = import ./nil_ls-settings.nix { inherit lib helpers; }; + settings = cfg: { nil = cfg; }; } { name = "nimls"; diff --git a/plugins/lsp/language-servers/nil_ls-settings.nix b/plugins/lsp/language-servers/nil_ls-settings.nix new file mode 100644 index 00000000..c0291146 --- /dev/null +++ b/plugins/lsp/language-servers/nil_ls-settings.nix @@ -0,0 +1,63 @@ +{ lib, helpers }: +# Options: +# - https://github.com/oxalica/nil/blob/main/docs/configuration.md?plain=1# +with lib; +{ + formatting = { + command = helpers.defaultNullOpts.mkListOf types.str "null" '' + External formatter command (with arguments). + It should accepts file content in stdin and print the formatted code into stdout. + ''; + }; + + diagnostics = { + ignored = helpers.defaultNullOpts.mkListOf types.str "[]" '' + Ignored diagnostic kinds. + The kind identifier is a snake_cased_string usually shown together + with the diagnostic message. + ''; + + excludedFiles = helpers.defaultNullOpts.mkListOf types.str "[]" '' + Files to exclude from showing diagnostics. Useful for generated files. + It accepts an array of paths. Relative paths are joint to the workspace root. + Glob patterns are currently not supported. + ''; + }; + + nix = { + binary = helpers.defaultNullOpts.mkStr "nix" '' + The path to the `nix` binary. + ''; + + maxMemoryMB = helpers.defaultNullOpts.mkInt 2560 '' + The heap memory limit in MiB for `nix` evaluation. + Currently it only applies to flake evaluation when `autoEvalInputs` is enabled, and only works + for Linux. + Other `nix` invocations may be also applied in the future. + `null` means no limit. + As a reference, `nix flake show --legacy nixpkgs` usually requires about 2GiB memory. + ''; + + flake = { + autoArchive = helpers.defaultNullOpts.mkBool false '' + Auto-archiving behavior which may use network. + - `null`: Ask every time. + - `true`: Automatically run `nix flake archive` when necessary. + - `false`: Do not archive. Only load inputs that are already on disk. + ''; + + autoEvalInputs = helpers.defaultNullOpts.mkBool false '' + Whether to auto-eval flake inputs. + The evaluation result is used to improve completion, but may cost lots of time and/or memory. + ''; + + nixpkgsInputName = helpers.defaultNullOpts.mkStr "nixpkgs" '' + The input name of nixpkgs for NixOS options evaluation. + + The options hierarchy is used to improve completion, but may cost lots of time and/or memory. + If this value is `null` or is not found in the workspace flake's inputs, NixOS options are + not evaluated. + ''; + }; + }; +} diff --git a/tests/test-sources/plugins/lsp/language-servers/nil-ls.nix b/tests/test-sources/plugins/lsp/language-servers/nil-ls.nix new file mode 100644 index 00000000..51bd3765 --- /dev/null +++ b/tests/test-sources/plugins/lsp/language-servers/nil-ls.nix @@ -0,0 +1,33 @@ +{ + example = { + plugins.lsp = { + enable = true; + + servers.nil_ls = { + enable = true; + + settings = { + diagnostics = { + ignored = [ + "unused_binding" + "unused_with" + ]; + excludedFiles = [ "Cargo.nix" ]; + }; + formatting = { + command = [ "nixfmt" ]; + }; + nix = { + binary = "nix"; + maxMemoryMB = 2048; + flake = { + autoArchive = true; + autoEvalInputs = false; + nixpkgsInputName = "nixpkgs"; + }; + }; + }; + }; + }; + }; +}