plugins/nvim-jdtls: add data and configuration options (#308)

This commit is contained in:
Gaétan Lepage 2023-03-31 18:05:56 +02:00 committed by GitHub
parent cbf6c56385
commit 75f7b22f21
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 83 additions and 10 deletions

View file

@ -15,10 +15,50 @@ in {
package = helpers.mkPackageOption "nvim-jdtls" pkgs.vimPlugins.nvim-jdtls; package = helpers.mkPackageOption "nvim-jdtls" pkgs.vimPlugins.nvim-jdtls;
cmd = mkOption { cmd = helpers.mkNullOrOption (types.listOf types.str) ''
type = types.listOf types.str; The command that starts the language server.
description = "The command that starts the language server";
default = ["${pkgs.jdt-language-server}/bin/jdt-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 = rootDir =
@ -52,9 +92,31 @@ in {
}; };
config = let 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 = options =
{ {
inherit (cfg) cmd; inherit cmd;
root_dir = cfg.rootDir; root_dir = cfg.rootDir;
inherit (cfg) settings; inherit (cfg) settings;
init_options = cfg.initOptions; init_options = cfg.initOptions;

View file

@ -1,13 +1,15 @@
{pkgs}: { {pkgs}: {
empty = {
plugins.nvim-jdtls.enable = true;
};
example = { example = {
plugins.nvim-jdtls = { plugins.nvim-jdtls = {
enable = true; 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'})"; 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";
};
};
} }