@evandu/super-pi 0.1.326 → 0.1.327
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/README.md +13 -0
- package/dist/client/.super-pi-client-sources.json +14 -12
- package/dist/client/assets/CodeMirrorEditor-BslZa6Te.js +2 -0
- package/dist/client/assets/FileWorkbenchChrome-opMS3cZ5.js +1 -0
- package/dist/client/assets/GitDiffEditor-DrWsJi0Q.js +31 -0
- package/dist/client/assets/GitHistoricalFile-B_GSmox7.js +1 -0
- package/dist/client/assets/{dist-36Vke2EH.js → dist-B01U6Kqm.js} +1 -1
- package/dist/client/assets/dist-B7BIlMIZ.js +1 -0
- package/dist/client/assets/{dist-BCNE0i_L.js → dist-BL4zqiB3.js} +1 -1
- package/dist/client/assets/{dist-D5K62raW.js → dist-BcAL7bRJ.js} +1 -1
- package/dist/client/assets/{dist-CACYWoKG.js → dist-BkSZy41B.js} +1 -1
- package/dist/client/assets/{dist-JLvZm5Mv.js → dist-BrKx1t7U.js} +1 -1
- package/dist/client/assets/dist-BywGDVPc.js +3 -0
- package/dist/client/assets/{dist-CB-n6qyW.js → dist-C3KFCuxF.js} +1 -1
- package/dist/client/assets/{dist-CAM5m6VB.js → dist-CDLDZZr2.js} +1 -1
- package/dist/client/assets/{dist-IQ81OBbu.js → dist-CW2Zb9XN.js} +1 -1
- package/dist/client/assets/dist-CczD4z3C.js +1 -0
- package/dist/client/assets/{dist-CD0jGv9h.js → dist-CmezYegB.js} +2 -2
- package/dist/client/assets/{dist-DexiWS0i.js → dist-Cp5g1LCT.js} +1 -1
- package/dist/client/assets/{dist-DESLeVIi.js → dist-CsZ8KzbR.js} +1 -1
- package/dist/client/assets/{dist-Ch-BrJW7.js → dist-D5ttfXvN.js} +1 -1
- package/dist/client/assets/{dist-Bkr3xgoh.js → dist-D9Tp0kLx.js} +1 -1
- package/dist/client/assets/dist-DEmZaMiQ.js +23 -0
- package/dist/client/assets/{dist-1rD0ihl2.js → dist-DEwbAwCm.js} +1 -1
- package/dist/client/assets/dist-DKaZ9Fax.js +1 -0
- package/dist/client/assets/{dist-CjVRUfws.js → dist-DWnCTx3S.js} +1 -1
- package/dist/client/assets/dist-DfZq6DlC.js +2 -0
- package/dist/client/assets/{dist-C3S630Ts.js → dist-DvoNKyrD.js} +1 -1
- package/dist/client/assets/{dist-BWav58GK.js → dist-UJRxKnWM.js} +2 -2
- package/dist/client/assets/editor-code-navigation-kyvwJimV.js +1 -0
- package/dist/client/assets/index-BI_W-Q7j.js +363 -0
- package/dist/client/assets/index-BRi_VDmX.css +1 -0
- package/dist/client/assets/protobuf-D1ij_kNL.js +1 -0
- package/dist/client/index.html +3 -4
- package/dist/server/code-navigation.d.ts +36 -0
- package/dist/server/code-navigation.js +301 -0
- package/dist/server/http-server.d.ts +1 -0
- package/dist/server/http-server.js +67 -2
- package/dist/server/index.js +1 -0
- package/dist/shared/code-navigation.d.ts +25 -0
- package/dist/shared/code-navigation.js +49 -0
- package/package.json +5 -1
- package/dist/client/assets/CodeMirrorEditor-GWeu0OUL.js +0 -2
- package/dist/client/assets/GitDiffEditor-sc09J8B7.js +0 -31
- package/dist/client/assets/GitHistoricalFile-BwlKi5UX.js +0 -1
- package/dist/client/assets/dist-56GF8ANx.js +0 -1
- package/dist/client/assets/dist-DKp0_dx5.js +0 -23
- package/dist/client/assets/dist-DTem9o2m.js +0 -2
- package/dist/client/assets/dist-DcAKBmUm.js +0 -1
- package/dist/client/assets/dist-Dk-yOCN3.js +0 -3
- package/dist/client/assets/editor-blame-DcMUzRBK.js +0 -15
- package/dist/client/assets/editor-blame-PLncD0eu.css +0 -1
- package/dist/client/assets/index-BpMJTeh4.css +0 -1
- package/dist/client/assets/index-Cevzgr74.js +0 -350
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(e){return RegExp(`^((`+e.join(`)|(`)+`))\\b`,`i`)}var t=`package.message.import.syntax.required.optional.repeated.reserved.default.extensions.packed.bool.bytes.double.enum.float.string.int32.int64.uint32.uint64.sint32.sint64.fixed32.fixed64.sfixed32.sfixed64.option.service.rpc.returns`.split(`.`),n=e(t),r=RegExp(`^[_A-Za-z¡-][_A-Za-z0-9¡-]*`);function i(e){return e.eatSpace()?null:e.match(`//`)?(e.skipToEnd(),`comment`):e.match(/^[0-9\.+-]/,!1)&&(e.match(/^[+-]?0x[0-9a-fA-F]+/)||e.match(/^[+-]?\d*\.\d+([EeDd][+-]?\d+)?/)||e.match(/^[+-]?\d+([EeDd][+-]?\d+)?/))?`number`:e.match(/^"([^"]|(""))*"/)||e.match(/^'([^']|(''))*'/)?`string`:e.match(n)?`keyword`:e.match(r)?`variable`:(e.next(),null)}var a={name:`protobuf`,token:i,languageData:{autocomplete:t}};export{a as protobuf};
|
package/dist/client/index.html
CHANGED
|
@@ -8,10 +8,9 @@
|
|
|
8
8
|
<link rel="alternate icon" href="/favicon.ico" />
|
|
9
9
|
<link rel="apple-touch-icon" href="/favicon.svg" />
|
|
10
10
|
<title>Super Pi</title>
|
|
11
|
-
<script type="module" crossorigin src="/assets/index-
|
|
12
|
-
<link rel="modulepreload" crossorigin href="/assets/
|
|
13
|
-
<link rel="stylesheet" crossorigin href="/assets/
|
|
14
|
-
<link rel="stylesheet" crossorigin href="/assets/index-BpMJTeh4.css">
|
|
11
|
+
<script type="module" crossorigin src="/assets/index-BI_W-Q7j.js"></script>
|
|
12
|
+
<link rel="modulepreload" crossorigin href="/assets/FileWorkbenchChrome-opMS3cZ5.js">
|
|
13
|
+
<link rel="stylesheet" crossorigin href="/assets/index-BRi_VDmX.css">
|
|
15
14
|
</head>
|
|
16
15
|
<body>
|
|
17
16
|
<div id="root"></div>
|
|
18
17
|
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type CodeDiagnostic, type CodeLocation, type CodeNavigationKind, type CodeTextEdit } from "../shared/code-navigation.js";
|
|
2
|
+
type NavigationErrorCode = "missing_server" | "unsupported" | "unavailable" | "timeout" | "busy";
|
|
3
|
+
export declare class CodeNavigationError extends Error {
|
|
4
|
+
readonly code: NavigationErrorCode;
|
|
5
|
+
constructor(code: NavigationErrorCode);
|
|
6
|
+
}
|
|
7
|
+
export type CodeNavigationRequest = {
|
|
8
|
+
path: string;
|
|
9
|
+
} & ({
|
|
10
|
+
kind: CodeNavigationKind;
|
|
11
|
+
line: number;
|
|
12
|
+
column: number;
|
|
13
|
+
} | {
|
|
14
|
+
kind: "diagnostics";
|
|
15
|
+
} | {
|
|
16
|
+
kind: "formatting";
|
|
17
|
+
});
|
|
18
|
+
export declare class CodeNavigation {
|
|
19
|
+
private projects;
|
|
20
|
+
private closed;
|
|
21
|
+
close(): void;
|
|
22
|
+
lookup(root: string, request: CodeNavigationRequest, content: string, signal?: AbortSignal): Promise<{
|
|
23
|
+
diagnostics: CodeDiagnostic[];
|
|
24
|
+
edits?: undefined;
|
|
25
|
+
locations?: undefined;
|
|
26
|
+
} | {
|
|
27
|
+
diagnostics?: undefined;
|
|
28
|
+
edits: CodeTextEdit[];
|
|
29
|
+
locations?: undefined;
|
|
30
|
+
} | {
|
|
31
|
+
diagnostics?: undefined;
|
|
32
|
+
edits?: undefined;
|
|
33
|
+
locations: CodeLocation[];
|
|
34
|
+
}>;
|
|
35
|
+
}
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { constants } from "node:fs";
|
|
3
|
+
import { access, stat } from "node:fs/promises";
|
|
4
|
+
import { createRequire } from "node:module";
|
|
5
|
+
import { delimiter, isAbsolute, join, relative, sep } from "node:path";
|
|
6
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
7
|
+
import { createMessageConnection, StreamMessageReader, StreamMessageWriter } from "vscode-jsonrpc/node.js";
|
|
8
|
+
import { codeLanguage } from "../shared/code-navigation.js";
|
|
9
|
+
export class CodeNavigationError extends Error {
|
|
10
|
+
code;
|
|
11
|
+
constructor(code) {
|
|
12
|
+
super(code);
|
|
13
|
+
this.code = code;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
const MAX_SERVERS = 6;
|
|
17
|
+
const IDLE_MS = 3 * 60_000;
|
|
18
|
+
const integer = (value) => typeof value === "number" && Number.isSafeInteger(value);
|
|
19
|
+
function uriKey(uri) {
|
|
20
|
+
try {
|
|
21
|
+
const path = fileURLToPath(uri);
|
|
22
|
+
return process.platform === "win32" ? path.toLowerCase() : path;
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return uri;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
async function pathExecutable(command) {
|
|
29
|
+
const binary = process.platform === "win32" ? `${command}.exe` : command;
|
|
30
|
+
const pathValue = process.env.PATH ?? process.env.Path ?? "";
|
|
31
|
+
for (const candidate of pathValue.split(delimiter)) {
|
|
32
|
+
const directory = candidate.trim().replace(/^"(.*)"$/, "$1");
|
|
33
|
+
if (!isAbsolute(directory))
|
|
34
|
+
continue;
|
|
35
|
+
const executable = join(directory, binary);
|
|
36
|
+
try {
|
|
37
|
+
await access(executable, constants.X_OK);
|
|
38
|
+
if ((await stat(executable)).isFile())
|
|
39
|
+
return executable;
|
|
40
|
+
}
|
|
41
|
+
catch { /* Try the next entry on the server's PATH. */ }
|
|
42
|
+
}
|
|
43
|
+
throw new CodeNavigationError("missing_server");
|
|
44
|
+
}
|
|
45
|
+
const resolvePackage = createRequire(import.meta.url).resolve;
|
|
46
|
+
const commands = {
|
|
47
|
+
clangd: ["--background-index", "--clang-tidy", "--log=error", "-j=2"], typescript: ["--stdio"], pylsp: [], buf: ["lsp", "serve"],
|
|
48
|
+
};
|
|
49
|
+
function withDeadline(promise, ms, expire) {
|
|
50
|
+
return new Promise((resolve, reject) => {
|
|
51
|
+
const timer = setTimeout(() => { reject(new CodeNavigationError("timeout")); expire(); }, ms);
|
|
52
|
+
promise.then(value => { clearTimeout(timer); resolve(value); }, error => { clearTimeout(timer); reject(error); });
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
function locations(root, answer) {
|
|
56
|
+
const targets = new Map();
|
|
57
|
+
for (const item of (Array.isArray(answer) ? answer : answer ? [answer] : []).slice(0, 100)) {
|
|
58
|
+
const uri = item?.targetUri ?? item?.uri;
|
|
59
|
+
const start = item?.targetSelectionRange?.start ?? item?.range?.start;
|
|
60
|
+
if (typeof uri !== "string" || !start || !integer(start.line) || !integer(start.character)
|
|
61
|
+
|| start.line < 0 || start.character < 0)
|
|
62
|
+
continue;
|
|
63
|
+
try {
|
|
64
|
+
const absolute = fileURLToPath(uri);
|
|
65
|
+
const path = relative(root, absolute);
|
|
66
|
+
const inside = path && !isAbsolute(path) && path !== ".." && !path.startsWith(".." + sep);
|
|
67
|
+
const target = {
|
|
68
|
+
path: (inside ? path : absolute).split(sep).join("/"),
|
|
69
|
+
...(inside ? {} : { external: true }),
|
|
70
|
+
line: start.line + 1,
|
|
71
|
+
column: start.character + 1,
|
|
72
|
+
};
|
|
73
|
+
targets.set(JSON.stringify(target), target);
|
|
74
|
+
}
|
|
75
|
+
catch { /* The editor can only open real filesystem locations. */ }
|
|
76
|
+
}
|
|
77
|
+
return [...targets.values()];
|
|
78
|
+
}
|
|
79
|
+
function codeOffsets(content, clamp = false) {
|
|
80
|
+
const lines = content.split("\n");
|
|
81
|
+
let next = 0;
|
|
82
|
+
const starts = lines.map(line => { const offset = next; next += line.length + 1; return offset; });
|
|
83
|
+
return (position) => {
|
|
84
|
+
if (!position || !integer(position.line) || !integer(position.character))
|
|
85
|
+
return;
|
|
86
|
+
const line = lines[position.line];
|
|
87
|
+
if (line === undefined || position.character < 0)
|
|
88
|
+
return;
|
|
89
|
+
const width = line.endsWith("\r") ? line.length - 1 : line.length;
|
|
90
|
+
if (position.character <= width || clamp)
|
|
91
|
+
return starts[position.line] + Math.min(width, position.character);
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function diagnosticsFor(content, diagnostics) {
|
|
95
|
+
const offset = codeOffsets(content, true);
|
|
96
|
+
return diagnostics.slice(0, 300).flatMap(item => {
|
|
97
|
+
if ((item.severity !== 1 && item.severity !== 2) || typeof item.message !== "string")
|
|
98
|
+
return [];
|
|
99
|
+
const from = offset(item.range?.start), to = offset(item.range?.end);
|
|
100
|
+
if (from === undefined || to === undefined || to < from)
|
|
101
|
+
return [];
|
|
102
|
+
const source = [item.source, item.code].filter(value => value !== undefined && value !== "").join(" · ");
|
|
103
|
+
return [{ from, to, severity: item.severity === 1 ? "error" : "warning", message: item.message, source }];
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
class LanguageProject {
|
|
107
|
+
root;
|
|
108
|
+
provider;
|
|
109
|
+
diagnosticsOnly;
|
|
110
|
+
onClose;
|
|
111
|
+
child;
|
|
112
|
+
connection;
|
|
113
|
+
initialization;
|
|
114
|
+
version = 0;
|
|
115
|
+
diagnostic;
|
|
116
|
+
diagnosticClear;
|
|
117
|
+
tail = Promise.resolve();
|
|
118
|
+
idle;
|
|
119
|
+
queued = 0;
|
|
120
|
+
closed = false;
|
|
121
|
+
constructor(root, provider, diagnosticsOnly, onClose) {
|
|
122
|
+
this.root = root;
|
|
123
|
+
this.provider = provider;
|
|
124
|
+
this.diagnosticsOnly = diagnosticsOnly;
|
|
125
|
+
this.onClose = onClose;
|
|
126
|
+
}
|
|
127
|
+
get canEvict() { return this.queued === 0; }
|
|
128
|
+
close() {
|
|
129
|
+
if (this.closed)
|
|
130
|
+
return;
|
|
131
|
+
this.closed = true;
|
|
132
|
+
clearTimeout(this.idle);
|
|
133
|
+
clearTimeout(this.diagnostic?.first);
|
|
134
|
+
this.diagnostic?.reject(new CodeNavigationError("unavailable"));
|
|
135
|
+
this.connection?.dispose();
|
|
136
|
+
this.child?.kill();
|
|
137
|
+
this.onClose();
|
|
138
|
+
}
|
|
139
|
+
async start() {
|
|
140
|
+
const provider = this.provider;
|
|
141
|
+
const binary = provider === "typescript" ? process.execPath : await pathExecutable(provider);
|
|
142
|
+
const args = provider === "typescript" ? [resolvePackage("typescript-language-server/lib/cli.mjs"), ...commands.typescript] : commands[provider];
|
|
143
|
+
if (this.closed)
|
|
144
|
+
throw new CodeNavigationError("unavailable");
|
|
145
|
+
const child = this.child = spawn(binary, args, { cwd: this.root, windowsHide: true });
|
|
146
|
+
child.on("error", () => this.close());
|
|
147
|
+
child.once("exit", () => this.close());
|
|
148
|
+
child.stderr.resume();
|
|
149
|
+
const rpc = this.connection = createMessageConnection(new StreamMessageReader(child.stdout), new StreamMessageWriter(child.stdin));
|
|
150
|
+
rpc.onError(() => this.close());
|
|
151
|
+
rpc.onClose(() => this.close());
|
|
152
|
+
rpc.onRequest("workspace/configuration", (params) => params.items?.map(item => item.section === "formattingOptions" ? { tabSize: 4, insertSpaces: true } : null) ?? []);
|
|
153
|
+
rpc.onRequest("workspace/workspaceFolders", () => [{ uri: pathToFileURL(this.root).href, name: "Workspace" }]);
|
|
154
|
+
rpc.onRequest("window/workDoneProgress/create", () => null);
|
|
155
|
+
rpc.onRequest("client/registerCapability", () => null);
|
|
156
|
+
rpc.onNotification("textDocument/publishDiagnostics", (params) => {
|
|
157
|
+
const uri = uriKey(params.uri);
|
|
158
|
+
if (this.diagnosticClear?.uri === uri && params.diagnostics?.length === 0)
|
|
159
|
+
this.diagnosticClear.done();
|
|
160
|
+
const pending = this.diagnostic;
|
|
161
|
+
if (!pending || pending.uri !== uri || (pending.version !== params.version && !(this.diagnosticsOnly && params.version === undefined))
|
|
162
|
+
|| !Array.isArray(params.diagnostics))
|
|
163
|
+
return;
|
|
164
|
+
if (provider === "buf" && !pending.first && !params.diagnostics.some(diagnostic => diagnostic.severity === 1)) {
|
|
165
|
+
// Buf publishes parse diagnostics before its independent lint pass.
|
|
166
|
+
pending.first = setTimeout(() => pending.resolve(params.diagnostics), 1500);
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
clearTimeout(pending.first);
|
|
170
|
+
pending.resolve(params.diagnostics);
|
|
171
|
+
});
|
|
172
|
+
rpc.listen();
|
|
173
|
+
const uri = pathToFileURL(this.root).href;
|
|
174
|
+
const initialized = await withDeadline(rpc.sendRequest("initialize", {
|
|
175
|
+
processId: process.pid, rootPath: this.root, rootUri: uri, workspaceFolders: [{ uri, name: "Workspace" }],
|
|
176
|
+
...(provider === "typescript" ? { initializationOptions: { disableAutomaticTypingAcquisition: true,
|
|
177
|
+
tsserver: { path: resolvePackage("typescript-lsp-runtime/lib/tsserver.js"), useSyntaxServer: "never" } } } : {}),
|
|
178
|
+
capabilities: { general: { positionEncodings: ["utf-16"] }, workspace: { configuration: true, workspaceFolders: true },
|
|
179
|
+
textDocument: { declaration: { linkSupport: true }, definition: { linkSupport: true }, publishDiagnostics: { versionSupport: true } } },
|
|
180
|
+
}), 12_000, () => this.close());
|
|
181
|
+
if (initialized.capabilities.positionEncoding && initialized.capabilities.positionEncoding !== "utf-16")
|
|
182
|
+
throw new CodeNavigationError("unsupported");
|
|
183
|
+
await rpc.sendNotification("initialized", {});
|
|
184
|
+
return initialized.capabilities;
|
|
185
|
+
}
|
|
186
|
+
lookup(query, content, signal) {
|
|
187
|
+
if (this.queued >= 8)
|
|
188
|
+
return Promise.reject(new CodeNavigationError("busy"));
|
|
189
|
+
clearTimeout(this.idle);
|
|
190
|
+
this.queued++;
|
|
191
|
+
const result = this.tail.then(async () => {
|
|
192
|
+
if (this.closed || signal?.aborted)
|
|
193
|
+
throw new CodeNavigationError("unavailable");
|
|
194
|
+
let capabilities;
|
|
195
|
+
try {
|
|
196
|
+
capabilities = await (this.initialization ??= this.start());
|
|
197
|
+
}
|
|
198
|
+
catch (error) {
|
|
199
|
+
this.close();
|
|
200
|
+
throw error;
|
|
201
|
+
}
|
|
202
|
+
if (signal?.aborted)
|
|
203
|
+
throw new CodeNavigationError("unavailable");
|
|
204
|
+
if (((query.kind === "definition" || query.kind === "declaration") && !capabilities.definitionProvider && !capabilities.declarationProvider)
|
|
205
|
+
|| (query.kind === "formatting" && !capabilities.documentFormattingProvider))
|
|
206
|
+
throw new CodeNavigationError("unsupported");
|
|
207
|
+
const rpc = this.connection;
|
|
208
|
+
const textDocument = { uri: pathToFileURL(query.path).href };
|
|
209
|
+
const version = ++this.version;
|
|
210
|
+
const ready = query.kind === "diagnostics" && !capabilities.diagnosticProvider ? new Promise((resolve, reject) => {
|
|
211
|
+
this.diagnostic = { version, uri: uriKey(textDocument.uri), resolve, reject };
|
|
212
|
+
}) : undefined;
|
|
213
|
+
ready?.catch(() => { });
|
|
214
|
+
try {
|
|
215
|
+
await rpc.sendNotification("textDocument/didOpen", { textDocument: { ...textDocument, languageId: codeLanguage(query.path)?.id, version, text: content } });
|
|
216
|
+
if (query.kind === "diagnostics") {
|
|
217
|
+
const items = ready ? await withDeadline(ready, 12_000, () => this.close())
|
|
218
|
+
: (await withDeadline(rpc.sendRequest("textDocument/diagnostic", { textDocument }), 12_000, () => this.close())).items ?? [];
|
|
219
|
+
return { diagnostics: diagnosticsFor(content, items) };
|
|
220
|
+
}
|
|
221
|
+
if (query.kind === "formatting") {
|
|
222
|
+
const changes = await withDeadline(rpc.sendRequest("textDocument/formatting", {
|
|
223
|
+
textDocument, options: { tabSize: 4, insertSpaces: true },
|
|
224
|
+
}), 12_000, () => this.close());
|
|
225
|
+
const offset = codeOffsets(content);
|
|
226
|
+
const edits = (changes ?? []).map(edit => {
|
|
227
|
+
const from = offset(edit.range?.start), to = offset(edit.range?.end);
|
|
228
|
+
if (from === undefined || to === undefined || to < from || typeof edit.newText !== "string")
|
|
229
|
+
throw new CodeNavigationError("unavailable");
|
|
230
|
+
return { from, to, insert: edit.newText };
|
|
231
|
+
}).sort((a, b) => a.from - b.from || a.to - b.to);
|
|
232
|
+
return { edits };
|
|
233
|
+
}
|
|
234
|
+
const method = query.kind === "declaration" && capabilities.declarationProvider ? "declaration" : "definition";
|
|
235
|
+
const reply = await withDeadline(rpc.sendRequest(`textDocument/${method}`, {
|
|
236
|
+
textDocument, position: { line: query.line - 1, character: query.column - 1 },
|
|
237
|
+
}), 12_000, () => this.close());
|
|
238
|
+
return { locations: locations(this.root, reply) };
|
|
239
|
+
}
|
|
240
|
+
finally {
|
|
241
|
+
clearTimeout(this.diagnostic?.first);
|
|
242
|
+
this.diagnostic = undefined;
|
|
243
|
+
if (!this.closed) {
|
|
244
|
+
if (!this.diagnosticsOnly)
|
|
245
|
+
await rpc.sendNotification("textDocument/didClose", { textDocument });
|
|
246
|
+
else {
|
|
247
|
+
const cleared = new Promise(done => { this.diagnosticClear = { uri: uriKey(textDocument.uri), done }; });
|
|
248
|
+
try {
|
|
249
|
+
await rpc.sendNotification("textDocument/didClose", { textDocument });
|
|
250
|
+
await withDeadline(cleared, 1000, () => this.close());
|
|
251
|
+
}
|
|
252
|
+
catch {
|
|
253
|
+
this.close();
|
|
254
|
+
}
|
|
255
|
+
finally {
|
|
256
|
+
this.diagnosticClear = undefined;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}).finally(() => {
|
|
262
|
+
if (--this.queued === 0 && !this.closed) {
|
|
263
|
+
this.idle = setTimeout(() => this.close(), IDLE_MS);
|
|
264
|
+
this.idle.unref();
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
this.tail = result.catch(() => { });
|
|
268
|
+
return result;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
export class CodeNavigation {
|
|
272
|
+
projects = new Map();
|
|
273
|
+
closed = false;
|
|
274
|
+
close() {
|
|
275
|
+
this.closed = true;
|
|
276
|
+
for (const project of this.projects.values())
|
|
277
|
+
project.close();
|
|
278
|
+
}
|
|
279
|
+
lookup(root, request, content, signal) {
|
|
280
|
+
if (this.closed)
|
|
281
|
+
throw new CodeNavigationError("unavailable");
|
|
282
|
+
const language = codeLanguage(request.path);
|
|
283
|
+
if (!language)
|
|
284
|
+
throw new CodeNavigationError("unsupported");
|
|
285
|
+
// Servers that do not version diagnostics cannot share the editor-query connection safely.
|
|
286
|
+
const diagnosticsOnly = request.kind === "diagnostics" && (language.server === "typescript" || language.server === "pylsp");
|
|
287
|
+
const key = JSON.stringify([root, language.server, diagnosticsOnly]);
|
|
288
|
+
let project = this.projects.get(key);
|
|
289
|
+
if (!project) {
|
|
290
|
+
if (this.projects.size >= MAX_SERVERS) {
|
|
291
|
+
const idle = [...this.projects.values()].find(candidate => candidate.canEvict);
|
|
292
|
+
if (!idle)
|
|
293
|
+
throw new CodeNavigationError("busy");
|
|
294
|
+
idle.close();
|
|
295
|
+
}
|
|
296
|
+
project = new LanguageProject(root, language.server, diagnosticsOnly, () => this.projects.delete(key));
|
|
297
|
+
this.projects.set(key, project);
|
|
298
|
+
}
|
|
299
|
+
return project.lookup(request, content, signal);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
@@ -9,6 +9,7 @@ import { spawn } from "node:child_process";
|
|
|
9
9
|
import { randomUUID } from "node:crypto";
|
|
10
10
|
import { BrowserAccess, isBrowserAuthorized } from "./browser-access.js";
|
|
11
11
|
import { NativeToolsService, NativeToolsError } from "./native-tools-service.js";
|
|
12
|
+
import { CodeNavigation, CodeNavigationError } from "./code-navigation.js";
|
|
12
13
|
import { once } from "node:events";
|
|
13
14
|
import { access, readFile, readdir, realpath, rm, stat } from "node:fs/promises";
|
|
14
15
|
import { createServer } from "node:http";
|
|
@@ -376,6 +377,7 @@ export function createHttpServer(options) {
|
|
|
376
377
|
const explicitFileOpen = createExplicitFileOpen();
|
|
377
378
|
const browserAccess = context.browserAccess ??= new BrowserAccess(join(paths.dataDir, "browser-access.json"));
|
|
378
379
|
const nativeTools = new NativeToolsService(paths.dataDir, () => context.runtime?.reloadNativeTools?.());
|
|
380
|
+
const codeNavigation = new CodeNavigation();
|
|
379
381
|
const readBaseline = [];
|
|
380
382
|
const initialReadState = store.clientState({});
|
|
381
383
|
for (const conversation of initialReadState.conversations) {
|
|
@@ -3854,6 +3856,66 @@ export function createHttpServer(options) {
|
|
|
3854
3856
|
}
|
|
3855
3857
|
return;
|
|
3856
3858
|
}
|
|
3859
|
+
if (url.pathname === "/api/files/code-navigation") {
|
|
3860
|
+
if (request.method !== "POST") {
|
|
3861
|
+
json(405, { code: "method" });
|
|
3862
|
+
return;
|
|
3863
|
+
}
|
|
3864
|
+
if (!isBrowserAuthorized(request) && !isLocalOrPrivateAddress(remote)) {
|
|
3865
|
+
json(403, { code: "unavailable" });
|
|
3866
|
+
return;
|
|
3867
|
+
}
|
|
3868
|
+
const workspaceId = url.searchParams.get("workspaceId")?.trim();
|
|
3869
|
+
const workspace = workspaceId ? store.workspace(workspaceId) : undefined;
|
|
3870
|
+
if (!workspace || workspace.closedAt) {
|
|
3871
|
+
json(404, { code: "workspace_missing" });
|
|
3872
|
+
return;
|
|
3873
|
+
}
|
|
3874
|
+
const controller = new AbortController();
|
|
3875
|
+
response.once("close", () => controller.abort());
|
|
3876
|
+
try {
|
|
3877
|
+
const payload = await readRequestText(request, MAX_FILE_BYTES * 2);
|
|
3878
|
+
if (payload.tooLarge) {
|
|
3879
|
+
json(413, { code: "too_large" });
|
|
3880
|
+
return;
|
|
3881
|
+
}
|
|
3882
|
+
let body;
|
|
3883
|
+
try {
|
|
3884
|
+
body = JSON.parse(payload.text);
|
|
3885
|
+
}
|
|
3886
|
+
catch {
|
|
3887
|
+
json(400, { code: "bad_query" });
|
|
3888
|
+
return;
|
|
3889
|
+
}
|
|
3890
|
+
const kind = body?.kind, path = body?.path, line = body?.line, column = body?.column, content = body?.content;
|
|
3891
|
+
const symbol = kind === "definition" || kind === "declaration";
|
|
3892
|
+
if ((!symbol && kind !== "diagnostics" && kind !== "formatting") || typeof path !== "string" || !path || path.length > 4096
|
|
3893
|
+
|| (symbol && (!Number.isSafeInteger(line) || line < 1 || !Number.isSafeInteger(column) || column < 1))
|
|
3894
|
+
|| (content !== undefined && (typeof content !== "string" || Buffer.byteLength(content) > MAX_FILE_BYTES))) {
|
|
3895
|
+
json(400, { code: "bad_query" });
|
|
3896
|
+
return;
|
|
3897
|
+
}
|
|
3898
|
+
const checkout = await resolveFileCwd(workspace.path);
|
|
3899
|
+
const cwd = await resolveFileCwd(checkout, url.searchParams.get("cwd"));
|
|
3900
|
+
await explorerPath(checkout, cwd, path, true);
|
|
3901
|
+
const file = await resolveInsideRoot(cwd, path);
|
|
3902
|
+
const disk = await readWorkspaceFile(cwd, path);
|
|
3903
|
+
const result = await codeNavigation.lookup(checkout, symbol ? { kind, path: file, line, column } : { kind, path: file }, content ?? disk.content, controller.signal);
|
|
3904
|
+
if (!controller.signal.aborted)
|
|
3905
|
+
json(200, result);
|
|
3906
|
+
}
|
|
3907
|
+
catch (error) {
|
|
3908
|
+
if (controller.signal.aborted)
|
|
3909
|
+
return;
|
|
3910
|
+
if (error instanceof CodeNavigationError)
|
|
3911
|
+
json(422, { code: error.code });
|
|
3912
|
+
else if (error instanceof FilesError)
|
|
3913
|
+
json(error.status, { code: "bad_file" });
|
|
3914
|
+
else
|
|
3915
|
+
json(502, { code: "unavailable" });
|
|
3916
|
+
}
|
|
3917
|
+
return;
|
|
3918
|
+
}
|
|
3857
3919
|
if (url.pathname === "/api/files" || url.pathname === "/api/file") {
|
|
3858
3920
|
const json = (status, body) => {
|
|
3859
3921
|
response.writeHead(status, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify(body));
|
|
@@ -4218,6 +4280,9 @@ export function createHttpServer(options) {
|
|
|
4218
4280
|
}
|
|
4219
4281
|
}
|
|
4220
4282
|
});
|
|
4221
|
-
server.once("close", () => { void nativeTools.close(); });
|
|
4222
|
-
return Object.assign(server, {
|
|
4283
|
+
server.once("close", () => { codeNavigation.close(); void nativeTools.close(); });
|
|
4284
|
+
return Object.assign(server, {
|
|
4285
|
+
closeNativeTools: () => nativeTools.close(),
|
|
4286
|
+
closeCodeNavigation: () => codeNavigation.close(),
|
|
4287
|
+
});
|
|
4223
4288
|
}
|
package/dist/server/index.js
CHANGED
|
@@ -497,6 +497,7 @@ async function shutdown(reason) {
|
|
|
497
497
|
// Stop accepting new connections first. Existing clients stay connected until
|
|
498
498
|
// their cancelled work has recorded its terminal state.
|
|
499
499
|
const httpClosed = closeHttpServer();
|
|
500
|
+
httpServer.closeCodeNavigation();
|
|
500
501
|
const nativeToolsClosed = httpServer.closeNativeTools();
|
|
501
502
|
// Kill every shell BEFORE the sockets close, so a PTY is never outlived by the server that owns it.
|
|
502
503
|
terminalService.closeAll();
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export type CodeNavigationKind = "definition" | "declaration";
|
|
2
|
+
export type CodeLanguageServer = "clangd" | "typescript" | "pylsp" | "buf";
|
|
3
|
+
export interface CodeLocation {
|
|
4
|
+
path: string;
|
|
5
|
+
external?: true;
|
|
6
|
+
line: number;
|
|
7
|
+
column: number;
|
|
8
|
+
}
|
|
9
|
+
export type CodeTextEdit = {
|
|
10
|
+
from: number;
|
|
11
|
+
to: number;
|
|
12
|
+
insert: string;
|
|
13
|
+
};
|
|
14
|
+
export type CodeDiagnostic = {
|
|
15
|
+
from: number;
|
|
16
|
+
to: number;
|
|
17
|
+
severity: "error" | "warning";
|
|
18
|
+
message: string;
|
|
19
|
+
source?: string;
|
|
20
|
+
};
|
|
21
|
+
export declare function applyCodeEdits(content: string, edits: readonly CodeTextEdit[]): string;
|
|
22
|
+
export declare function codeLanguage(path: string): {
|
|
23
|
+
server: CodeLanguageServer;
|
|
24
|
+
id: string;
|
|
25
|
+
} | undefined;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export function applyCodeEdits(content, edits) {
|
|
2
|
+
let end = 0;
|
|
3
|
+
const parts = [];
|
|
4
|
+
for (const edit of edits) {
|
|
5
|
+
if (!Number.isSafeInteger(edit.from) || !Number.isSafeInteger(edit.to) || edit.from < end || edit.to < edit.from || edit.to > content.length || typeof edit.insert !== "string") {
|
|
6
|
+
throw new Error("Invalid formatting edits");
|
|
7
|
+
}
|
|
8
|
+
parts.push(content.slice(end, edit.from), edit.insert);
|
|
9
|
+
end = edit.to;
|
|
10
|
+
}
|
|
11
|
+
return parts.join("") + content.slice(end);
|
|
12
|
+
}
|
|
13
|
+
function clangLanguage(extension) {
|
|
14
|
+
if (extension === "C")
|
|
15
|
+
return "cpp";
|
|
16
|
+
switch (extension?.toLowerCase()) {
|
|
17
|
+
case "c": return "c";
|
|
18
|
+
case "h":
|
|
19
|
+
case "cc":
|
|
20
|
+
case "cp":
|
|
21
|
+
case "cpp":
|
|
22
|
+
case "cxx":
|
|
23
|
+
case "c++":
|
|
24
|
+
case "hh":
|
|
25
|
+
case "hpp":
|
|
26
|
+
case "hxx":
|
|
27
|
+
case "h++":
|
|
28
|
+
case "ipp":
|
|
29
|
+
case "inl":
|
|
30
|
+
return "cpp";
|
|
31
|
+
case "m": return "objective-c";
|
|
32
|
+
case "mm": return "objective-cpp";
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export function codeLanguage(path) {
|
|
36
|
+
const ext = /\.([\w+]+)$/.exec(path)?.[1];
|
|
37
|
+
switch (ext?.toLowerCase()) {
|
|
38
|
+
case "ts":
|
|
39
|
+
case "mts":
|
|
40
|
+
case "cts": return { server: "typescript", id: "typescript" };
|
|
41
|
+
case "tsx": return { server: "typescript", id: "typescriptreact" };
|
|
42
|
+
case "py":
|
|
43
|
+
case "pyi": return { server: "pylsp", id: "python" };
|
|
44
|
+
case "proto": return { server: "buf", id: "protobuf" };
|
|
45
|
+
}
|
|
46
|
+
const id = clangLanguage(ext);
|
|
47
|
+
if (id)
|
|
48
|
+
return { server: "clangd", id };
|
|
49
|
+
}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"superPi": {
|
|
4
4
|
"managedDirectListener": true
|
|
5
5
|
},
|
|
6
|
-
"version": "0.1.
|
|
6
|
+
"version": "0.1.327",
|
|
7
7
|
"description": "Web control plane and companion for Pi",
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"type": "module",
|
|
@@ -506,6 +506,7 @@
|
|
|
506
506
|
"@codemirror/lang-yaml": "^6.1.3",
|
|
507
507
|
"@codemirror/language": "^6.13.1",
|
|
508
508
|
"@codemirror/legacy-modes": "^6.5.5",
|
|
509
|
+
"@codemirror/lint": "^6.9.8",
|
|
509
510
|
"@codemirror/merge": "^6.12.3",
|
|
510
511
|
"@codemirror/search": "^6.7.2",
|
|
511
512
|
"@codemirror/state": "^6.7.6",
|
|
@@ -525,7 +526,10 @@
|
|
|
525
526
|
"fuse.js": "^7.5.0",
|
|
526
527
|
"node-pty": "^1.2.0-beta.15",
|
|
527
528
|
"ssh2": "1.17.0",
|
|
529
|
+
"typescript-language-server": "^5.3.0",
|
|
530
|
+
"typescript-lsp-runtime": "npm:typescript@^5.9.3",
|
|
528
531
|
"undici": "^7.30.2",
|
|
532
|
+
"vscode-jsonrpc": "^8.2.1",
|
|
529
533
|
"ws": "latest"
|
|
530
534
|
},
|
|
531
535
|
"devDependencies": {
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/dist-1rD0ihl2.js","assets/editor-blame-DcMUzRBK.js","assets/editor-blame-PLncD0eu.css","assets/dist-CD0jGv9h.js","assets/dist-Ch-BrJW7.js","assets/dist-DTem9o2m.js","assets/dist-Dk-yOCN3.js","assets/dist-BWav58GK.js","assets/dist-56GF8ANx.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{F as e,I as t,L as n,Xt as r,_ as i,a,d as o,f as s,h as c,m as l,on as u,p as d,r as f,rn as p}from"./editor-blame-DcMUzRBK.js";var m=u(p(),1);function ee(e,t,n,r){return[n.EditorView.decorations.compute([`selection`,`doc`],e=>n.Decoration.set(e.selection.ranges.filter(e=>!e.empty).map(e=>n.Decoration.mark({class:`cm-workbench-selectedText`}).range(e.from,e.to)),!0)),n.ViewPlugin.define(e=>{let n=null,i,a=!1,o=e=>{n&&(e===`expanded`?(a=!a,u()):n.querySelector(`input[name="${e===`caseSensitive`?`case`:e===`wholeWord`?`word`:`re`}"]`)?.click())},s=e=>{let t=l(e);t&&(e.preventDefault(),e.stopPropagation(),o(t))},u=()=>{if(!n||!i)return;let r=t.getSearchQuery(e.state);if(n.dataset.editorSearchExpanded=String(a),i.update({caseSensitive:r.caseSensitive,wholeWord:r.wholeWord,regexp:r.regexp,expanded:a}),n.querySelector(`[data-find-error]`)?.remove(),r.search&&!r.valid){let e=document.createElement(`output`);e.dataset.findError=``,e.setAttribute(`role`,`alert`),e.textContent=`正则表达式无效`,n.append(e)}},d=()=>{let l=r.querySelector(`.cm-panel.cm-search`);if(l===n)return;if(n?.removeEventListener(`keydown`,s,!0),i?.destroy(),n=l,!n){i=void 0;return}for(let[e,t,r]of[[`next`,`↓`,`下一处`],[`prev`,`↑`,`上一处`]]){let i=n.querySelector(`button[name="${e}"]`);i&&(i.textContent=t,i.setAttribute(`aria-label`,r),i.title=r)}let d=document.createElement(`span`);d.dataset.findControls=``,n.prepend(d);let f=t.getSearchQuery(e.state);a=!1,i=c(d,{...f,expanded:a},o),n.addEventListener(`keydown`,s,!0),u()},f=new MutationObserver(d);return f.observe(r,{childList:!0,subtree:!0}),d(),{update(){u()},destroy(){f.disconnect(),n?.removeEventListener(`keydown`,s,!0),i?.destroy()}}}),e.Prec.highest(n.keymap.of([{key:`Mod-Shift-l`,run:t.selectSelectionMatches},{key:`Mod-h`,scope:`editor search-panel`,run:e=>(t.searchPanelOpen(e.state)||t.openSearchPanel(e),requestAnimationFrame(()=>{e.dom.isConnected&&r.querySelector(`[data-editor-search-options][aria-expanded="false"]`)?.click()}),!0)},...[`c`,`w`,`r`].map(e=>({key:`Alt-${e}`,run:n=>{t.searchPanelOpen(n.state)||t.openSearchPanel(n);let r=t.getSearchQuery(n.state);return n.dispatch({effects:t.setSearchQuery.of(new t.SearchQuery({...r,...e===`c`?{caseSensitive:!r.caseSensitive}:e===`w`?{wholeWord:!r.wholeWord}:{regexp:!r.regexp}}))}),!0}}))])),n.panels({topContainer:r}),n.EditorView.scrollMargins.of(()=>({top:r.querySelector(`.cm-search`)?Math.min(r.getBoundingClientRect().height+8,Math.max(0,(r.parentElement?.clientHeight??0)-32)):0})),t.highlightSelectionMatches({wholeWords:!0,minSelectionLength:1,maxMatches:1e3}),t.search({top:!0}),e.EditorState.phrases.of({Find:`查找`,Replace:`替换为`,next:`下一处`,previous:`上一处`,all:`全部选中`,"match case":`区分大小写`,regexp:`正则表达式`,"by word":`全词匹配`,replace:`替换`,"replace all":`全部替换`,close:`关闭查找`,"current match":`当前匹配`,"on line":`所在行`})]}function te(e,t,n,r,i){let a=new e.Compartment,c=()=>{let r=o();return[e.EditorState.tabSize.of(r.tabSize),n.indentUnit.of(r.indent===`tabs`?` `:` `.repeat(r.tabSize)),r.wrap?t.EditorView.lineWrapping:[],r.whitespace?[t.highlightWhitespace(),t.highlightTrailingWhitespace()]:[]]};return[e.EditorState.allowMultipleSelections.of(!0),t.rectangularSelection(),t.crosshairCursor({key:`Alt`}),e.EditorState.phrases.of({"folded code":`已折叠代码`,unfold:`展开代码`,"Fold line":`折叠代码`,"Unfold line":`展开代码`}),t.highlightActiveLineGutter(),t.highlightSpecialChars(),t.dropCursor(),n.bracketMatching(),n.indentOnInput(),n.foldGutter(),r.closeBrackets(),e.Prec.highest(t.keymap.of([...r.closeBracketsKeymap,...n.foldKeymap,{key:`Alt-z`,run:()=>(s({wrap:!o().wrap}),!0)},{key:`Mod-Shift-z`,run:i.redo},{key:`Mod-y`,run:i.redo}])),a.of(c()),t.ViewPlugin.define(e=>({destroy:d(()=>{e.dispatch({effects:a.reconfigure(c())})})}))]}var h=new Map;function ne(e){let t=h.get(e);return t&&(h.delete(e),h.set(e,t)),t}function g(e,t){h.delete(e),h.set(e,t);let n=[...h.values()].reduce((e,t)=>e+t.state.doc.length,0);for(;h.size>32||n>16777216;){let e=h.keys().next().value;n-=h.get(e).state.doc.length,h.delete(e)}}var _=r(),re=262144,v=131072;function ie(e){return e.split(`.`).pop()?.toLowerCase()??``}function y(e,t,n=!1){let r=e=>n?`var(--git-diff-${e.slice(5)}, var(${e}))`:`var(${e})`;return e.HighlightStyle.define([{tag:t.tags.keyword,color:r(`--cm-keyword`)},{tag:t.tags.string,color:r(`--cm-string`)},{tag:t.tags.number,color:r(`--cm-number`)},{tag:t.tags.comment,color:r(`--cm-comment`),fontStyle:`italic`},{tag:t.tags.function(t.tags.variableName),color:r(`--cm-function`)},{tag:t.tags.typeName,color:r(`--cm-type`)},{tag:t.tags.className,color:r(`--cm-type`)},{tag:t.tags.propertyName,color:r(`--cm-property`)},{tag:t.tags.operator,color:r(`--cm-operator`)},{tag:t.tags.variableName,color:r(`--cm-variable`)}])}function b({path:r,value:o,onChange:s,jumpToLine:c,onSave:l,workspaceId:u,cwd:d=``,blame:p,onPosition:h,onView:b,readOnly:x=!1,languageOverride:S,onReviewLine:C}){let w=(0,m.useRef)(null),T=(0,m.useRef)(null),E=(0,m.useRef)(null),ae=(0,m.useRef)(null),D=JSON.stringify([u,d,r]),O=(0,m.useRef)(void 0),k=(0,m.useRef)(null),A=(0,m.useRef)(null),oe=(0,m.useRef)(null),j=(0,m.useRef)(null),M=(0,m.useRef)(null),N=(0,m.useRef)(null),P=(0,m.useRef)(s),F=(0,m.useRef)(l),I=(0,m.useRef)(o);I.current=o;let L=(0,m.useRef)(!1),R=(0,m.useRef)(b);R.current=b;let z=(0,m.useRef)(C);z.current=C;let B=!!C;P.current=s,F.current=l;let[V,se]=(0,m.useState)(!1),[H,U]=(0,m.useState)(!1),[W,ce]=(0,m.useState)(`0,0`),[G,le]=(0,m.useState)(0),[K,ue]=(0,m.useState)(1);(0,m.useEffect)(()=>{let e=!1,s,c,l,u,d;return(async()=>{try{let f=S??ie(r),p=t(f),[m,h,g,_,v,b,C,V,H]=await Promise.all([n(()=>import(`./dist-1rD0ihl2.js`).then(e=>e.S),__vite__mapDeps([0,1,2])),n(()=>import(`./dist-CD0jGv9h.js`).then(e=>e.s),__vite__mapDeps([3,1,2,0])),n(()=>import(`./dist-Ch-BrJW7.js`),__vite__mapDeps([4,0,1,2,3,5,6])),n(()=>import(`./dist-BWav58GK.js`),__vite__mapDeps([7,0,1,2,3])),n(()=>import(`./dist-Dk-yOCN3.js`).then(e=>e.d),__vite__mapDeps([6,1,2,0,3,5])),n(()=>import(`./dist-DTem9o2m.js`).then(e=>e.n),__vite__mapDeps([5,1,2])),p?p().catch(e=>(console.warn(`[CodeMirror] Failed to load language for .${f}:`,e),null)):Promise.resolve(null),a().catch(e=>(console.warn(`[CodeMirror] Failed to build the blame extension:`,e),null)),n(()=>import(`./dist-56GF8ANx.js`).then(e=>e.r),__vite__mapDeps([8,1,2,0,3,6,5]))]);if(e||!w.current||!T.current)return;ae.current=h.EditorView,u=v,d=b,A.current=m.Annotation.define(),oe.current=m.Transaction.addToHistory;let W=o.length<=re&&C!==null;c=new m.Compartment;let G=[h.lineNumbers(),h.highlightActiveLine(),h.drawSelection(),g.history(),h.keymap.of([g.indentWithTab,...g.defaultKeymap,...g.historyKeymap,..._.searchKeymap,{key:`Mod-s`,run:()=>(F.current(),!0)}]),h.EditorView.updateListener.of(e=>{e.docChanged&&!(A.current&&e.transactions.some(e=>e.annotation(A.current)===!0))&&P.current(e.state.doc.toString()),e.selectionSet&&ce(`${e.state.selection.main.from},${e.state.selection.main.to}`)}),h.EditorView.domEventHandlers({mousedown:(e,t)=>(t.focus(),!1)})];if(B&&G.push(i(h,e=>z.current?.(e),`file`)),G.push(h.EditorView.updateListener.of(e=>{e.selectionSet&&ue(e.state.selection.ranges.length),e.docChanged?L.current=!1:e.selectionSet&&(L.current=e.transactions.some(e=>e.isUserEvent(`select.search`)||e.isUserEvent(`select.pointer`)))}),ee(m,_,h,T.current),te(m,h,v,H,g)),x&&G.push(m.EditorState.readOnly.of(!0),h.EditorView.editable.of(!1),h.EditorView.contentAttributes.of({tabindex:`0`})),V&&!x&&(l=new m.Compartment,G.splice(1,0,l.of([])),G.push(V.base)),C)try{G.push(C)}catch(e){console.warn(`[CodeMirror] Failed to apply language extension for .${f}:`,e),W=!1}if(W&&c&&u&&d)try{G.push(c.of(u.syntaxHighlighting(y(u,d))))}catch(e){console.warn(`[CodeMirror] Failed to attach syntaxHighlighting for .${f}:`,e),W=!1}let K=ne(D),q=K&&K.state.doc.toString()===I.current,J=q?K.state.update({effects:m.StateEffect.reconfigure.of(G)}).state:m.EditorState.create({doc:I.current,extensions:G});if(s=new h.EditorView({state:J,parent:w.current}),O.current=q?K.jump:void 0,ue(s.state.selection.ranges.length),ce(`${s.state.selection.main.from},${s.state.selection.main.to}`),q&&(s.scrollDOM.scrollTop=K.top,s.scrollDOM.scrollLeft=K.left,O.current=K.jump),e){s.destroy();return}E.current=s,R.current?.(s),se(W),U(!0),j.current=V,M.current=l??null,N.current=null,le(e=>e+1);let Y=new MutationObserver(()=>{let e=E.current;if(e&&W&&c&&u&&d)try{e.dispatch({effects:c.reconfigure(u.syntaxHighlighting(y(u,d)))})}catch{}});k.current=Y,Y.observe(document.documentElement,{attributes:!0,attributeFilter:[`data-theme`]})}catch(t){console.error(`[CodeMirror] Fatal editor initialization error:`,t),e||U(!0)}})(),()=>{e=!0,k.current?.disconnect(),k.current=null,s&&g(D,{state:s.state,top:s.scrollDOM.scrollTop,left:s.scrollDOM.scrollLeft,jump:O.current}),s?.destroy(),E.current=null,R.current?.(),U(!1),w.current&&(w.current.textContent=``)}},[D,x,S,B]),(0,m.useEffect)(()=>{let e=E.current;if(!e)return;let t=e.state.doc.toString();t!==o&&e.dispatch({changes:{from:0,to:t.length,insert:o},annotations:A.current?A.current.of(!0):void 0})},[o,H]),(0,m.useEffect)(()=>{let e=E.current;if(!e||!c||O.current===c.request)return;O.current=c.request;let t=e.state.doc.line(Math.min(Math.max(1,c.line),e.state.doc.lines)),n=Math.min(t.to,t.from+(c.column??1)-1);e.dispatch({selection:{anchor:t.to,head:n},effects:ae.current?.scrollIntoView(n,{y:`start`,yMargin:Math.round(e.scrollDOM.clientHeight/3)})}),e.focus()},[c,H]);let q=!!(p&&p.state===`ready`&&p.response&&p.path===r&&p.workspaceId===u);(0,m.useEffect)(()=>{let e=E.current,t=j.current,n=M.current;if(!e||!t||!n)return;let i=p&&p.state===`ready`&&p.response&&p.path===r&&p.workspaceId===u?p.response:null,a=i?f(i):null;N.current!==a&&(N.current=a,e.dispatch({effects:[t.setBlame.of(a),n.reconfigure(a?t.gutter:[])]}))},[p?.state,p?.response,p?.path,p?.workspaceId,r,u,G]);let J=E.current?.state.doc.toString()??o,Y=J.length<=v?J:J.slice(0,v),X=S??ie(r),Z=e(X),de=E.current?.state,Q=de?.selection.main.head,$=Q===void 0?void 0:de?.doc.lineAt(Q),fe=$?.number,pe=Q!==void 0&&$?Q-$.from+1:void 0;return(0,m.useEffect)(()=>{let e=E.current;if(H&&e&&(!c||O.current===c.request)){let t=e.state.selection.main.head,n=e.state.doc.lineAt(t);h?.({line:n.number,column:t-n.from+1,language:V&&Z||`纯文本`,highlight:V?X:`plain`,navigation:L.current,selections:e.state.selection.ranges.length})}},[H,fe,pe,V,Z,X,h,K,c?.request]),(0,m.useEffect)(()=>()=>h?.(),[h]),(0,_.jsxs)(`div`,{className:`file-cm-wrap`,"data-file-text":r,"data-file-content":Y,"data-file-content-truncated":J.length>v?`1`:`0`,"data-file-selection":W,"data-editor-selection-count":K,"data-file-editor-ready":H?`1`:`0`,"data-file-blame-gutter":q?`1`:void 0,onMouseDown:e=>{e.target.closest(`.cm-panels`)||E.current?.focus()},children:[(0,_.jsx)(`div`,{className:`file-cm`,ref:w,"aria-label":`${x?`查看`:`编辑`} ${r}`}),(0,_.jsx)(`div`,{className:`workbench-editor-search`,ref:T,"data-editor-find-host":`file`}),(!H||!h)&&(0,_.jsxs)(`div`,{className:`file-editor-status`,children:[!H&&(0,_.jsx)(`span`,{"data-file-editor-loading":`1`,children:`正在加载编辑器…`}),H&&Q!==void 0&&$&&(0,_.jsxs)(`span`,{children:[`第 `,$.number,` 行,第 `,Q-$.from+1,` 列`]}),H&&!V&&(0,_.jsx)(`span`,{"data-file-highlight-status":`plain`,children:`纯文本`}),H&&V&&Z&&(0,_.jsx)(`span`,{"data-file-highlight-status":X,children:Z})]})]})}export{b as CodeMirrorEditor,ee as n,te as t,y as themeHighlightStyle};
|