mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-20 16:15:43 +02:00
plugins/nvim-jdtls: rename to jdtls, migrate to mkNeovimPlugin
This commit is contained in:
parent
d67fcbd1d3
commit
7114362f36
7 changed files with 194 additions and 189 deletions
|
@ -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.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
|
54
plugins/by-name/jdtls/default.nix
Normal file
54
plugins/by-name/jdtls/default.nix
Normal file
|
@ -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])
|
||||
'';
|
||||
};
|
||||
}
|
49
plugins/by-name/jdtls/deprecations.nix
Normal file
49
plugins/by-name/jdtls/deprecations.nix
Normal file
|
@ -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`
|
||||
'')
|
||||
];
|
||||
}
|
46
plugins/by-name/jdtls/settings-options.nix
Normal file
46
plugins/by-name/jdtls/settings-options.nix
Normal file
|
@ -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
|
||||
'';
|
||||
}
|
|
@ -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
|
||||
'';
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
43
tests/test-sources/plugins/by-name/jdtls/default.nix
Normal file
43
tests/test-sources/plugins/by-name/jdtls/default.nix
Normal file
|
@ -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"
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
|
@ -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";
|
||||
};
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue