@trim21/personal-pi-extensions 0.1.642 → 0.1.643
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/client.ts +23 -11
- package/src/lib/lsp/lsp.ts +32 -39
package/package.json
CHANGED
package/src/lib/lsp/client.ts
CHANGED
|
@@ -282,21 +282,33 @@ export const clientDefaults = {
|
|
|
282
282
|
maxOpenDocuments: 32,
|
|
283
283
|
} as const;
|
|
284
284
|
|
|
285
|
-
|
|
285
|
+
/**
|
|
286
|
+
* 客户端可调项的唯一定义:`create()` 的覆盖参数、`lsp.ts` 的 `ResolvedLspConfig`
|
|
287
|
+
* 与 `resolveConfig` 共用同一份字段集合,新增旋钮只需在这里声明一次即可被
|
|
288
|
+
* 配置解析与客户端构造同时要求。超时均为解析后的毫秒数,缺省值见 clientDefaults。
|
|
289
|
+
*/
|
|
290
|
+
export interface LspClientOptions {
|
|
291
|
+
/** push 诊断去抖(ms)。 */
|
|
292
|
+
diagnosticsDebounceMs: number;
|
|
293
|
+
/** document 模式诊断等待上限(ms)。 */
|
|
294
|
+
diagnosticsDocumentWaitTimeoutMs: number;
|
|
295
|
+
/** 上一份诊断为空的文档的等待上限(ms);缺省见 clientDefaults。 */
|
|
296
|
+
diagnosticsSilentWaitTimeoutMs: number;
|
|
297
|
+
/** full 模式诊断等待上限(ms)。 */
|
|
298
|
+
diagnosticsFullWaitTimeoutMs: number;
|
|
299
|
+
/** 单次 pull 诊断请求超时(ms)。 */
|
|
300
|
+
diagnosticsRequestTimeoutMs: number;
|
|
301
|
+
/** 服务器 initialize 握手超时(ms)。 */
|
|
302
|
+
initializeTimeoutMs: number;
|
|
303
|
+
/** 驻留文档上限(LRU 容量,缺省 32);超过时淘汰最久未使用并 didClose。 */
|
|
304
|
+
maxOpenDocuments: number;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
export interface CreateInput extends Partial<LspClientOptions> {
|
|
286
308
|
serverID: string;
|
|
287
309
|
server: LspServerHandle;
|
|
288
310
|
root: string;
|
|
289
311
|
directory: string;
|
|
290
|
-
/** 可覆盖的超时参数(缺省用 client 默认值,由全局/本地 lsp.json 配置注入)。 */
|
|
291
|
-
diagnosticsDebounceMs?: number;
|
|
292
|
-
diagnosticsDocumentWaitTimeoutMs?: number;
|
|
293
|
-
/** 上一份诊断为空的文档的等待上限;缺省见 clientDefaults。 */
|
|
294
|
-
diagnosticsSilentWaitTimeoutMs?: number;
|
|
295
|
-
diagnosticsFullWaitTimeoutMs?: number;
|
|
296
|
-
diagnosticsRequestTimeoutMs?: number;
|
|
297
|
-
initializeTimeoutMs?: number;
|
|
298
|
-
/** 驻留文档上限(LRU 容量,缺省 32);超过时淘汰最久未使用并 didClose。 */
|
|
299
|
-
maxOpenDocuments?: number;
|
|
300
312
|
/** 覆盖 rename 覆盖校验的轮询节奏(缺省见 DEFAULT_RENAME_VERIFICATION_TIMING)。 */
|
|
301
313
|
renameVerificationTiming?: Partial<RenameVerificationTiming>;
|
|
302
314
|
}
|
package/src/lib/lsp/lsp.ts
CHANGED
|
@@ -37,6 +37,7 @@ import {
|
|
|
37
37
|
type Diagnostic,
|
|
38
38
|
type Info as LspClient,
|
|
39
39
|
type InspectLocation,
|
|
40
|
+
type LspClientOptions,
|
|
40
41
|
LspMethodNotSupportedError,
|
|
41
42
|
RenameNotPossibleError,
|
|
42
43
|
WATCH_KIND_CHANGE,
|
|
@@ -68,7 +69,7 @@ const watchConfigSchema = Type.Object({
|
|
|
68
69
|
ignore: Type.Optional(Type.Array(Type.String())),
|
|
69
70
|
});
|
|
70
71
|
|
|
71
|
-
/** lsp.json 的配置项(全局与本地同构;只描述用户可写的原始形态,缺省见
|
|
72
|
+
/** lsp.json 的配置项(全局与本地同构;只描述用户可写的原始形态,缺省见 watchDefaults / clientDefaults)。 */
|
|
72
73
|
const lspConfigSchema = Type.Object({
|
|
73
74
|
/** 配置文件版本(当前 1);未知版本会被 typebox 严格校验拒绝。 */
|
|
74
75
|
version: Type.Optional(Type.Number()),
|
|
@@ -78,7 +79,7 @@ const lspConfigSchema = Type.Object({
|
|
|
78
79
|
enabled: Type.Optional(Type.Array(Type.String())),
|
|
79
80
|
/** 从启用集中排除的服务器 id(缺省 = 无)。 */
|
|
80
81
|
disabled: Type.Optional(Type.Array(Type.String())),
|
|
81
|
-
/** 工作区文件监听配置(缺省全部字段见
|
|
82
|
+
/** 工作区文件监听配置(缺省全部字段见 watchDefaults)。 */
|
|
82
83
|
watch: Type.Optional(watchConfigSchema),
|
|
83
84
|
/** 驻留文档上限(LRU 容量),超过时淘汰最久未使用并 didClose。 */
|
|
84
85
|
maxOpenDocuments: Type.Optional(Type.Number({ minimum: 1 })),
|
|
@@ -99,18 +100,12 @@ const lspConfigSchema = Type.Object({
|
|
|
99
100
|
/** 配置值(单文件解析结果);超时字段为原始写法(number 或字符串),换算在 resolveConfig。 */
|
|
100
101
|
export type LspConfig = Static<typeof lspConfigSchema>;
|
|
101
102
|
|
|
102
|
-
/**
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
enabled: true,
|
|
109
|
-
debounceMs: 300,
|
|
110
|
-
flushMs: 1_000,
|
|
111
|
-
maxBatch: 500,
|
|
112
|
-
},
|
|
113
|
-
maxOpenDocuments: clientDefaults.maxOpenDocuments,
|
|
103
|
+
/** 解析期缺省:watch 段(无 client 对应项,数值在此集中);客户端参数缺省见 clientDefaults。 */
|
|
104
|
+
const watchDefaults = {
|
|
105
|
+
enabled: true,
|
|
106
|
+
debounceMs: 300,
|
|
107
|
+
flushMs: 1_000,
|
|
108
|
+
maxBatch: 500,
|
|
114
109
|
} as const;
|
|
115
110
|
|
|
116
111
|
/** 服务器启动失败后自动重试的冷却(ms);冷却内跳过,之后下次触碰自动重试。 */
|
|
@@ -127,8 +122,12 @@ interface EffectiveWatchConfig {
|
|
|
127
122
|
ignore: string[];
|
|
128
123
|
}
|
|
129
124
|
|
|
130
|
-
/**
|
|
131
|
-
|
|
125
|
+
/**
|
|
126
|
+
* 全局 + 本地合并并解析后的生效配置:所有字段为确定值,无"未配置"歧义。
|
|
127
|
+
* 客户端参数的整体形状复用 `LspClientOptions`(定义在 client.ts,与
|
|
128
|
+
* `create()` 的覆盖参数同源),因此这里不再逐字段重声明。
|
|
129
|
+
*/
|
|
130
|
+
export interface ResolvedLspConfig extends LspClientOptions {
|
|
132
131
|
/** 合并后的服务器定义(未配置任何服务器时为空表)。 */
|
|
133
132
|
servers: Record<string, ServerConfig>;
|
|
134
133
|
/** enabled 白名单(undefined = 全部启用)。 */
|
|
@@ -137,15 +136,6 @@ export interface ResolvedLspConfig {
|
|
|
137
136
|
disabled: Set<string> | undefined;
|
|
138
137
|
/** 工作区监听配置(缺省值已应用)。 */
|
|
139
138
|
watch: EffectiveWatchConfig;
|
|
140
|
-
/** 驻留文档 LRU 容量。 */
|
|
141
|
-
maxOpenDocuments: number;
|
|
142
|
-
/** 以下超时均为换算后的毫秒数(缺省见 configDefaults / clientDefaults)。 */
|
|
143
|
-
diagnosticsDebounceMs: number;
|
|
144
|
-
diagnosticsDocumentWaitTimeoutMs: number;
|
|
145
|
-
diagnosticsSilentWaitTimeoutMs: number;
|
|
146
|
-
diagnosticsFullWaitTimeoutMs: number;
|
|
147
|
-
diagnosticsRequestTimeoutMs: number;
|
|
148
|
-
initializeTimeoutMs: number;
|
|
149
139
|
}
|
|
150
140
|
|
|
151
141
|
/** "500" → 500、"5s" → 5000、"1m" → 60000;无效字符串返回 NaN(由调用方兜底缺省)。 */
|
|
@@ -177,7 +167,7 @@ function toMs(value: number | string | undefined): number | undefined {
|
|
|
177
167
|
}
|
|
178
168
|
|
|
179
169
|
/**
|
|
180
|
-
* 把合并后的原始配置解析为生效配置:应用
|
|
170
|
+
* 把合并后的原始配置解析为生效配置:应用 watchDefaults / clientDefaults 缺省、字符串时长换算、
|
|
181
171
|
* 白名单转 Set;per-server 的 workingDir / rootMarkers 互斥校验在此完成
|
|
182
172
|
* (配置解析期抛错,与 enabled 白名单校验同层)。
|
|
183
173
|
*/
|
|
@@ -195,13 +185,13 @@ export function resolveConfig(raw: LspConfig): ResolvedLspConfig {
|
|
|
195
185
|
enabled: raw.enabled === undefined ? undefined : new Set(raw.enabled),
|
|
196
186
|
disabled: raw.disabled === undefined ? undefined : new Set(raw.disabled),
|
|
197
187
|
watch: {
|
|
198
|
-
enabled: raw.watch?.enabled ??
|
|
199
|
-
debounceMs: toMs(raw.watch?.debounceMs) ??
|
|
200
|
-
flushMs:
|
|
201
|
-
maxBatch: raw.watch?.maxBatch ??
|
|
188
|
+
enabled: raw.watch?.enabled ?? watchDefaults.enabled,
|
|
189
|
+
debounceMs: toMs(raw.watch?.debounceMs) ?? watchDefaults.debounceMs,
|
|
190
|
+
flushMs: watchDefaults.flushMs,
|
|
191
|
+
maxBatch: raw.watch?.maxBatch ?? watchDefaults.maxBatch,
|
|
202
192
|
ignore: raw.watch?.ignore ?? [],
|
|
203
193
|
},
|
|
204
|
-
maxOpenDocuments: raw.maxOpenDocuments ??
|
|
194
|
+
maxOpenDocuments: raw.maxOpenDocuments ?? clientDefaults.maxOpenDocuments,
|
|
205
195
|
diagnosticsDebounceMs: toMs(raw.diagnosticsDebounceMs) ?? clientDefaults.diagnosticsDebounceMs,
|
|
206
196
|
diagnosticsDocumentWaitTimeoutMs:
|
|
207
197
|
toMs(raw.diagnosticsDocumentWaitTimeoutMs) ?? clientDefaults.diagnosticsDocumentWaitTimeoutMs,
|
|
@@ -848,19 +838,22 @@ export function createLspService(
|
|
|
848
838
|
reportStartupFailure(key, adapter.id, root, "binary not found", notify);
|
|
849
839
|
return;
|
|
850
840
|
}
|
|
841
|
+
const overrides: Partial<LspClientOptions> = {};
|
|
842
|
+
if (adapter.diagnosticsWaitMs !== undefined) {
|
|
843
|
+
overrides.diagnosticsDocumentWaitTimeoutMs = adapter.diagnosticsWaitMs;
|
|
844
|
+
}
|
|
845
|
+
if (adapter.startupTimeoutMs !== undefined) {
|
|
846
|
+
overrides.initializeTimeoutMs = adapter.startupTimeoutMs;
|
|
847
|
+
}
|
|
851
848
|
const client = await create({
|
|
852
849
|
serverID: adapter.id,
|
|
853
850
|
server: handle,
|
|
854
851
|
root,
|
|
855
852
|
directory: cwd,
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
diagnosticsFullWaitTimeoutMs: config.diagnosticsFullWaitTimeoutMs,
|
|
861
|
-
diagnosticsRequestTimeoutMs: config.diagnosticsRequestTimeoutMs,
|
|
862
|
-
initializeTimeoutMs: adapter.startupTimeoutMs ?? config.initializeTimeoutMs,
|
|
863
|
-
maxOpenDocuments: config.maxOpenDocuments,
|
|
853
|
+
// 客户端参数整体取自生效配置(ResolvedLspConfig extends LspClientOptions),
|
|
854
|
+
// 不做逐字段搬运:新增旋钮时漏接线会静默失效,这里靠展开消除该位置。
|
|
855
|
+
...config,
|
|
856
|
+
...overrides,
|
|
864
857
|
});
|
|
865
858
|
if (state.closing || state.disabled) {
|
|
866
859
|
await client.shutdown();
|