Repository navigation
fix(java): 改进 jdtls-runtime 发现与 JDT LS 所需 Java 版本校验 - #29
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
关联 Issue / Linked issue
PR 类型 / Type
改动说明 / What changes
背景 / Why
升级到
v3.0.0+后,JDT LS 和运行它的 JDK(jdtls-runtime)都改由用户机器提供,实际环境存在两类阻塞启动的断层:jdtls-runtime被PATH上的低版本 Java 抢占:jdtls-runtime在executables中把{"kind": "command", "command": "java"}(shell,rank 4)排在{"kind": "toolchain", "scope": "installed"}(detected,rank 5)之前,且version.pattern原先与项目java相同(接受1.8.0_301等所有版本)。当用户机器同时装有 Java 8(在PATH上)与 JDK 21/25(在系统 JDK 目录但不在PATH上)时,Core 选出PATH上的 Java 8,随后被插件java.resolveLaunch以launch.runtime_too_old拒绝,不会回退到已发现的 JDK 21+。redhat.java扩展新版 JDT LS(1.63+)要求 Java 25,但扩展自带的 JRE 25 未纳入发现,且插件硬编码只校验 Java 21:jdtls.rs自动发现.vscode/extensions/redhat.java-*/server,其中redhat.java1.58.0+(JDT LS 1.63.0)的核心 OSGi bundle(如org.eclipse.core.filesystem_1.12.0、org.eclipse.jdt.core_3.48.0、org.eclipse.core.resources_3.25.0)声明了Bundle-RequiredExecutionEnvironment: JavaSE-25。当用户在「JDK for JDT LS」中手动选择 JDK 21 时,插件原先硬编码< 21放行启动,导致 Equinox 启动后因Unresolved requirement: osgi.ee; version=25以退出码 13 早退(host.exitedEarly);同时redhat.java随扩展自带的.vscode/extensions/redhat.java-*/jre/*(JRE 25)也未列入jdtls-runtime的discovery。改动 / Changes
io.github.lithe-idea.java-support/plugin.json:jdtls-runtime的version.pattern收紧为"version \\\"((?:2[1-9]|[3-9]\\d|\\d{3,})(?:\\.\\d+)*)",仅匹配 Java 21 及以上版本;当PATH上的java为 Java 8/11/17 时,Core 工具链解析判定versionUnsatisfied并自动跳过shell候选,继续回退到detected(已发现的最高版本 JDK 21+)。项目自身的java工具保持原匹配规则不变,仍支持 Java 8+。jdtls-runtime的discovery中新增.vscode/extensions/redhat.java-*/jre/*和.cursor/extensions/redhat.java-*/jre/*(kind: "home",共 16 条,符合 CoretoolDefinitions每工具最多 16 条discovery的上限),使复用 VS Code / Cursorredhat.java扩展的用户也能自动发现扩展自带的配套 JRE(如 JRE 25)。backend/src/jdtls.rs:ServerInstallation增加minimum_java_version: u64(默认下限DEFAULT_MINIMUM_JAVA_VERSION = 21)。required_java_version与manifest_java_version:检查目标 JDT LSplugins/下核心 bundle(org.eclipse.jdt.ls.core_*、org.eclipse.jdt.core_*、org.eclipse.core.resources_*、org.eclipse.core.filesystem_*、org.eclipse.equinox.common_*)的META-INF/MANIFEST.MF,解析Bundle-RequiredExecutionEnvironment: JavaSE-<N>与Require-Capability中的(version=<N>)(支持行折叠),得出该 JDT LS 安装实际要求的最低 Java 版本(如 21 或 25)。locate_for_runtime(configured, environment, os, arch, runtime_java_version):在未显式指定 JDT LS 目录时,优先选择当前jdtls-runtime版本可满足其minimum_java_version的 JDT LS 安装;若所有候选安装均高于当前 runtime,则回退到第一个候选安装,由启动校验报出该安装所需的准确 Java 版本。backend/src/launch.rs:runtime_too_old_message(minimum_java_version)与check_server_runtime_for(request, minimum_java_version):按目标ServerInstallation.minimum_java_version校验jdtls-runtime版本,不满足时在启动进程前直接返回launch.runtime_too_old并提示该 JDT LS 实际要求的最低 JDK 版本(例如The Eclipse JDT Language Server requires JDK 25 or newer...),避免盲目拉起 JDT LS 后以 OSGi exit code 13 早退。resolve_launch_function传入server_runtime_feature(&request)调用jdtls::locate_for_runtime。backend/src/jdtls.rs:新增bundle_manifests_report_the_java_release_the_installation_requires单测,验证JavaSE-25/version=21清单解析,以及locate_for_runtime在 JDK 21、JDK 25、JDK 17 下的优选与回退行为。backend/src/launch.rs:扩展a_runtime_older_than_java_21_is_refused_before_anything_is_written,覆盖要求 Java 25 的 JDT LS 在 JDK 21 下被拒绝并返回 JDK 25 提示、在 JDK 25 下放行的场景。backend/tests/repository_pins.rs:断言jdtls-runtime的version.pattern仅匹配 21+,且discovery包含java的全部条目及.vscode/.cursorredhat.java-*/jre/*(总数<= 16)。README.md与docs/feature-matrix.md。不在本 PR 范围内 / Out of scope
类型专属:fix
复现与根因
PATH默认java为1.8.0_301,系统同时装有 JDK 21 和 VS Coderedhat.java-1.58.0(含server/JDT LS 1.63.0 与jre/25.0.4.1);工具链保持「自动」时因PATHJava 8 命中jdtls-runtime报launch.runtime_too_old;手动把JDK for JDT LS设为 JDK 21 后,JDT LS 1.63.0 启动约 4 秒后因JavaSE-25未满足退出(exit code 13,host.exitedEarly)。jdtls-runtime自动跳过PATH上低于 21 的 Java 并发现系统 JDK 21+ 及redhat.java扩展自带的 JRE;当用户所选 JDK 低于目标 JDT LS 要求的 Java 版本(如 25)时,在启动前直接报出准确所需的 JDK 版本。git log -S或git blame查):46d04d2(v3.0.0改用用户安装的 JDT LS 与jdtls-runtime工具时,jdtls-runtime复用了java的全版本正则和发现列表,且硬编码最低版本为 21)。plugin.json与 Rust 后端)。检查项
backend/src/jdtls.rs(bundle_manifests_report_the_java_release_the_installation_requires)、backend/src/launch.rs(a_runtime_older_than_java_21_is_refused_before_anything_is_written)、backend/tests/repository_pins.rs(the_users_jdt_ls_runs_on_the_declared_runtime_tool).agents/notes/implemented/bug-fix/记录:本仓库为独立插件仓库,约束与契约测试已固化在backend/tests/repository_pins.rs范围检查 / Scope checks
功能矩阵 / Feature matrix
docs/feature-matrix.md(未在宿主仓库新建具体插件条目)插件归属 / Plugin ownership
Lithe-IDEA/lithe-plugin-java仓库内维护,宿主与 Core 零具体插件依赖UI 验证 / UI evidence
N/A:本 PR 只涉及
plugin.json工具发现规则与后端 JDT LS 启动前校验,无插件 UI 布局变化。统一日志系统 / Structured logging
launch.runtime_too_old受控错误码与 SDK 自动记录,一个操作只有一条终态,不写 stderr,不记录路径或用户内容界面文案 / i18n
shared/i18n/逻辑归属 / Logic placement
MANIFEST.MF的JavaSE-<N>要求解析属于 Java 插件领域逻辑,放在插件 Rust 后端backend/src/jdtls.rs与backend/src/launch.rs性能与内存 / Performance and memory
java.resolveLaunch启动语言服务器时读取目标 JDT LS 目录中最多 5 个核心 bundle JAR 的META-INF/MANIFEST.MF(每个上限 64 KiB),无后台轮询或常驻内存增长设置 / Settings
N/A:未新增或移动设置页。
插件契约 / Plugin contract
N/A:未修改 Rust Core 插件契约或宿主方法,
plugin.json严格遵守现有toolDefinitions契约限制(discovery共 16 条,<= 16)。发行包与资源 / Bundle and resources
无用代码与重构 / Dead code and refactoring
RUNTIME_TOO_OLD_MESSAGE已改为按所需版本生成的runtime_too_old_message(minimum_java_version),无残留无用代码refactor标签的 Issue,没有在本 PR 顺手处理:未发现额外无用代码验证 / Verification
cargo fmt --all --checkcargo clippy --workspace --all-targets -- -D warningscargo test --workspacelithe-java-backend130 项 +repository_pins10 项 +lithe-java-domain282 项全绿)node --test --test-timeout=60000 scripts/package/*.test.mjsnode --test --test-timeout=15000 scripts/compiler/process.test.mjs未能执行的检查和原因:
提交前确认 / Final checks
main创建;目标分支:feat、fix、docs 为main,release 以发布流程要求为准.build/、target/、dist/、.artifacts/等产物,没有凭据、个人路径和未脱敏的日志或截图