@trim21/personal-pi-extensions 0.1.652 → 0.1.653
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/tool-services.ts +17 -1
package/package.json
CHANGED
package/src/lib/tool-services.ts
CHANGED
|
@@ -44,11 +44,19 @@ export function createToolServices(pi: ExtensionAPI, options?: ToolServicesOptio
|
|
|
44
44
|
runtime.setup(pi);
|
|
45
45
|
|
|
46
46
|
let delegate: ((service: LspService) => void) | undefined;
|
|
47
|
+
// manager 的 session_start handler 注册在入口的注册回调之前(入口须先知道本会话
|
|
48
|
+
// 的模型才能选出工具集),所以它触发 onEnabled 时 delegate 往往还没就位。先缓存
|
|
49
|
+
// 服务,等 setLspEnabledHandler 调用时立即补发,注册不再依赖两者的先后顺序。
|
|
50
|
+
let pendingService: LspService | undefined;
|
|
47
51
|
const manager = createLspManager(
|
|
48
52
|
pi,
|
|
49
53
|
{
|
|
50
54
|
onEnabled: (_pi, service) => {
|
|
51
|
-
delegate
|
|
55
|
+
if (delegate) {
|
|
56
|
+
delegate(service);
|
|
57
|
+
} else {
|
|
58
|
+
pendingService = service;
|
|
59
|
+
}
|
|
52
60
|
},
|
|
53
61
|
},
|
|
54
62
|
options,
|
|
@@ -60,6 +68,14 @@ export function createToolServices(pi: ExtensionAPI, options?: ToolServicesOptio
|
|
|
60
68
|
manager,
|
|
61
69
|
setLspEnabledHandler(handler) {
|
|
62
70
|
delegate = handler;
|
|
71
|
+
if (!handler) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const pending = pendingService;
|
|
75
|
+
pendingService = undefined;
|
|
76
|
+
if (pending) {
|
|
77
|
+
handler(pending);
|
|
78
|
+
}
|
|
63
79
|
},
|
|
64
80
|
};
|
|
65
81
|
}
|