From 75f7b22f2128188a7378d80e3e8e23679b5af5f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=A9tan=20Lepage?= <33058747+GaetanLepage@users.noreply.github.com> Date: Fri, 31 Mar 2023 18:05:56 +0200 Subject: [PATCH] plugins/nvim-jdtls: add data and configuration options (#308) --- plugins/languages/nvim-jdtls.nix | 72 +++++++++++++++++-- .../plugins/languages/nvim-jdtls.nix | 21 ++++-- 2 files changed, 83 insertions(+), 10 deletions(-) diff --git a/plugins/languages/nvim-jdtls.nix b/plugins/languages/nvim-jdtls.nix index 0b7f365e..3cc4fc7a 100644 --- a/plugins/languages/nvim-jdtls.nix +++ b/plugins/languages/nvim-jdtls.nix @@ -15,10 +15,50 @@ in { package = helpers.mkPackageOption "nvim-jdtls" pkgs.vimPlugins.nvim-jdtls; - cmd = mkOption { - type = types.listOf types.str; - description = "The command that starts the language server"; - default = ["${pkgs.jdt-language-server}/bin/jdt-language-server"]; + cmd = helpers.mkNullOrOption (types.listOf types.str) '' + The command that starts the language server. + + You should either set a value for this option, or, you can instead set the `data` (and + `configuration`) options. + + ``` + plugins.nvim-jdtls = { + enable = true; + cmd = [ + "$\{pkgs.jdt-language-server}/bin/jdt-language-server" + "-data" "/path/to/your/workspace" + "-configuration" "/path/to/your/configuration" + "-foo" "bar" + ]; + }; + ``` + + Or, + ``` + plugins.nvim-jdtls = { + enable = true; + data = "/path/to/your/workspace"; + configuration = "/path/to/your/configuration"; + }; + ``` + ''; + + data = mkOption { + type = types.nullOr types.str; + default = null; + example = "/home/YOUR_USERNAME/.cache/jdtls/workspace"; + description = '' + eclipse.jdt.ls stores project specific data within the folder set via the -data flag. + If you're using eclipse.jdt.ls with multiple different projects you must use a dedicated + data directory per project. + ''; + }; + + configuration = mkOption { + type = types.nullOr types.str; + default = null; + example = "/home/YOUR_USERNAME/.cache/jdtls/config"; + description = "Path to the configuration file."; }; rootDir = @@ -52,9 +92,31 @@ in { }; config = let + cmd = + if isNull cfg.cmd + then let + data = + if isNull cfg.data + then + throw '' + You have to either set the 'plugins.nvim-jdtls.data' or the 'plugins.nvim-jdtls.cmd' + option. + '' + else cfg.data; + in + [ + "${pkgs.jdt-language-server}/bin/jdt-language-server" + ] + ++ ["-data" data] + ++ ( + optionals (!isNull cfg.configuration) + ["-configuration" cfg.configuration] + ) + else cfg.cmd; + options = { - inherit (cfg) cmd; + inherit cmd; root_dir = cfg.rootDir; inherit (cfg) settings; init_options = cfg.initOptions; diff --git a/tests/test-sources/plugins/languages/nvim-jdtls.nix b/tests/test-sources/plugins/languages/nvim-jdtls.nix index 1e8620c0..be50f13a 100644 --- a/tests/test-sources/plugins/languages/nvim-jdtls.nix +++ b/tests/test-sources/plugins/languages/nvim-jdtls.nix @@ -1,13 +1,15 @@ {pkgs}: { - empty = { - plugins.nvim-jdtls.enable = true; - }; - example = { plugins.nvim-jdtls = { enable = true; - cmd = ["${pkgs.jdt-language-server}/bin/jdt-language-server"]; + cmd = [ + "${pkgs.jdt-language-server}/bin/jdt-language-server" + "-data" + "/dev/null" + "-configuration" + "/dev/null" + ]; rootDir.__raw = "require('jdtls.setup').find_root({'.git', 'mvnw', 'gradlew'})"; @@ -20,4 +22,13 @@ }; }; }; + + dataAndConfiguration = { + plugins.nvim-jdtls = { + enable = true; + + data = "/path/to/my/project"; + configuration = "/path/to/configuration"; + }; + }; }