From 7114362f36123a8401f4905c2e833fd9a0c2ddd1 Mon Sep 17 00:00:00 2001 From: Gaetan Lepage Date: Tue, 8 Apr 2025 00:59:39 +0200 Subject: [PATCH] plugins/nvim-jdtls: rename to jdtls, migrate to mkNeovimPlugin --- plugins/by-name/java/default.nix | 4 +- plugins/by-name/jdtls/default.nix | 54 +++++++ plugins/by-name/jdtls/deprecations.nix | 49 ++++++ plugins/by-name/jdtls/settings-options.nix | 46 ++++++ plugins/by-name/nvim-jdtls/default.nix | 152 ------------------ .../plugins/by-name/jdtls/default.nix | 43 +++++ .../plugins/by-name/nvim-jdtls/default.nix | 35 ---- 7 files changed, 194 insertions(+), 189 deletions(-) create mode 100644 plugins/by-name/jdtls/default.nix create mode 100644 plugins/by-name/jdtls/deprecations.nix create mode 100644 plugins/by-name/jdtls/settings-options.nix delete mode 100644 plugins/by-name/nvim-jdtls/default.nix create mode 100644 tests/test-sources/plugins/by-name/jdtls/default.nix delete mode 100644 tests/test-sources/plugins/by-name/nvim-jdtls/default.nix diff --git a/plugins/by-name/java/default.nix b/plugins/by-name/java/default.nix index 46373a78..5fd4ffec 100644 --- a/plugins/by-name/java/default.nix +++ b/plugins/by-name/java/default.nix @@ -34,10 +34,10 @@ lib.nixvim.plugins.mkNeovimPlugin { extraConfig = cfg: { assertions = lib.nixvim.mkAssertions "plugins.nvim-java" { - assertion = cfg.enable -> !config.plugins.nvim-jdtls.enable; + assertion = cfg.enable -> !config.plugins.jdtls.enable; message = '' You cannot use nvim-java alongside nvim-jdtls. - Please, disable `plugins.nvim-jdtls` if you wish to use this plugin. + Please, disable `plugins.jdtls` if you wish to use this plugin. ''; }; }; diff --git a/plugins/by-name/jdtls/default.nix b/plugins/by-name/jdtls/default.nix new file mode 100644 index 00000000..dc4bbd51 --- /dev/null +++ b/plugins/by-name/jdtls/default.nix @@ -0,0 +1,54 @@ +{ + lib, + pkgs, + ... +}: +lib.nixvim.plugins.mkNeovimPlugin { + name = "jdtls"; + packPathName = "nvim-jdtls"; + package = "nvim-jdtls"; + + maintainers = [ lib.maintainers.GaetanLepage ]; + + # TODO: Added 2025-04-07; remove after 25.05 + inherit (import ./deprecations.nix lib) + imports + deprecateExtraOptions + ; + + extraOptions = { + jdtLanguageServerPackage = lib.mkPackageOption pkgs "jdt-language-server" { + nullable = true; + }; + }; + + setup = ".start_or_attach"; # only used settingsDescription + callSetup = false; + extraConfig = cfg: { + extraPackages = [ cfg.jdtLanguageServerPackage ]; + + autoCmd = [ + { + event = "FileType"; + pattern = "java"; + callback.__raw = '' + function () + require('jdtls').start_or_attach(${lib.nixvim.toLuaObject cfg.settings}) + end + ''; + } + ]; + }; + + settingsOptions = import ./settings-options.nix lib; + + settingsExample = { + cmd = [ + "jdtls" + { __raw = "'--jvm-arg='..vim.api.nvim_eval('g:NVIM_LOMBOK')"; } + ]; + root_dir.__raw = '' + vim.fs.dirname(vim.fs.find({'gradlew', '.git', 'mvnw'}, { upward = true })[1]) + ''; + }; +} diff --git a/plugins/by-name/jdtls/deprecations.nix b/plugins/by-name/jdtls/deprecations.nix new file mode 100644 index 00000000..b101b911 --- /dev/null +++ b/plugins/by-name/jdtls/deprecations.nix @@ -0,0 +1,49 @@ +lib: { + deprecateExtraOptions = true; + + imports = + let + oldPluginPath = [ + "plugins" + "nvim-jdtls" + ]; + newPluginPath = [ + "plugins" + "jdtls" + ]; + + settingsOptions = { + cmd = "cmd"; + rootDir = "root_dir"; + settings = "settings"; + initOptions = "init_options"; + }; + + renamedOptions = lib.nixvim.mkSettingsRenamedOptionModules oldPluginPath newPluginPath ( + [ + "enable" + "package" + { + old = "jdtLanguageServerPackage"; + new = "jdtLanguageServerPackage"; + } + ] + ++ (lib.mapAttrsToList (old: new_: { + inherit old; + new = [ + "settings" + new_ + ]; + }) settingsOptions) + ); + in + renamedOptions + ++ [ + (lib.mkRemovedOptionModule (oldPluginPath ++ [ "data" ]) '' + Please, directly add the necessary `"-data"` flag and its argument to `plugins.jdtls.settings.cmd` + '') + (lib.mkRemovedOptionModule (oldPluginPath ++ [ "configuration" ]) '' + Please, directly add the necessary `"-configuration"` flag and its argument to `plugins.jdtls.settings.cmd` + '') + ]; +} diff --git a/plugins/by-name/jdtls/settings-options.nix b/plugins/by-name/jdtls/settings-options.nix new file mode 100644 index 00000000..869bd713 --- /dev/null +++ b/plugins/by-name/jdtls/settings-options.nix @@ -0,0 +1,46 @@ +lib: +let + inherit (lib) types; + inherit (lib.nixvim) defaultNullOpts mkNullOrOption mkNullOrOption'; +in +{ + cmd = mkNullOrOption' { + type = with types; listOf str; + example = [ + "java" + "-data" + "/path/to/your/workspace" + "-configuration" + "/path/to/your/configuration" + "-foo" + "bar" + ]; + description = '' + The command that starts the language server. + ''; + }; + + root_dir = + defaultNullOpts.mkStr { __raw = "require('jdtls.setup').find_root({'.git', 'mvnw', 'gradlew'})"; } + '' + Function to identify the root directory from which to run the language server. + ''; + + settings = mkNullOrOption (with types; attrsOf anything) '' + Here you can configure `eclipse.jdt.ls` specific settings. + + See https://github.com/eclipse/eclipse.jdt.ls/wiki/Running-the-JAVA-LS-server-from-the-command-line#initialize-request + for a list of options. + ''; + + init_options = mkNullOrOption types.attrs '' + Language server `initializationOptions`. + + You need to extend the `bundles` with paths to jar files if you want to use additional + `eclipse.jdt.ls` plugins. + + See https://github.com/mfussenegger/nvim-jdtls#java-debug-installation + + If you don't plan on using the debugger or other `eclipse.jdt.ls` plugins, ignore this option + ''; +} diff --git a/plugins/by-name/nvim-jdtls/default.nix b/plugins/by-name/nvim-jdtls/default.nix deleted file mode 100644 index 2d76f34f..00000000 --- a/plugins/by-name/nvim-jdtls/default.nix +++ /dev/null @@ -1,152 +0,0 @@ -{ - lib, - helpers, - config, - pkgs, - ... -}: -with lib; -let - cfg = config.plugins.nvim-jdtls; -in -{ - options.plugins.nvim-jdtls = lib.nixvim.plugins.neovim.extraOptionsOptions // { - enable = mkEnableOption "nvim-jdtls"; - - package = lib.mkPackageOption pkgs "nvim-jdtls" { - default = [ - "vimPlugins" - "nvim-jdtls" - ]; - }; - - jdtLanguageServerPackage = lib.mkPackageOption pkgs "jdt-language-server" { - nullable = true; - }; - - 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. - - ```nix - plugins.nvim-jdtls = { - enable = true; - cmd = [ - (lib.getExe pkgs.jdt-language-server) - "-data" "/path/to/your/workspace" - "-configuration" "/path/to/your/configuration" - "-foo" "bar" - ]; - }; - ``` - - Or, - ```nix - plugins.nvim-jdtls = { - enable = true; - data = "/path/to/your/workspace"; - configuration = "/path/to/your/configuration"; - }; - ``` - ''; - - data = mkOption { - type = with types; nullOr (maybeRaw 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 = with types; nullOr (maybeRaw str); - default = null; - example = "/home/YOUR_USERNAME/.cache/jdtls/config"; - description = "Path to the configuration file."; - }; - - rootDir = - helpers.defaultNullOpts.mkStr - { __raw = "require('jdtls.setup').find_root({'.git', 'mvnw', 'gradlew'})"; } - '' - This is the default if not provided, you can remove it. Or adjust as needed. - One dedicated LSP server & client will be started per unique root_dir - ''; - - settings = helpers.mkNullOrOption types.attrs '' - Here you can configure eclipse.jdt.ls specific settings - See https://github.com/eclipse/eclipse.jdt.ls/wiki/Running-the-JAVA-LS-server-from-the-command-line#initialize-request - for a list of options. - ''; - - initOptions = helpers.mkNullOrOption types.attrs '' - Language server `initializationOptions` - You need to extend the `bundles` with paths to jar files if you want to use additional - eclipse.jdt.ls plugins. - - See https://github.com/mfussenegger/nvim-jdtls#java-debug-installation - - If you don't plan on using the debugger or other eclipse.jdt.ls plugins, ignore this option - ''; - }; - - config = - let - cmd = - if (cfg.cmd == null && cfg.jdtLanguageServerPackage != null) then - [ (lib.getExe cfg.jdtLanguageServerPackage) ] - ++ [ - "-data" - cfg.data - ] - ++ (optionals (cfg.configuration != null) [ - "-configuration" - cfg.configuration - ]) - else - cfg.cmd; - - options = { - inherit cmd; - root_dir = cfg.rootDir; - inherit (cfg) settings; - init_options = cfg.initOptions; - } // cfg.extraOptions; - in - mkIf cfg.enable { - assertions = lib.nixvim.mkAssertions "plugins.nvim-jdtls" [ - { - assertion = cfg.cmd != null || cfg.data != null; - message = "You have to either set the `plugins.nvim-jdtls.data` or the `plugins.nvim-jdtls.cmd` option."; - } - { - assertion = cfg.cmd == null -> cfg.jdtLanguageServerPackage != null; - message = '' - You haven't defined a `cmd` or `jdtLanguageServerPackage`. - - The default `cmd` requires `plugins.nvim-jdtls.jdtLanguageServerPackage` to be set. - ''; - } - ]; - extraPlugins = [ cfg.package ]; - - extraPackages = [ cfg.jdtLanguageServerPackage ]; - - autoCmd = [ - { - event = "FileType"; - pattern = "java"; - callback.__raw = '' - function () - require('jdtls').start_or_attach(${lib.nixvim.toLuaObject options}) - end - ''; - } - ]; - }; -} diff --git a/tests/test-sources/plugins/by-name/jdtls/default.nix b/tests/test-sources/plugins/by-name/jdtls/default.nix new file mode 100644 index 00000000..ecbbad16 --- /dev/null +++ b/tests/test-sources/plugins/by-name/jdtls/default.nix @@ -0,0 +1,43 @@ +{ pkgs, ... }: +{ + example = { + plugins.jdtls = { + enable = true; + jdtLanguageServerPackage = null; + + settings = { + cmd = [ + "${pkgs.jdt-language-server}/bin/jdt-language-server" + "-data" + "/dev/null" + "-configuration" + "/dev/null" + ]; + + root_dir.__raw = "require('jdtls.setup').find_root({'.git', 'mvnw', 'gradlew'})"; + + settings = { + java = { }; + }; + + init_options = { + bundles = { }; + }; + }; + }; + }; + + dataAndConfiguration = { + plugins.jdtls = { + enable = true; + + settings.cmd = [ + "jdtls" + "-data" + "/path/to/my/project" + "-configuration" + "/path/to/configuration" + ]; + }; + }; +} diff --git a/tests/test-sources/plugins/by-name/nvim-jdtls/default.nix b/tests/test-sources/plugins/by-name/nvim-jdtls/default.nix deleted file mode 100644 index bda54d38..00000000 --- a/tests/test-sources/plugins/by-name/nvim-jdtls/default.nix +++ /dev/null @@ -1,35 +0,0 @@ -{ pkgs, ... }: -{ - example = { - plugins.nvim-jdtls = { - enable = true; - jdtLanguageServerPackage = null; - 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'})"; - - settings = { - java = { }; - }; - - initOptions = { - bundles = { }; - }; - }; - }; - - dataAndConfiguration = { - plugins.nvim-jdtls = { - enable = true; - - data = "/path/to/my/project"; - configuration = "/path/to/configuration"; - }; - }; -}