From 619e24366e8ad34230d65a323d26ca981bfa6927 Mon Sep 17 00:00:00 2001 From: Gaetan Lepage Date: Sun, 13 Oct 2024 15:22:01 +0200 Subject: [PATCH] plugins/lsp/hls: handle automatic installation of required GHC --- plugins/lsp/language-servers/default.nix | 1 + plugins/lsp/language-servers/hls.nix | 34 ++++++++++++++++++++++++ tests/lsp-servers.nix | 11 +++++--- 3 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 plugins/lsp/language-servers/hls.nix diff --git a/plugins/lsp/language-servers/default.nix b/plugins/lsp/language-servers/default.nix index 05a1cd07..da7e2946 100644 --- a/plugins/lsp/language-servers/default.nix +++ b/plugins/lsp/language-servers/default.nix @@ -220,6 +220,7 @@ in ++ [ ./ccls.nix ./efmls-configs.nix + ./hls.nix ./pylsp.nix ./rust-analyzer.nix ./svelte.nix diff --git a/plugins/lsp/language-servers/hls.nix b/plugins/lsp/language-servers/hls.nix new file mode 100644 index 00000000..d86111a0 --- /dev/null +++ b/plugins/lsp/language-servers/hls.nix @@ -0,0 +1,34 @@ +{ + config, + lib, + pkgs, + ... +}: +with lib; +let + cfg = config.plugins.lsp.servers.hls; +in +{ + options.plugins.lsp.servers.hls = { + installGhc = mkOption { + type = with types; nullOr bool; + default = null; + example = true; + description = "Whether to install `ghc`."; + }; + + ghcPackage = mkPackageOption pkgs "ghc" { }; + }; + + config = mkIf cfg.enable { + warnings = optional (cfg.installGhc == null) '' + `hls` relies on `ghc` (the Glasgow Haskell Compiler). + - Set `plugins.lsp.servers.hls.installGhc = true` to install it automatically with Nixvim. + You can customize which package to install by changing `plugins.lsp.servers.hls.ghcPackage`. + - Set `plugins.lsp.servers.hls.installGhc = false` to not have it install through Nixvim. + By doing so, you will dismiss this warning. + ''; + + extraPackages = with pkgs; (optional ((isBool cfg.installGhc) && cfg.installGhc) cfg.ghcPackage); + }; +} diff --git a/tests/lsp-servers.nix b/tests/lsp-servers.nix index 64bdeb02..ba3bca13 100644 --- a/tests/lsp-servers.nix +++ b/tests/lsp-servers.nix @@ -16,9 +16,14 @@ let plugins.lsp = { enable = true; - servers.rust_analyzer = { - installCargo = true; - installRustc = true; + servers = { + hls = { + installGhc = true; + }; + rust_analyzer = { + installCargo = true; + installRustc = true; + }; }; }; };