Skip to content

Commit ba8c5fb

Browse files
committed
fix(java): refresh actions after progressive project imports
1 parent 935b887 commit ba8c5fb

4 files changed

Lines changed: 99 additions & 27 deletions

File tree

‎README.md‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
> 需要同时包含 Lithe 客户端的动作注册解码、动作刷新与首次调试加载修复;未修改这些行为的旧 preview 不能直接使用本包。
77
> 插件只在 Java 文件/调试被使用时激活,不再在打开任何工作区时启动。
88
> 运行动作等到 JDT 就绪才注册,复用设置会话已有的代际保护;编译报错时拒绝启动旧 class。
9+
> 渐进导入的后续模块还会发送 ProjectsImported / ClasspathUpdated / ProjectsDeleted,插件按事件刷新动作,
10+
> 不把首次 ServiceReady 当成所有模块已导入;旧服务器或工作区代际的迟到通知会被丢弃。
911
> 当前宿主未提供 `workspace/findFiles`,因此暂不提供控制台堆栈链接,不申请无效的搜索权限。
1012
> 下文旧客户端/API 版本与发布说明是历史背景,不代表当前 Viva 已验收。
1113
@@ -77,12 +79,22 @@ JUnit 的 Maven goal 也不代表 Java 插件的每一种行内测试运行器
7779
原 Java 5 配置可用。Java 8/11 运行时由 `LITHE_TEST_JAVA8_HOME`、`LITHE_TEST_JAVA11_HOME` 提供,测试
7880
会核对 class 目标版本与实际 JVM,不从 JDT 使用的随包 JDK 推断项目运行时。
7981

82+
| 历史源码基线 | 原 Java 5 POM | 仅在副本把 source/target 改为 1.8 |
83+
| --- | --- | --- |
84+
| Commons CLI 1.3.1,`41d3dbf00f3e2041f5e407b9b96d8f048ab388d9` | Maven 编译/补全通过,Run/Debug 被拒绝 | 补全、编译、API 验证 main、断点变量、继续/停止通过,22.13 秒 |
85+
| Joda-Time 2.3,`b0fcbb950326cbb47452670de9e666ca119ef53d` | Maven 编译/补全通过,Run/Debug 被拒绝 | 同上,23.71 秒 |
86+
87+
两者都增加了调用真实项目 API 的验证入口;未声称运行了原项目的完整应用、所有测试或时区数据生成。
88+
下载源码保持只读,未把第三方源码、产物或用户路径提交到客户端。
89+
8090
正常关闭时宿主仍可能通过 `destroyServer` 的预期拒绝重试等待退出,产生多条 WARN;本轮未观察到
8191
进程残留,已有独立重构单 [Lithe-IDEA #1860](https://github.com/1lck/Lithe-IDEA/issues/1860)。
8292

8393
2026-11-13 本地结果:最终 arm64 ZIP 连续三轮上述完整流程通过,分别 18.54、18.23、19.20 秒。
8494
每轮隔离安装和工作区,但 Maven 依赖缓存与系统文件缓存没有清空;这不是首次联网下载或长期压力测试。
85-
插件 371 项 Rust 测试、客户端全量 Go 测试/`vet`、5 项定向竞态回归通过。
95+
初轮插件 371 项 Rust 测试、客户端全量 Go 测试/`vet`、5 项定向竞态回归通过;
96+
扩展测试发现渐进导入动作刷新遗漏,补上事件驱动刷新和服务器代际校验后,Rust 372 项通过,
97+
真实含中文空格路径的跨模块工程连续五轮完整流程通过。修复前的偶发失败保留在验证记录中,不能只报告重跑成功。
8698
小工程导入后的 JDT 进程树 RSS 约 0.8 GiB,是单点观测,不是峰值或客户端总内存。
8799

88100
本轮清单的 API 和能力版本均为 0,插件归属仍为社区普通插件。权限用途如下;保留的测试、生成器、

‎backend/src/run.rs‎

Lines changed: 63 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -391,18 +391,25 @@ impl RunSession {
391391
.ok();
392392
}
393393

394-
/// Re-registers the actions binding of a context whose language server
395-
/// just became ready, so the host collects the actions of the open
396-
/// documents again.
397-
///
398-
/// The host collects once when a binding is registered and then only on
399-
/// edits. The first registration runs right after `initialize`, while JDT
400-
/// LS is still starting, so that collection answers no actions; without
401-
/// this the gutter stays empty until the user edits the file.
394+
/// Refreshes open-document actions after readiness or a JDT project-model
395+
/// change. Progressive imports can finish additional modules after
396+
/// ServiceReady, so readiness alone is not the last collection boundary.
402397
pub fn did_receive_notification(&self, params: &Value, report: &dyn Fn(&str, u64)) {
403-
let Some(context_id) = service_ready_context(params) else {
398+
let Some(context_id) = action_refresh_context(params) else {
399+
return;
400+
};
401+
let Ok(reference) = WorkspaceContext::from_value(&params["context"]) else {
402+
return;
403+
};
404+
let Some(generation) = params.get("generation").and_then(Value::as_u64) else {
404405
return;
405406
};
407+
if !self
408+
.settings
409+
.accepts_server_notification(&reference, generation)
410+
{
411+
return;
412+
}
406413
if let Some(stale) = lock(&self.registrations).remove(&context_id) {
407414
let _ = stale.subscription.dispose();
408415
}
@@ -1111,17 +1118,27 @@ fn failure(code: &'static str, message: impl Into<String>) -> FunctionError {
11111118
PluginError::new(code, message).into()
11121119
}
11131120

1114-
/// The context ID of a forwarded `language/status` `ServiceReady` of the
1115-
/// `java` server, `None` for every other notification.
1116-
fn service_ready_context(params: &Value) -> Option<String> {
1117-
if params.get("serverID").and_then(Value::as_str) != Some(SERVER_ID)
1118-
|| params.get("method").and_then(Value::as_str) != Some(LANGUAGE_STATUS_METHOD)
1119-
|| params
1120-
.get("params")
1121-
.and_then(|status| status.get("type"))
1122-
.and_then(Value::as_str)
1123-
!= Some(SERVICE_READY_TYPE)
1124-
{
1121+
/// The context of a JDT readiness or project/classpath change. Other semantic
1122+
/// notifications do not invalidate run markers. Accept both upstream enum
1123+
/// names and their published numeric values without inspecting project data.
1124+
fn action_refresh_context(params: &Value) -> Option<String> {
1125+
if params.get("serverID").and_then(Value::as_str) != Some(SERVER_ID) {
1126+
return None;
1127+
}
1128+
let refresh = match params.get("method").and_then(Value::as_str) {
1129+
Some(LANGUAGE_STATUS_METHOD) => {
1130+
params.pointer("/params/type").and_then(Value::as_str) == Some(SERVICE_READY_TYPE)
1131+
}
1132+
Some("language/eventNotification") => {
1133+
let event = &params["params"]["eventType"];
1134+
matches!(
1135+
event.as_str(),
1136+
Some("ClasspathUpdated" | "ProjectsImported" | "ProjectsDeleted")
1137+
) || matches!(event.as_u64(), Some(100 | 200 | 210))
1138+
}
1139+
_ => false,
1140+
};
1141+
if !refresh {
11251142
return None;
11261143
}
11271144
WorkspaceContext::from_value(&params["context"])
@@ -1146,15 +1163,15 @@ mod tests {
11461163
}
11471164

11481165
#[test]
1149-
fn only_a_service_ready_status_of_the_java_server_names_its_context() {
1166+
fn a_service_ready_status_of_the_java_server_names_its_context() {
11501167
let ready = json!({
11511168
"context": {"contextID": "ctx-1", "generation": 3},
11521169
"serverID": SERVER_ID,
11531170
"generation": 2,
11541171
"method": LANGUAGE_STATUS_METHOD,
11551172
"params": {"type": SERVICE_READY_TYPE, "message": "ServiceReady"},
11561173
});
1157-
assert_eq!(service_ready_context(&ready).as_deref(), Some("ctx-1"));
1174+
assert_eq!(action_refresh_context(&ready).as_deref(), Some("ctx-1"));
11581175
let mut other_server = ready.clone();
11591176
other_server["serverID"] = json!("kotlin");
11601177
let mut other_method = ready.clone();
@@ -1166,7 +1183,30 @@ mod tests {
11661183
let mut no_context = ready.clone();
11671184
no_context.as_object_mut().unwrap().remove("context");
11681185
for value in [other_server, other_method, starting, no_params, no_context] {
1169-
assert_eq!(service_ready_context(&value), None, "{value}");
1186+
assert_eq!(action_refresh_context(&value), None, "{value}");
1187+
}
1188+
}
1189+
1190+
#[test]
1191+
fn progressive_import_and_classpath_changes_refresh_actions() {
1192+
for event in [
1193+
json!("ProjectsImported"),
1194+
json!("ClasspathUpdated"),
1195+
json!("ProjectsDeleted"),
1196+
json!(100),
1197+
json!(200),
1198+
json!(210),
1199+
] {
1200+
let notification = json!({
1201+
"context": {"contextID":"ctx-1", "generation":1},
1202+
"serverID":SERVER_ID, "generation":1,
1203+
"method":"language/eventNotification", "params":{"eventType":event, "data":[]},
1204+
});
1205+
assert_eq!(
1206+
action_refresh_context(&notification).as_deref(),
1207+
Some("ctx-1"),
1208+
"{event}"
1209+
);
11701210
}
11711211
}
11721212

‎backend/src/settings_session.rs‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,10 +535,26 @@ impl SettingsSession {
535535

536536
/// Action collection must not call JDT before its authoritative running event.
537537
pub(crate) fn server_is_running(&self, context: &WorkspaceContext) -> bool {
538+
self.running_server_generation(context).is_some()
539+
}
540+
541+
/// A delayed notification from a stopped/replaced process cannot refresh
542+
/// actions belonging to a new process or a new workspace generation.
543+
pub(crate) fn accepts_server_notification(
544+
&self,
545+
context: &WorkspaceContext,
546+
generation: u64,
547+
) -> bool {
548+
self.running_server_generation(context) == Some(generation)
549+
}
550+
551+
fn running_server_generation(&self, context: &WorkspaceContext) -> Option<u64> {
538552
self.lock_states()
539553
.get(context.context_id())
540-
.is_some_and(|state| {
541-
state.context.generation() == context.generation() && state.is_running()
554+
.filter(|state| state.context.generation() == context.generation())
555+
.and_then(|state| match state.seen {
556+
Some((generation, ServerPhase::Running)) => Some(generation),
557+
_ => None,
542558
})
543559
}
544560

@@ -1002,13 +1018,17 @@ mod tests {
10021018
assert!(!session.server_is_running(&workspace()));
10031019
session.did_change_state(&java("running", 1), &quiet);
10041020
assert!(session.server_is_running(&workspace()));
1021+
assert!(session.accepts_server_notification(&workspace(), 1));
10051022
session.did_change_state(&java("stopped", 1), &quiet);
10061023
session.did_change_state(&java("running", 1), &quiet);
10071024
assert!(!session.server_is_running(&workspace()));
10081025
session.did_change_state(&java("running", 2), &quiet);
10091026
assert!(session.server_is_running(&workspace()));
1027+
assert!(!session.accepts_server_notification(&workspace(), 1));
1028+
assert!(session.accepts_server_notification(&workspace(), 2));
10101029
let replaced = WorkspaceContext::new("ctx-1", 2).unwrap();
10111030
assert!(!session.server_is_running(&replaced));
1031+
assert!(!session.accepts_server_notification(&replaced, 2));
10121032
}
10131033

10141034
#[test]

‎backend/tests/session.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl Host {
8989
}
9090

9191
/// Sends `initialize` as a host that offers plugin functions and
92-
/// `litheLogging` 1, and returns the answer.
92+
/// `litheLogging` 0, and returns the answer.
9393
fn initialize(&mut self) -> Value {
9494
self.request(
9595
0,

0 commit comments

Comments
 (0)