@webgal/language-service 0.0.2-alpha.0
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/LICENSE +373 -0
- package/build/chunk-C0xms8kb.cjs +34 -0
- package/build/index.cjs +297 -0
- package/build/index.d.cts +103 -0
- package/build/index.d.mts +103 -0
- package/build/index.mjs +293 -0
- package/build/language-configuration-BeRkRSII.mjs +214 -0
- package/build/language-configuration-D41FLA6b.cjs +232 -0
- package/build/monaco-init.cjs +83 -0
- package/build/monaco-init.d.cts +7 -0
- package/build/monaco-init.d.mts +7 -0
- package/build/monaco-init.mjs +78 -0
- package/build/monaco.cjs +138 -0
- package/build/monaco.d.cts +32 -0
- package/build/monaco.d.mts +32 -0
- package/build/monaco.mjs +134 -0
- package/build/node.cjs +374 -0
- package/build/node.d.cts +11 -0
- package/build/node.d.mts +11 -0
- package/build/node.mjs +370 -0
- package/build/syntaxes.cjs +12 -0
- package/build/syntaxes.d.cts +293 -0
- package/build/syntaxes.d.mts +293 -0
- package/build/syntaxes.mjs +9 -0
- package/build/themes.cjs +10 -0
- package/build/themes.d.cts +286 -0
- package/build/themes.d.mts +286 -0
- package/build/themes.mjs +8 -0
- package/build/white-Be4QIaif.cjs +1007 -0
- package/build/white-CaNrG0B0.mjs +995 -0
- package/package.json +71 -0
package/build/index.cjs
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
//#region src/index.ts
|
|
4
|
+
const normalizePath = (input) => {
|
|
5
|
+
let path = input.replace(/\\/g, "/").replace(/\/+/g, "/");
|
|
6
|
+
if (path === "") return "/";
|
|
7
|
+
if (!path.startsWith("/")) path = "/" + path;
|
|
8
|
+
if (path.length > 1 && path.endsWith("/")) path = path.slice(0, -1);
|
|
9
|
+
return path;
|
|
10
|
+
};
|
|
11
|
+
const joinPaths = (...parts) => {
|
|
12
|
+
return normalizePath(parts.filter((part) => part && part !== "/").join("/"));
|
|
13
|
+
};
|
|
14
|
+
const uriToPath = (uriString) => {
|
|
15
|
+
if (uriString.startsWith("file://")) {
|
|
16
|
+
const stripped = uriString.replace(/^file:\/*/i, "/");
|
|
17
|
+
const decoded = decodeURIComponent(stripped).replace(/\\/g, "/");
|
|
18
|
+
if (/^\/[a-zA-Z]:\//.test(decoded)) return decoded.slice(1);
|
|
19
|
+
return normalizePath(decoded);
|
|
20
|
+
}
|
|
21
|
+
return normalizePath(uriString);
|
|
22
|
+
};
|
|
23
|
+
const toVfsPath = (value) => value.startsWith("file://") ? uriToPath(value) : value;
|
|
24
|
+
function createMemoryFileSystem(options) {
|
|
25
|
+
const root = normalizePath(options?.root ?? "/");
|
|
26
|
+
let rootEntry = options?.tree && options.tree.type === "dir" ? options.tree : {
|
|
27
|
+
type: "dir",
|
|
28
|
+
children: {}
|
|
29
|
+
};
|
|
30
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
31
|
+
const emit = (changes) => {
|
|
32
|
+
for (const listener of listeners) listener(changes);
|
|
33
|
+
};
|
|
34
|
+
const resolveToSegments = (path) => {
|
|
35
|
+
let resolved = normalizePath(path);
|
|
36
|
+
if (root !== "/" && resolved.startsWith(root)) resolved = resolved.slice(root.length);
|
|
37
|
+
if (resolved.startsWith("/")) resolved = resolved.slice(1);
|
|
38
|
+
return resolved ? resolved.split("/") : [];
|
|
39
|
+
};
|
|
40
|
+
const ensureDirectoryEntry = (segments) => {
|
|
41
|
+
let current = rootEntry;
|
|
42
|
+
for (const segment of segments) {
|
|
43
|
+
if (current.type !== "dir") throw new Error("Path segment is not a directory");
|
|
44
|
+
const directory = current;
|
|
45
|
+
const existing = directory.children[segment];
|
|
46
|
+
if (!existing) {
|
|
47
|
+
const created = {
|
|
48
|
+
type: "dir",
|
|
49
|
+
children: {}
|
|
50
|
+
};
|
|
51
|
+
directory.children[segment] = created;
|
|
52
|
+
current = created;
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
if (existing.type !== "dir") throw new Error("Path segment is not a directory");
|
|
56
|
+
current = existing;
|
|
57
|
+
}
|
|
58
|
+
if (current.type !== "dir") throw new Error("Path is not a directory");
|
|
59
|
+
return current;
|
|
60
|
+
};
|
|
61
|
+
const getEntry = (path) => {
|
|
62
|
+
const segments = resolveToSegments(path);
|
|
63
|
+
let current = rootEntry;
|
|
64
|
+
for (const segment of segments) {
|
|
65
|
+
if (current.type !== "dir") return null;
|
|
66
|
+
const next = current.children[segment];
|
|
67
|
+
if (!next) return null;
|
|
68
|
+
current = next;
|
|
69
|
+
}
|
|
70
|
+
return current;
|
|
71
|
+
};
|
|
72
|
+
const readDirectory = async (path) => {
|
|
73
|
+
const entry = getEntry(path);
|
|
74
|
+
if (!entry || entry.type !== "dir") return null;
|
|
75
|
+
return Object.entries(entry.children).map(([name, child]) => ({
|
|
76
|
+
name,
|
|
77
|
+
isDirectory: child.type === "dir"
|
|
78
|
+
}));
|
|
79
|
+
};
|
|
80
|
+
const readFile = async (path) => {
|
|
81
|
+
const entry = getEntry(path);
|
|
82
|
+
if (!entry || entry.type !== "file") return null;
|
|
83
|
+
return entry.content;
|
|
84
|
+
};
|
|
85
|
+
const stat = async (path) => {
|
|
86
|
+
const entry = getEntry(path);
|
|
87
|
+
if (!entry) return null;
|
|
88
|
+
return {
|
|
89
|
+
isFile: entry.type === "file",
|
|
90
|
+
isDirectory: entry.type === "dir"
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
const findFile = async (startPath, targetName) => {
|
|
94
|
+
const startEntry = getEntry(startPath);
|
|
95
|
+
if (!startEntry || startEntry.type !== "dir") return null;
|
|
96
|
+
const stack = [{
|
|
97
|
+
path: normalizePath(startPath),
|
|
98
|
+
entry: startEntry
|
|
99
|
+
}];
|
|
100
|
+
while (stack.length) {
|
|
101
|
+
const current = stack.pop();
|
|
102
|
+
if (!current) break;
|
|
103
|
+
if (current.entry.type === "dir") for (const [name, child] of Object.entries(current.entry.children)) {
|
|
104
|
+
const nextPath = joinPaths(current.path, name);
|
|
105
|
+
if (child.type === "file" && name === targetName) return nextPath;
|
|
106
|
+
if (child.type === "dir") stack.push({
|
|
107
|
+
path: nextPath,
|
|
108
|
+
entry: child
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return null;
|
|
113
|
+
};
|
|
114
|
+
const getResourceDirectory = async (urls) => {
|
|
115
|
+
return readDirectory(joinPaths(root, ...urls));
|
|
116
|
+
};
|
|
117
|
+
const getAllTextWithScene = async () => {
|
|
118
|
+
const scenePath = joinPaths(root, "scene");
|
|
119
|
+
const sceneEntry = getEntry(scenePath);
|
|
120
|
+
if (!sceneEntry || sceneEntry.type !== "dir") return null;
|
|
121
|
+
const map = {};
|
|
122
|
+
for (const [name, child] of Object.entries(sceneEntry.children)) if (child.type === "file" && name.endsWith(".txt")) {
|
|
123
|
+
const fullPath = joinPaths(scenePath, name);
|
|
124
|
+
map[name] = {
|
|
125
|
+
path: fullPath,
|
|
126
|
+
name,
|
|
127
|
+
text: child.content,
|
|
128
|
+
fullPath
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
return map;
|
|
132
|
+
};
|
|
133
|
+
const getTree = () => rootEntry;
|
|
134
|
+
const setTree = (tree) => {
|
|
135
|
+
rootEntry = tree.type === "dir" ? tree : {
|
|
136
|
+
type: "dir",
|
|
137
|
+
children: {}
|
|
138
|
+
};
|
|
139
|
+
emit([{
|
|
140
|
+
type: "setTree",
|
|
141
|
+
tree: rootEntry
|
|
142
|
+
}]);
|
|
143
|
+
};
|
|
144
|
+
const writeFile = async (targetPath, content) => {
|
|
145
|
+
const segments = resolveToSegments(targetPath);
|
|
146
|
+
if (segments.length === 0) return;
|
|
147
|
+
const fileName = segments[segments.length - 1];
|
|
148
|
+
const parent = ensureDirectoryEntry(segments.slice(0, -1));
|
|
149
|
+
parent.children[fileName] = {
|
|
150
|
+
type: "file",
|
|
151
|
+
content
|
|
152
|
+
};
|
|
153
|
+
emit([{
|
|
154
|
+
type: "writeFile",
|
|
155
|
+
path: normalizePath(targetPath),
|
|
156
|
+
content
|
|
157
|
+
}]);
|
|
158
|
+
};
|
|
159
|
+
const mkdir = async (targetPath) => {
|
|
160
|
+
ensureDirectoryEntry(resolveToSegments(targetPath));
|
|
161
|
+
emit([{
|
|
162
|
+
type: "mkdir",
|
|
163
|
+
path: normalizePath(targetPath)
|
|
164
|
+
}]);
|
|
165
|
+
};
|
|
166
|
+
const deletePath = async (targetPath) => {
|
|
167
|
+
const segments = resolveToSegments(targetPath);
|
|
168
|
+
if (segments.length === 0) return;
|
|
169
|
+
const name = segments[segments.length - 1];
|
|
170
|
+
const parentSegments = segments.slice(0, -1);
|
|
171
|
+
const parentEntry = parentSegments.length === 0 ? rootEntry : getEntry(joinPaths(root, ...parentSegments));
|
|
172
|
+
if (!parentEntry || parentEntry.type !== "dir") return;
|
|
173
|
+
delete parentEntry.children[name];
|
|
174
|
+
emit([{
|
|
175
|
+
type: "deletePath",
|
|
176
|
+
path: normalizePath(targetPath)
|
|
177
|
+
}]);
|
|
178
|
+
};
|
|
179
|
+
const rename = async (from, to) => {
|
|
180
|
+
const fromSegments = resolveToSegments(from);
|
|
181
|
+
if (fromSegments.length === 0) return;
|
|
182
|
+
const fromName = fromSegments[fromSegments.length - 1];
|
|
183
|
+
const fromParentSegments = fromSegments.slice(0, -1);
|
|
184
|
+
const fromParentEntry = fromParentSegments.length === 0 ? rootEntry : getEntry(joinPaths(root, ...fromParentSegments));
|
|
185
|
+
if (!fromParentEntry || fromParentEntry.type !== "dir") return;
|
|
186
|
+
const entry = fromParentEntry.children[fromName];
|
|
187
|
+
if (!entry) return;
|
|
188
|
+
delete fromParentEntry.children[fromName];
|
|
189
|
+
const toSegments = resolveToSegments(to);
|
|
190
|
+
if (toSegments.length === 0) return;
|
|
191
|
+
const toName = toSegments[toSegments.length - 1];
|
|
192
|
+
const toParent = ensureDirectoryEntry(toSegments.slice(0, -1));
|
|
193
|
+
toParent.children[toName] = entry;
|
|
194
|
+
emit([{
|
|
195
|
+
type: "rename",
|
|
196
|
+
from: normalizePath(from),
|
|
197
|
+
to: normalizePath(to)
|
|
198
|
+
}]);
|
|
199
|
+
};
|
|
200
|
+
const applyChanges = async (changes) => {
|
|
201
|
+
for (const change of changes) {
|
|
202
|
+
if (change.type === "writeFile") {
|
|
203
|
+
await writeFile(change.path, change.content);
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
if (change.type === "mkdir") {
|
|
207
|
+
await mkdir(change.path);
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
if (change.type === "deletePath") {
|
|
211
|
+
await deletePath(change.path);
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
if (change.type === "rename") {
|
|
215
|
+
await rename(change.from, change.to);
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
if (change.type === "setTree") setTree(change.tree);
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
const onDidChange = (listener) => {
|
|
222
|
+
listeners.add(listener);
|
|
223
|
+
return () => {
|
|
224
|
+
listeners.delete(listener);
|
|
225
|
+
};
|
|
226
|
+
};
|
|
227
|
+
return {
|
|
228
|
+
root,
|
|
229
|
+
currentDirectory: () => root,
|
|
230
|
+
join: (...parts) => joinPaths(...parts),
|
|
231
|
+
stat,
|
|
232
|
+
readDirectory,
|
|
233
|
+
readFile,
|
|
234
|
+
findFile,
|
|
235
|
+
getResourceDirectory,
|
|
236
|
+
getAllTextWithScene,
|
|
237
|
+
getTree,
|
|
238
|
+
setTree,
|
|
239
|
+
writeFile,
|
|
240
|
+
deletePath,
|
|
241
|
+
mkdir,
|
|
242
|
+
rename,
|
|
243
|
+
applyChanges,
|
|
244
|
+
onDidChange
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
function createWebgalClientHandlers(options) {
|
|
248
|
+
const normalizeChange = (change) => {
|
|
249
|
+
if (change.type === "writeFile") return {
|
|
250
|
+
type: "writeFile",
|
|
251
|
+
path: toVfsPath(change.path),
|
|
252
|
+
content: change.content
|
|
253
|
+
};
|
|
254
|
+
if (change.type === "deletePath") return {
|
|
255
|
+
type: "deletePath",
|
|
256
|
+
path: toVfsPath(change.path)
|
|
257
|
+
};
|
|
258
|
+
if (change.type === "mkdir") return {
|
|
259
|
+
type: "mkdir",
|
|
260
|
+
path: toVfsPath(change.path)
|
|
261
|
+
};
|
|
262
|
+
if (change.type === "rename") return {
|
|
263
|
+
type: "rename",
|
|
264
|
+
from: toVfsPath(change.from),
|
|
265
|
+
to: toVfsPath(change.to)
|
|
266
|
+
};
|
|
267
|
+
return change;
|
|
268
|
+
};
|
|
269
|
+
return {
|
|
270
|
+
"client/showTip": options.showTip ?? (() => null),
|
|
271
|
+
"client/currentDirectory": () => options.vfs.currentDirectory(),
|
|
272
|
+
"client/FJoin": (args) => options.vfs.join(...Array.isArray(args) ? args : [args]),
|
|
273
|
+
"client/FStat": (path) => options.vfs.stat(path),
|
|
274
|
+
"client/findFile": ([startPath, targetName]) => options.vfs.findFile(startPath, targetName),
|
|
275
|
+
"client/goPropertyDoc": options.goPropertyDoc ?? (() => null),
|
|
276
|
+
"client/readDirectory": (uriString) => options.vfs.readDirectory(uriToPath(uriString)),
|
|
277
|
+
"client/getAllTextWithScene": () => options.vfs.getAllTextWithScene(),
|
|
278
|
+
"client/getResourceDirectory": (urls) => options.vfs.getResourceDirectory(urls),
|
|
279
|
+
"client/vfs/getTree": () => options.vfs.getTree(),
|
|
280
|
+
"client/vfs/setTree": (tree) => options.vfs.setTree(tree),
|
|
281
|
+
"client/vfs/readFile": (path) => options.vfs.readFile(toVfsPath(path)),
|
|
282
|
+
"client/vfs/writeFile": ({ path, content }) => options.vfs.writeFile(toVfsPath(path), content),
|
|
283
|
+
"client/vfs/deletePath": (path) => options.vfs.deletePath(toVfsPath(path)),
|
|
284
|
+
"client/vfs/mkdir": (path) => options.vfs.mkdir(toVfsPath(path)),
|
|
285
|
+
"client/vfs/rename": ({ from, to }) => options.vfs.rename(toVfsPath(from), toVfsPath(to)),
|
|
286
|
+
"client/vfs/applyChanges": (changes) => options.vfs.applyChanges(changes.map(normalizeChange)),
|
|
287
|
+
...options.overrides ?? {}
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
function registerWebgalClientHandlers(client, handlers) {
|
|
291
|
+
for (const [method, handler] of Object.entries(handlers)) client.onRequest(method, handler);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
//#endregion
|
|
295
|
+
exports.createMemoryFileSystem = createMemoryFileSystem;
|
|
296
|
+
exports.createWebgalClientHandlers = createWebgalClientHandlers;
|
|
297
|
+
exports.registerWebgalClientHandlers = registerWebgalClientHandlers;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
//#region src/index.d.ts
|
|
2
|
+
type DirectoryEntry = {
|
|
3
|
+
name: string;
|
|
4
|
+
isDirectory: boolean;
|
|
5
|
+
};
|
|
6
|
+
type VirtualFileEntry = {
|
|
7
|
+
type: "file";
|
|
8
|
+
content: string;
|
|
9
|
+
};
|
|
10
|
+
type VirtualDirectoryEntry = {
|
|
11
|
+
type: "dir";
|
|
12
|
+
children: Record<string, VirtualEntry>;
|
|
13
|
+
};
|
|
14
|
+
type VirtualEntry = VirtualFileEntry | VirtualDirectoryEntry;
|
|
15
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
16
|
+
type VirtualFileSystemChange = {
|
|
17
|
+
type: "writeFile";
|
|
18
|
+
path: string;
|
|
19
|
+
content: string;
|
|
20
|
+
} | {
|
|
21
|
+
type: "deletePath";
|
|
22
|
+
path: string;
|
|
23
|
+
} | {
|
|
24
|
+
type: "mkdir";
|
|
25
|
+
path: string;
|
|
26
|
+
} | {
|
|
27
|
+
type: "rename";
|
|
28
|
+
from: string;
|
|
29
|
+
to: string;
|
|
30
|
+
} | {
|
|
31
|
+
type: "setTree";
|
|
32
|
+
tree: VirtualEntry;
|
|
33
|
+
};
|
|
34
|
+
type VirtualFileSystemChangeListener = (changes: VirtualFileSystemChange[]) => void;
|
|
35
|
+
type VirtualFileSystem = {
|
|
36
|
+
root: string;
|
|
37
|
+
currentDirectory: () => string | null;
|
|
38
|
+
join: (...parts: string[]) => string;
|
|
39
|
+
stat: (path: string) => Promise<{
|
|
40
|
+
isFile: boolean;
|
|
41
|
+
isDirectory: boolean;
|
|
42
|
+
} | null>;
|
|
43
|
+
readDirectory: (path: string) => Promise<DirectoryEntry[] | null>;
|
|
44
|
+
readFile: (path: string) => Promise<string | null>;
|
|
45
|
+
findFile: (startPath: string, targetName: string) => Promise<string | null>;
|
|
46
|
+
getResourceDirectory: (urls: string[]) => Promise<DirectoryEntry[] | null>;
|
|
47
|
+
getAllTextWithScene: () => Promise<Record<string, {
|
|
48
|
+
path: string;
|
|
49
|
+
name: string;
|
|
50
|
+
text: string;
|
|
51
|
+
fullPath: string;
|
|
52
|
+
}> | null>;
|
|
53
|
+
getTree: () => VirtualEntry;
|
|
54
|
+
setTree: (tree: VirtualEntry) => void;
|
|
55
|
+
writeFile: (path: string, content: string) => Promise<void>;
|
|
56
|
+
deletePath: (path: string) => Promise<void>;
|
|
57
|
+
mkdir: (path: string) => Promise<void>;
|
|
58
|
+
rename: (from: string, to: string) => Promise<void>;
|
|
59
|
+
applyChanges: (changes: VirtualFileSystemChange[]) => Promise<void>;
|
|
60
|
+
onDidChange: (listener: VirtualFileSystemChangeListener) => () => void;
|
|
61
|
+
};
|
|
62
|
+
type WebgalClientHandlers = {
|
|
63
|
+
"client/showTip": (message: string) => MaybePromise<unknown>;
|
|
64
|
+
"client/currentDirectory": () => MaybePromise<string | null>;
|
|
65
|
+
"client/FJoin": (args: string | string[]) => MaybePromise<string | null>;
|
|
66
|
+
"client/FStat": (path: string) => MaybePromise<unknown>;
|
|
67
|
+
"client/findFile": (args: [string, string]) => MaybePromise<string | null>;
|
|
68
|
+
"client/goPropertyDoc": (pathSegments: string[]) => MaybePromise<unknown>;
|
|
69
|
+
"client/readDirectory": (uriString: string) => MaybePromise<unknown>;
|
|
70
|
+
"client/getAllTextWithScene": () => MaybePromise<unknown>;
|
|
71
|
+
"client/getResourceDirectory": (urls: string[]) => MaybePromise<unknown>;
|
|
72
|
+
"client/vfs/getTree": () => MaybePromise<VirtualEntry>;
|
|
73
|
+
"client/vfs/setTree": (tree: VirtualEntry) => MaybePromise<unknown>;
|
|
74
|
+
"client/vfs/readFile": (path: string) => MaybePromise<string | null>;
|
|
75
|
+
"client/vfs/writeFile": (args: {
|
|
76
|
+
path: string;
|
|
77
|
+
content: string;
|
|
78
|
+
}) => MaybePromise<unknown>;
|
|
79
|
+
"client/vfs/deletePath": (path: string) => MaybePromise<unknown>;
|
|
80
|
+
"client/vfs/mkdir": (path: string) => MaybePromise<unknown>;
|
|
81
|
+
"client/vfs/rename": (args: {
|
|
82
|
+
from: string;
|
|
83
|
+
to: string;
|
|
84
|
+
}) => MaybePromise<unknown>;
|
|
85
|
+
"client/vfs/applyChanges": (changes: VirtualFileSystemChange[]) => MaybePromise<unknown>;
|
|
86
|
+
};
|
|
87
|
+
type LanguageClientLike = {
|
|
88
|
+
onRequest: (method: string, handler: (...args: any[]) => unknown) => void;
|
|
89
|
+
};
|
|
90
|
+
type CreateWebgalClientHandlersOptions = {
|
|
91
|
+
vfs: VirtualFileSystem;
|
|
92
|
+
showTip?: (message: string) => unknown;
|
|
93
|
+
goPropertyDoc?: (pathSegments: string[]) => unknown;
|
|
94
|
+
overrides?: Partial<WebgalClientHandlers>;
|
|
95
|
+
};
|
|
96
|
+
declare function createMemoryFileSystem(options?: {
|
|
97
|
+
root?: string;
|
|
98
|
+
tree?: VirtualEntry;
|
|
99
|
+
}): VirtualFileSystem;
|
|
100
|
+
declare function createWebgalClientHandlers(options: CreateWebgalClientHandlersOptions): WebgalClientHandlers;
|
|
101
|
+
declare function registerWebgalClientHandlers(client: LanguageClientLike, handlers: Partial<WebgalClientHandlers>): void;
|
|
102
|
+
//#endregion
|
|
103
|
+
export { CreateWebgalClientHandlersOptions, DirectoryEntry, LanguageClientLike, MaybePromise, VirtualDirectoryEntry, VirtualEntry, VirtualFileEntry, VirtualFileSystem, VirtualFileSystemChange, VirtualFileSystemChangeListener, WebgalClientHandlers, createMemoryFileSystem, createWebgalClientHandlers, registerWebgalClientHandlers };
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
//#region src/index.d.ts
|
|
2
|
+
type DirectoryEntry = {
|
|
3
|
+
name: string;
|
|
4
|
+
isDirectory: boolean;
|
|
5
|
+
};
|
|
6
|
+
type VirtualFileEntry = {
|
|
7
|
+
type: "file";
|
|
8
|
+
content: string;
|
|
9
|
+
};
|
|
10
|
+
type VirtualDirectoryEntry = {
|
|
11
|
+
type: "dir";
|
|
12
|
+
children: Record<string, VirtualEntry>;
|
|
13
|
+
};
|
|
14
|
+
type VirtualEntry = VirtualFileEntry | VirtualDirectoryEntry;
|
|
15
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
16
|
+
type VirtualFileSystemChange = {
|
|
17
|
+
type: "writeFile";
|
|
18
|
+
path: string;
|
|
19
|
+
content: string;
|
|
20
|
+
} | {
|
|
21
|
+
type: "deletePath";
|
|
22
|
+
path: string;
|
|
23
|
+
} | {
|
|
24
|
+
type: "mkdir";
|
|
25
|
+
path: string;
|
|
26
|
+
} | {
|
|
27
|
+
type: "rename";
|
|
28
|
+
from: string;
|
|
29
|
+
to: string;
|
|
30
|
+
} | {
|
|
31
|
+
type: "setTree";
|
|
32
|
+
tree: VirtualEntry;
|
|
33
|
+
};
|
|
34
|
+
type VirtualFileSystemChangeListener = (changes: VirtualFileSystemChange[]) => void;
|
|
35
|
+
type VirtualFileSystem = {
|
|
36
|
+
root: string;
|
|
37
|
+
currentDirectory: () => string | null;
|
|
38
|
+
join: (...parts: string[]) => string;
|
|
39
|
+
stat: (path: string) => Promise<{
|
|
40
|
+
isFile: boolean;
|
|
41
|
+
isDirectory: boolean;
|
|
42
|
+
} | null>;
|
|
43
|
+
readDirectory: (path: string) => Promise<DirectoryEntry[] | null>;
|
|
44
|
+
readFile: (path: string) => Promise<string | null>;
|
|
45
|
+
findFile: (startPath: string, targetName: string) => Promise<string | null>;
|
|
46
|
+
getResourceDirectory: (urls: string[]) => Promise<DirectoryEntry[] | null>;
|
|
47
|
+
getAllTextWithScene: () => Promise<Record<string, {
|
|
48
|
+
path: string;
|
|
49
|
+
name: string;
|
|
50
|
+
text: string;
|
|
51
|
+
fullPath: string;
|
|
52
|
+
}> | null>;
|
|
53
|
+
getTree: () => VirtualEntry;
|
|
54
|
+
setTree: (tree: VirtualEntry) => void;
|
|
55
|
+
writeFile: (path: string, content: string) => Promise<void>;
|
|
56
|
+
deletePath: (path: string) => Promise<void>;
|
|
57
|
+
mkdir: (path: string) => Promise<void>;
|
|
58
|
+
rename: (from: string, to: string) => Promise<void>;
|
|
59
|
+
applyChanges: (changes: VirtualFileSystemChange[]) => Promise<void>;
|
|
60
|
+
onDidChange: (listener: VirtualFileSystemChangeListener) => () => void;
|
|
61
|
+
};
|
|
62
|
+
type WebgalClientHandlers = {
|
|
63
|
+
"client/showTip": (message: string) => MaybePromise<unknown>;
|
|
64
|
+
"client/currentDirectory": () => MaybePromise<string | null>;
|
|
65
|
+
"client/FJoin": (args: string | string[]) => MaybePromise<string | null>;
|
|
66
|
+
"client/FStat": (path: string) => MaybePromise<unknown>;
|
|
67
|
+
"client/findFile": (args: [string, string]) => MaybePromise<string | null>;
|
|
68
|
+
"client/goPropertyDoc": (pathSegments: string[]) => MaybePromise<unknown>;
|
|
69
|
+
"client/readDirectory": (uriString: string) => MaybePromise<unknown>;
|
|
70
|
+
"client/getAllTextWithScene": () => MaybePromise<unknown>;
|
|
71
|
+
"client/getResourceDirectory": (urls: string[]) => MaybePromise<unknown>;
|
|
72
|
+
"client/vfs/getTree": () => MaybePromise<VirtualEntry>;
|
|
73
|
+
"client/vfs/setTree": (tree: VirtualEntry) => MaybePromise<unknown>;
|
|
74
|
+
"client/vfs/readFile": (path: string) => MaybePromise<string | null>;
|
|
75
|
+
"client/vfs/writeFile": (args: {
|
|
76
|
+
path: string;
|
|
77
|
+
content: string;
|
|
78
|
+
}) => MaybePromise<unknown>;
|
|
79
|
+
"client/vfs/deletePath": (path: string) => MaybePromise<unknown>;
|
|
80
|
+
"client/vfs/mkdir": (path: string) => MaybePromise<unknown>;
|
|
81
|
+
"client/vfs/rename": (args: {
|
|
82
|
+
from: string;
|
|
83
|
+
to: string;
|
|
84
|
+
}) => MaybePromise<unknown>;
|
|
85
|
+
"client/vfs/applyChanges": (changes: VirtualFileSystemChange[]) => MaybePromise<unknown>;
|
|
86
|
+
};
|
|
87
|
+
type LanguageClientLike = {
|
|
88
|
+
onRequest: (method: string, handler: (...args: any[]) => unknown) => void;
|
|
89
|
+
};
|
|
90
|
+
type CreateWebgalClientHandlersOptions = {
|
|
91
|
+
vfs: VirtualFileSystem;
|
|
92
|
+
showTip?: (message: string) => unknown;
|
|
93
|
+
goPropertyDoc?: (pathSegments: string[]) => unknown;
|
|
94
|
+
overrides?: Partial<WebgalClientHandlers>;
|
|
95
|
+
};
|
|
96
|
+
declare function createMemoryFileSystem(options?: {
|
|
97
|
+
root?: string;
|
|
98
|
+
tree?: VirtualEntry;
|
|
99
|
+
}): VirtualFileSystem;
|
|
100
|
+
declare function createWebgalClientHandlers(options: CreateWebgalClientHandlersOptions): WebgalClientHandlers;
|
|
101
|
+
declare function registerWebgalClientHandlers(client: LanguageClientLike, handlers: Partial<WebgalClientHandlers>): void;
|
|
102
|
+
//#endregion
|
|
103
|
+
export { CreateWebgalClientHandlersOptions, DirectoryEntry, LanguageClientLike, MaybePromise, VirtualDirectoryEntry, VirtualEntry, VirtualFileEntry, VirtualFileSystem, VirtualFileSystemChange, VirtualFileSystemChangeListener, WebgalClientHandlers, createMemoryFileSystem, createWebgalClientHandlers, registerWebgalClientHandlers };
|