@trim21/personal-pi-extensions 0.0.356 → 0.0.357
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 +19 -3
package/package.json
CHANGED
package/src/lib/lsp/client.ts
CHANGED
|
@@ -236,8 +236,11 @@ export async function create(input: CreateInput): Promise<LspClient> {
|
|
|
236
236
|
(params: { uri: string; version?: number; diagnostics: Diagnostic[] }) => {
|
|
237
237
|
const filePath = getFilePath(params.uri);
|
|
238
238
|
if (!filePath) return;
|
|
239
|
-
//
|
|
240
|
-
//
|
|
239
|
+
// 支持 pull 诊断的服务器:push 的结果可能来自旧内容(异步重算迟到),
|
|
240
|
+
// 直接忽略,只信任 pull 返回的当前文档结果,从源头避免 stale。
|
|
241
|
+
if (supportsPullDiagnostics()) return;
|
|
242
|
+
// 纯 push 服务器:服务器版本滞后于已发送版本时,该 push 对应的是旧内容
|
|
243
|
+
// (重算未完成时的迟到结果),同样忽略。
|
|
241
244
|
const currentVersion = documentVersions.get(filePath);
|
|
242
245
|
const isStalePush =
|
|
243
246
|
typeof params.version === "number" &&
|
|
@@ -416,6 +419,15 @@ export async function create(input: CreateInput): Promise<LspClient> {
|
|
|
416
419
|
return { handled: true, matched, byFile };
|
|
417
420
|
}
|
|
418
421
|
|
|
422
|
+
/** 是否支持文档级 pull 诊断:静态 diagnosticProvider 或动态注册的 document 诊断。 */
|
|
423
|
+
function supportsPullDiagnostics(): boolean {
|
|
424
|
+
if (hasStaticPullDiagnostics) return true;
|
|
425
|
+
for (const registration of diagnosticRegistrations.values()) {
|
|
426
|
+
if (registration.registerOptions?.workspaceDiagnostics !== true) return true;
|
|
427
|
+
}
|
|
428
|
+
return false;
|
|
429
|
+
}
|
|
430
|
+
|
|
419
431
|
function documentPullState() {
|
|
420
432
|
const documentRegistrations = [...diagnosticRegistrations.values()].filter(
|
|
421
433
|
(registration) => registration.registerOptions?.workspaceDiagnostics !== true,
|
|
@@ -424,7 +436,7 @@ export async function create(input: CreateInput): Promise<LspClient> {
|
|
|
424
436
|
documentIdentifiers: [
|
|
425
437
|
...new Set(documentRegistrations.flatMap((r) => r.registerOptions?.identifier ?? [])),
|
|
426
438
|
],
|
|
427
|
-
supported:
|
|
439
|
+
supported: supportsPullDiagnostics(),
|
|
428
440
|
};
|
|
429
441
|
}
|
|
430
442
|
|
|
@@ -589,6 +601,9 @@ export async function create(input: CreateInput): Promise<LspClient> {
|
|
|
589
601
|
while (Date.now() - startedAt < diagnosticsDocumentWaitTimeoutMs) {
|
|
590
602
|
const result = await requestDocumentDiagnostics(request.path);
|
|
591
603
|
if (result.matched) return;
|
|
604
|
+
// 支持 pull 的服务器:pull 未匹配(失败/超时)即返回,不依赖 push 兜底
|
|
605
|
+
// (push 已被忽略);纯 push 服务器继续走下面的 push 等待。
|
|
606
|
+
if (supportsPullDiagnostics()) return;
|
|
592
607
|
const remaining = diagnosticsDocumentWaitTimeoutMs - (Date.now() - startedAt);
|
|
593
608
|
if (remaining <= 0) return;
|
|
594
609
|
const next = await Promise.race([
|
|
@@ -617,6 +632,7 @@ export async function create(input: CreateInput): Promise<LspClient> {
|
|
|
617
632
|
while (Date.now() - startedAt < diagnosticsFullWaitTimeoutMs) {
|
|
618
633
|
const result = await requestFullDiagnostics(request.path);
|
|
619
634
|
if (result.handled || result.matched) return;
|
|
635
|
+
if (supportsPullDiagnostics()) return;
|
|
620
636
|
const remaining = diagnosticsFullWaitTimeoutMs - (Date.now() - startedAt);
|
|
621
637
|
if (remaining <= 0) return;
|
|
622
638
|
const next = await Promise.race([
|