@trim21/personal-pi-extensions 0.0.355 → 0.0.356

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trim21/personal-pi-extensions",
3
- "version": "0.0.355",
3
+ "version": "0.0.356",
4
4
  "type": "module",
5
5
  "description": "Custom pi coding-agent extensions: bwrap sandbox, workspace guard, opencode edit, and more",
6
6
  "keywords": [
@@ -210,6 +210,8 @@ export async function create(input: CreateInput): Promise<LspClient> {
210
210
  const diagnosticRegistrations = new Map<string, CapabilityRegistration>();
211
211
  const registrationListeners = new Set<() => void>();
212
212
  const diagnosticListeners = new Set<(input: { path: string; serverID: string }) => void>();
213
+ /** resolvedPath → 客户端已发送的最新文档版本(didOpen=0,didChange 递增)。 */
214
+ const documentVersions = new Map<string, number>();
213
215
  const mergedDiagnostics = (filePath: string): Diagnostic[] =>
214
216
  dedupeDiagnostics([
215
217
  ...(pushDiagnostics.get(filePath) ?? []),
@@ -234,6 +236,14 @@ export async function create(input: CreateInput): Promise<LspClient> {
234
236
  (params: { uri: string; version?: number; diagnostics: Diagnostic[] }) => {
235
237
  const filePath = getFilePath(params.uri);
236
238
  if (!filePath) return;
239
+ // 服务器版本滞后于已发送版本时,该 push 对应的是旧内容(重算未完成时的
240
+ // 迟到结果)。忽略它,避免与 pull 通道的当前结果合并出 stale 诊断。
241
+ const currentVersion = documentVersions.get(filePath);
242
+ const isStalePush =
243
+ typeof params.version === "number" &&
244
+ currentVersion !== undefined &&
245
+ params.version !== currentVersion;
246
+ if (isStalePush) return;
237
247
  published.set(filePath, {
238
248
  at: Date.now(),
239
249
  version: typeof params.version === "number" ? params.version : undefined,
@@ -652,6 +662,7 @@ export async function create(input: CreateInput): Promise<LspClient> {
652
662
 
653
663
  const next = document.version + 1;
654
664
  files[resolvedPath] = { version: next, text };
665
+ documentVersions.set(resolvedPath, next);
655
666
  await connection.sendNotification("textDocument/didChange", {
656
667
  textDocument: { uri, version: next },
657
668
  contentChanges:
@@ -677,6 +688,7 @@ export async function create(input: CreateInput): Promise<LspClient> {
677
688
  textDocument: { uri, languageId, version: 0, text },
678
689
  });
679
690
  files[resolvedPath] = { version: 0, text };
691
+ documentVersions.set(resolvedPath, 0);
680
692
  return 0;
681
693
  },
682
694
  },