@trim21/personal-pi-extensions 0.0.354 → 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 +1 -1
- package/src/aft/tools.ts +22 -1
- package/src/lib/lsp/client.ts +12 -0
package/package.json
CHANGED
package/src/aft/tools.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import { readFileSync } from "node:fs";
|
|
9
9
|
import { stat } from "node:fs/promises";
|
|
10
10
|
import { homedir } from "node:os";
|
|
11
|
-
import { isAbsolute, join, relative, resolve } from "node:path";
|
|
11
|
+
import { basename, isAbsolute, join, relative, resolve } from "node:path";
|
|
12
12
|
import { fileURLToPath } from "node:url";
|
|
13
13
|
|
|
14
14
|
import {
|
|
@@ -63,6 +63,16 @@ export function formatDisplayPath(cwd: string, filePath: string): string {
|
|
|
63
63
|
return filePath;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
+
/** subtitle 中路径的最大显示长度,超过时退化为仅文件名。 */
|
|
67
|
+
export const MAX_SUBTITLE_PATH_LENGTH = 20;
|
|
68
|
+
|
|
69
|
+
/** subtitle 用的显示路径:优先 `./…` / `~/…` / 绝对路径,结果过长时只显示文件名。 */
|
|
70
|
+
export function formatSubtitlePath(cwd: string, filePath: string): string {
|
|
71
|
+
const display = formatDisplayPath(cwd, filePath);
|
|
72
|
+
if (display.length <= MAX_SUBTITLE_PATH_LENGTH) return display;
|
|
73
|
+
return basename(filePath);
|
|
74
|
+
}
|
|
75
|
+
|
|
66
76
|
export interface AftToolContext {
|
|
67
77
|
cwd: string;
|
|
68
78
|
pool: AftTransportPool;
|
|
@@ -150,6 +160,8 @@ export function registerOutlineTool(pi: ExtensionAPI, ctx: AftToolContext): void
|
|
|
150
160
|
if (filesMode) rawArgs.files = true;
|
|
151
161
|
if (params.includeTests !== undefined) rawArgs.includeTests = params.includeTests;
|
|
152
162
|
|
|
163
|
+
const subtitle = buildOutlineSubtitle(extCtx.cwd, target);
|
|
164
|
+
|
|
153
165
|
const { text, response } = await callAftTool(bridgeFor(ctx), "outline", rawArgs, extCtx);
|
|
154
166
|
const truncated = response.truncated === true;
|
|
155
167
|
return {
|
|
@@ -157,12 +169,21 @@ export function registerOutlineTool(pi: ExtensionAPI, ctx: AftToolContext): void
|
|
|
157
169
|
details: {
|
|
158
170
|
truncated,
|
|
159
171
|
params,
|
|
172
|
+
pendant: {
|
|
173
|
+
title: "aft_outline",
|
|
174
|
+
subtitle,
|
|
175
|
+
} satisfies ToolPendant,
|
|
160
176
|
},
|
|
161
177
|
};
|
|
162
178
|
},
|
|
163
179
|
});
|
|
164
180
|
}
|
|
165
181
|
|
|
182
|
+
/** 构建 aft_outline pendant 的 subtitle:`target="…"`(路径过长时只显示文件名)。 */
|
|
183
|
+
export function buildOutlineSubtitle(cwd: string, target: string): string {
|
|
184
|
+
return `target="${formatSubtitlePath(cwd, resolvePathArg(cwd, target))}"`;
|
|
185
|
+
}
|
|
186
|
+
|
|
166
187
|
const ZoomParams = Type.Object(
|
|
167
188
|
{
|
|
168
189
|
path: Type.String({ description: "文件路径(绝对或相对项目根)" }),
|
package/src/lib/lsp/client.ts
CHANGED
|
@@ -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
|
},
|