@trim21/personal-pi-extensions 0.1.508 → 0.1.509
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/lib/lsp/lsp.ts +24 -5
package/package.json
CHANGED
package/src/lib/lsp/lsp.ts
CHANGED
|
@@ -1039,14 +1039,29 @@ export function createLspManager(
|
|
|
1039
1039
|
const config = await loadLspConfig(ctx.cwd, options?.globalConfigPath);
|
|
1040
1040
|
validateConfig(config, options?.adapters);
|
|
1041
1041
|
if (enabledServerCount(config, options?.adapters) === 0) return;
|
|
1042
|
+
// 下面两个闭包被 service 长期持有,可能在会话被替换或 reload 后仍触发
|
|
1043
|
+
// (session_shutdown 清理、后台 watcher 错误、in-flight spawn 失败),
|
|
1044
|
+
// 而旧 ctx 已被 pi 标记 stale,ctx.ui getter 会直接抛错。UI 写入是尽力
|
|
1045
|
+
// 而为的上报,stale 时静默跳过——抛错逃逸会变成 unhandled rejection,
|
|
1046
|
+
// pi 会因此整个退出。
|
|
1042
1047
|
const next = createLspService(options?.adapters, options?.globalConfigPath, {
|
|
1043
1048
|
// 会话级通知:任何通道触发的启动失败都主动上报(不只依赖请求方 notify)
|
|
1044
|
-
notify: (message, level) =>
|
|
1049
|
+
notify: (message, level) => {
|
|
1050
|
+
try {
|
|
1051
|
+
ctx.ui.notify(message, level);
|
|
1052
|
+
} catch {
|
|
1053
|
+
/* 旧会话 ctx 已失效或 UI 不可用:通知无处可去 */
|
|
1054
|
+
}
|
|
1055
|
+
},
|
|
1045
1056
|
});
|
|
1046
1057
|
// footer status 显示当前所有 LSP server 状态(无 UI 时不显示)
|
|
1047
|
-
next.attachStatus((text) =>
|
|
1048
|
-
|
|
1049
|
-
|
|
1058
|
+
next.attachStatus((text) => {
|
|
1059
|
+
try {
|
|
1060
|
+
ctx.ui.setStatus("lsp", text ? ctx.ui.theme.fg("accent", text) : undefined);
|
|
1061
|
+
} catch {
|
|
1062
|
+
/* 旧会话 ctx 已失效:footer 不再属于本 service */
|
|
1063
|
+
}
|
|
1064
|
+
});
|
|
1050
1065
|
service = next;
|
|
1051
1066
|
hooks.onEnabled(pi, next);
|
|
1052
1067
|
} catch (error) {
|
|
@@ -1056,7 +1071,11 @@ export function createLspManager(
|
|
|
1056
1071
|
});
|
|
1057
1072
|
|
|
1058
1073
|
pi.on("session_shutdown", () => {
|
|
1059
|
-
|
|
1074
|
+
// 关停阶段 UI 已不可用(可能恰逢会话替换、旧 ctx 已 stale),清理失败
|
|
1075
|
+
// 无处上报,静默吞掉以避免 unhandled rejection 致 pi 退出
|
|
1076
|
+
void service?.shutdownAll().catch(() => {
|
|
1077
|
+
/* noop */
|
|
1078
|
+
});
|
|
1060
1079
|
});
|
|
1061
1080
|
|
|
1062
1081
|
// agent 生命周期边界显式刷新 status:agent 运行中 LSP server 才被惰性
|