mirror of
https://github.com/NotAShelf/nvf.git
synced 2026-06-24 13:24:39 +00:00
Merge pull request #1620 from snoweuph/feat/java
Some checks are pending
Set up binary cache / cachix (default) (push) Waiting to run
Set up binary cache / cachix (maximal) (push) Waiting to run
Set up binary cache / cachix (nix) (push) Waiting to run
Treewide Checks / Validate flake (push) Waiting to run
Treewide Checks / Check formatting (push) Waiting to run
Treewide Checks / Check source tree for typos (push) Waiting to run
Treewide Checks / Validate documentation builds (push) Waiting to run
Treewide Checks / Validate documentation builds-1 (push) Waiting to run
Treewide Checks / Validate documentation builds-2 (push) Waiting to run
Treewide Checks / Validate documentation builds-3 (push) Waiting to run
Treewide Checks / Validate hyperlinks in documentation sources (push) Waiting to run
Treewide Checks / Validate Editorconfig conformance (push) Waiting to run
Build and deploy documentation / Check latest commit (push) Waiting to run
Build and deploy documentation / publish (push) Blocked by required conditions
Some checks are pending
Set up binary cache / cachix (default) (push) Waiting to run
Set up binary cache / cachix (maximal) (push) Waiting to run
Set up binary cache / cachix (nix) (push) Waiting to run
Treewide Checks / Validate flake (push) Waiting to run
Treewide Checks / Check formatting (push) Waiting to run
Treewide Checks / Check source tree for typos (push) Waiting to run
Treewide Checks / Validate documentation builds (push) Waiting to run
Treewide Checks / Validate documentation builds-1 (push) Waiting to run
Treewide Checks / Validate documentation builds-2 (push) Waiting to run
Treewide Checks / Validate documentation builds-3 (push) Waiting to run
Treewide Checks / Validate hyperlinks in documentation sources (push) Waiting to run
Treewide Checks / Validate Editorconfig conformance (push) Waiting to run
Build and deploy documentation / Check latest commit (push) Waiting to run
Build and deploy documentation / publish (push) Blocked by required conditions
JLS
This commit is contained in:
commit
5727a5b9a7
6 changed files with 249 additions and 9 deletions
|
|
@ -323,6 +323,11 @@
|
||||||
|
|
||||||
[Snoweuph](https://github.com/snoweuph)
|
[Snoweuph](https://github.com/snoweuph)
|
||||||
|
|
||||||
|
- Added {option}`vim.lsp.presets.jls.enable` and made it available under
|
||||||
|
`vim.languages.java.lsp.servers`.
|
||||||
|
|
||||||
|
- Added {option}`vim.languages.java.dap.enable` with the `jls` DAP.
|
||||||
|
|
||||||
- Allow the usage of `pks.tree-sitter-grammars` in
|
- Allow the usage of `pks.tree-sitter-grammars` in
|
||||||
{option}`vim.treesitter.grammars` and language module tree-sitter package
|
{option}`vim.treesitter.grammars` and language module tree-sitter package
|
||||||
options created via `mkGrammarOption`.
|
options created via `mkGrammarOption`.
|
||||||
|
|
|
||||||
101
flake/pkgs/by-name/jls/package.nix
Normal file
101
flake/pkgs/by-name/jls/package.nix
Normal file
|
|
@ -0,0 +1,101 @@
|
||||||
|
# based on <https://github.com/idelice/jls/blob/master/default.nix>
|
||||||
|
{
|
||||||
|
lib,
|
||||||
|
jdk25_headless,
|
||||||
|
maven,
|
||||||
|
lombok,
|
||||||
|
protobuf_25,
|
||||||
|
lombokSupport ? true,
|
||||||
|
makeWrapper,
|
||||||
|
fetchFromGitHub,
|
||||||
|
}: let
|
||||||
|
inherit (lib.meta) getExe;
|
||||||
|
|
||||||
|
jdk = jdk25_headless;
|
||||||
|
java = getExe jdk;
|
||||||
|
jlinkVmOptions =
|
||||||
|
map
|
||||||
|
(option: ''
|
||||||
|
--add-flags "${option}" \
|
||||||
|
'')
|
||||||
|
[
|
||||||
|
"--add-modules jdk.jdeps"
|
||||||
|
"--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED"
|
||||||
|
"--add-exports jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED"
|
||||||
|
"--add-exports jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED"
|
||||||
|
"--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED"
|
||||||
|
"--add-exports jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED"
|
||||||
|
"--add-exports jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED"
|
||||||
|
"--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED"
|
||||||
|
"--add-exports jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED"
|
||||||
|
"--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED"
|
||||||
|
"--add-exports jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED"
|
||||||
|
"--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED"
|
||||||
|
"--add-opens jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED"
|
||||||
|
"--add-opens jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED"
|
||||||
|
"--add-opens jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED"
|
||||||
|
"--add-opens jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED"
|
||||||
|
"--add-opens jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED"
|
||||||
|
"--add-opens jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED"
|
||||||
|
"--add-opens jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED"
|
||||||
|
"--add-opens jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED"
|
||||||
|
"--add-opens jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED"
|
||||||
|
"--add-opens jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED"
|
||||||
|
"--add-opens jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED"
|
||||||
|
];
|
||||||
|
wrapperFlags = ''
|
||||||
|
${lib.concatStringsSep " " jlinkVmOptions} \
|
||||||
|
--add-flags "\$JLS_JVM_OPTS" \
|
||||||
|
--add-flags "-Djava.util.logging.config.file=$out/share/jls/logging.properties" \
|
||||||
|
${lib.optionalString lombokSupport ''--add-flags "-Dorg.javacs.lombokPath=${lombok}/share/lombok.jar"''} \
|
||||||
|
--add-flags "-classpath '$out/share/jls/classpath/*'" \
|
||||||
|
--set-default JLS_JVM_OPTS "-Xmx2g -Xms512m -XX:MaxHeapFreeRatio=50 -XX:MinHeapFreeRatio=20 -XX:+UseStringDeduplication" \
|
||||||
|
'';
|
||||||
|
in
|
||||||
|
maven.buildMavenPackage (finalAttrs: {
|
||||||
|
pname = "jls";
|
||||||
|
version = "0.6.1";
|
||||||
|
|
||||||
|
src = fetchFromGitHub {
|
||||||
|
owner = "idelice";
|
||||||
|
repo = "jls";
|
||||||
|
tag = "v${finalAttrs.version}";
|
||||||
|
hash = "sha256-kZ96OsCMtpS3diUT/4+TEnzNb2G4LfDdrrSKuhIM9NU=";
|
||||||
|
};
|
||||||
|
|
||||||
|
mvnJdk = jdk;
|
||||||
|
mvnHash = "sha256-E/ZNOGIB/00dfhPsagwJUV6TWHCY7Jb5Ewlvyxs3sRI=";
|
||||||
|
mvnParameters = "-DskipTests";
|
||||||
|
|
||||||
|
nativeBuildInputs = [
|
||||||
|
makeWrapper
|
||||||
|
protobuf_25
|
||||||
|
];
|
||||||
|
|
||||||
|
preBuild = ''
|
||||||
|
bash ./scripts/gen_proto.sh
|
||||||
|
'';
|
||||||
|
|
||||||
|
installPhase = ''
|
||||||
|
runHook preInstall
|
||||||
|
|
||||||
|
mkdir -p $out/bin $out/share/jls/
|
||||||
|
cp -r dist/classpath $out/share/jls/
|
||||||
|
install -Dm644 scripts/logging.properties $out/share/jls
|
||||||
|
|
||||||
|
makeWrapper ${java} $out/bin/jls \
|
||||||
|
${wrapperFlags} \
|
||||||
|
--add-flags "org.javacs.Main"
|
||||||
|
makeWrapper ${java} $out/bin/jls-dap \
|
||||||
|
${wrapperFlags} \
|
||||||
|
--add-flags "org.javacs.debug.JavaDebugServer"
|
||||||
|
|
||||||
|
runHook postInstall
|
||||||
|
'';
|
||||||
|
|
||||||
|
meta = {
|
||||||
|
description = "Java Language Server for Neovim";
|
||||||
|
license = lib.licenses.mit;
|
||||||
|
mainProgram = "jls";
|
||||||
|
};
|
||||||
|
})
|
||||||
|
|
@ -205,7 +205,7 @@ in {
|
||||||
|
|
||||||
dap = {
|
dap = {
|
||||||
enable =
|
enable =
|
||||||
mkEnableOption "Go Debug Adapter (DAP) via `nvim-dap-go"
|
mkEnableOption "Go Debug Adapter"
|
||||||
// {
|
// {
|
||||||
default = config.vim.languages.enableDAP;
|
default = config.vim.languages.enableDAP;
|
||||||
defaultText = literalExpression "config.vim.languages.enableDAP";
|
defaultText = literalExpression "config.vim.languages.enableDAP";
|
||||||
|
|
|
||||||
|
|
@ -2,19 +2,45 @@
|
||||||
config,
|
config,
|
||||||
pkgs,
|
pkgs,
|
||||||
lib,
|
lib,
|
||||||
|
inputs,
|
||||||
...
|
...
|
||||||
}: let
|
}: let
|
||||||
inherit (lib.options) literalExpression mkEnableOption mkOption;
|
|
||||||
inherit (lib.modules) mkIf mkMerge;
|
inherit (lib.modules) mkIf mkMerge;
|
||||||
inherit (lib) genAttrs;
|
inherit (lib.options) literalExpression mkEnableOption mkOption;
|
||||||
inherit (lib.types) listOf str;
|
inherit (lib.types) listOf str enum package;
|
||||||
inherit (lib.meta) getExe;
|
inherit (lib.attrsets) attrNames genAttrs;
|
||||||
|
inherit (lib.meta) getExe getExe';
|
||||||
inherit (lib.nvim.types) mkGrammarOption mkPluginSetupOption enumWithRename;
|
inherit (lib.nvim.types) mkGrammarOption mkPluginSetupOption enumWithRename;
|
||||||
|
|
||||||
cfg = config.vim.languages.java;
|
cfg = config.vim.languages.java;
|
||||||
|
|
||||||
defaultServers = ["jdt-language-server"];
|
defaultServers = ["jdt-language-server"];
|
||||||
servers = ["jdt-language-server"];
|
servers = ["jdt-language-server" "jls"];
|
||||||
|
|
||||||
|
defaultDebugger = "jls";
|
||||||
|
debuggers = {
|
||||||
|
jls = let
|
||||||
|
pkg = inputs.self.packages.${pkgs.stdenv.hostPlatform.system}.jls;
|
||||||
|
in {
|
||||||
|
package = pkg;
|
||||||
|
config = ''
|
||||||
|
dap.adapters.jls= {
|
||||||
|
type = 'executable',
|
||||||
|
command = '${getExe' pkg "jls-dap"}',
|
||||||
|
}
|
||||||
|
dap.configurations.java = {
|
||||||
|
{
|
||||||
|
type = "jls",
|
||||||
|
request = "attach",
|
||||||
|
name = "Attach",
|
||||||
|
hostName = "localhost",
|
||||||
|
port = 5005,
|
||||||
|
sourceRoots = vim.fn.glob("**/src/main/java", true, true),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
in {
|
in {
|
||||||
options.vim.languages.java = {
|
options.vim.languages.java = {
|
||||||
enable = mkEnableOption "Java language support";
|
enable = mkEnableOption "Java language support";
|
||||||
|
|
@ -48,6 +74,72 @@ in {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
dap = {
|
||||||
|
enable =
|
||||||
|
mkEnableOption "Java Debug Adapter"
|
||||||
|
// {
|
||||||
|
default = config.vim.languages.enableDAP;
|
||||||
|
defaultText = literalExpression "config.vim.languages.enableDAP";
|
||||||
|
};
|
||||||
|
|
||||||
|
debugger = mkOption {
|
||||||
|
type = enum (attrNames debuggers);
|
||||||
|
default = defaultDebugger;
|
||||||
|
description = ''
|
||||||
|
Java debugger to use.
|
||||||
|
|
||||||
|
**JLS**
|
||||||
|
|
||||||
|
For `jls` to work, you need to run your application with debug symbols and networking.
|
||||||
|
|
||||||
|
The `jls` configuration is hardcoded to listen on port `5005`.
|
||||||
|
This matches the configuration described [upstream](https://github.com/idelice/jls#usage).
|
||||||
|
You can change this by modifying `vim.debugger.nvim-dap.sources.java-debugger`.
|
||||||
|
```nix
|
||||||
|
vim.debugger.nvim-dap.sources.java-debugger = /* lua */ '''
|
||||||
|
dap.adapters.jls= {
|
||||||
|
type = 'executable',
|
||||||
|
command = ''\'''${getExe' inputs.self.packages.''${pkgs.stdenv.hostPlatform.system}.jls "jls-dap"}',
|
||||||
|
}
|
||||||
|
dap.configurations.java = {
|
||||||
|
{
|
||||||
|
type = "jls",
|
||||||
|
request = "attach",
|
||||||
|
name = "Attach",
|
||||||
|
hostName = "localhost",
|
||||||
|
port = 6969, -- your custom port
|
||||||
|
sourceRoots = vim.fn.glob("**/src/main/java", true, true),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
''';
|
||||||
|
```
|
||||||
|
|
||||||
|
*Examples:*
|
||||||
|
|
||||||
|
- Manual:
|
||||||
|
1. Build with debug symbols.
|
||||||
|
```sh
|
||||||
|
javac -g ...
|
||||||
|
```
|
||||||
|
1. Run with debug socket.
|
||||||
|
```sh
|
||||||
|
java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005 -jar your.jar
|
||||||
|
```
|
||||||
|
- Springboot Maven:
|
||||||
|
For Springboot you can just pass the JVM args directly into the `spring-boot:run`.
|
||||||
|
```sh
|
||||||
|
mvn spring-boot:run -Dspring-boot.run.jvmArguments="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005"
|
||||||
|
```
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
package = mkOption {
|
||||||
|
type = package;
|
||||||
|
default = debuggers.${cfg.dap.debugger}.package;
|
||||||
|
description = "Java debugger package.";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
extensions = {
|
extensions = {
|
||||||
maven-nvim = {
|
maven-nvim = {
|
||||||
enable = mkEnableOption "maven integration";
|
enable = mkEnableOption "maven integration";
|
||||||
|
|
@ -88,6 +180,11 @@ in {
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkIf cfg.enable (mkMerge [
|
config = mkIf cfg.enable (mkMerge [
|
||||||
|
(mkIf cfg.treesitter.enable {
|
||||||
|
vim.treesitter.enable = true;
|
||||||
|
vim.treesitter.grammars = [cfg.treesitter.package];
|
||||||
|
})
|
||||||
|
|
||||||
(mkIf cfg.lsp.enable {
|
(mkIf cfg.lsp.enable {
|
||||||
vim.lsp = {
|
vim.lsp = {
|
||||||
presets = genAttrs cfg.lsp.servers (_: {enable = true;});
|
presets = genAttrs cfg.lsp.servers (_: {enable = true;});
|
||||||
|
|
@ -97,9 +194,11 @@ in {
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
|
||||||
(mkIf cfg.treesitter.enable {
|
(mkIf cfg.dap.enable {
|
||||||
vim.treesitter.enable = true;
|
vim.debugger.nvim-dap = {
|
||||||
vim.treesitter.grammars = [cfg.treesitter.package];
|
enable = true;
|
||||||
|
sources.java-debugger = debuggers.${cfg.dap.debugger}.config;
|
||||||
|
};
|
||||||
})
|
})
|
||||||
|
|
||||||
(mkIf cfg.extensions.maven-nvim.enable {
|
(mkIf cfg.extensions.maven-nvim.enable {
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@
|
||||||
./intelephense.nix
|
./intelephense.nix
|
||||||
./jdt-language-server.nix
|
./jdt-language-server.nix
|
||||||
./jinja-lsp.nix
|
./jinja-lsp.nix
|
||||||
|
./jls.nix
|
||||||
./jq-lsp.nix
|
./jq-lsp.nix
|
||||||
./julia-languageserver.nix
|
./julia-languageserver.nix
|
||||||
./just-lsp.nix
|
./just-lsp.nix
|
||||||
|
|
|
||||||
34
modules/plugins/lsp/presets/jls.nix
Normal file
34
modules/plugins/lsp/presets/jls.nix
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
{
|
||||||
|
config,
|
||||||
|
lib,
|
||||||
|
pkgs,
|
||||||
|
inputs,
|
||||||
|
...
|
||||||
|
}: let
|
||||||
|
inherit (lib.meta) getExe;
|
||||||
|
inherit (lib.modules) mkIf;
|
||||||
|
inherit (lib.nvim.types) mkLspPresetEnableOption;
|
||||||
|
|
||||||
|
cfg = config.vim.lsp.presets.jls;
|
||||||
|
in {
|
||||||
|
options.vim.lsp.presets.jls = {
|
||||||
|
enable = mkLspPresetEnableOption "jls" "NeoVim Java" [];
|
||||||
|
};
|
||||||
|
|
||||||
|
config = mkIf cfg.enable {
|
||||||
|
vim.lsp.servers.jls = {
|
||||||
|
enable = true;
|
||||||
|
cmd = [(getExe inputs.self.packages.${pkgs.stdenv.hostPlatform.system}.jls)];
|
||||||
|
root_markers = [
|
||||||
|
".git"
|
||||||
|
".java-version"
|
||||||
|
"pom.xml"
|
||||||
|
"build.xml"
|
||||||
|
"build.gradle"
|
||||||
|
"build.gradle.kts"
|
||||||
|
"settings.gradle"
|
||||||
|
"settings.gradle.kts"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue