@webgal/language-service 0.0.2-alpha.5 → 0.0.3-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/README.en.md ADDED
@@ -0,0 +1,15 @@
1
+ # @webgal/language-service
2
+
3
+ English | [中文](./README.md)
4
+
5
+ WebGAL language service integration package, providing capabilities such as Monaco initialization, syntax and theme resources, VFS, and client processors.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm i @webgal/language-service
11
+ ```
12
+
13
+ ## Repository
14
+
15
+ https://github.com/xiaoxustudio/webgal-language-tools/tree/main/packages/language-service
package/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # @webgal/language-service
2
+
3
+ [English](./README.en.md) | 中文
4
+
5
+ WebGAL 语言服务集成包,提供 Monaco 初始化、语法与主题资源、VFS 与客户端处理器等能力。
6
+
7
+ ## 安装
8
+
9
+ ```bash
10
+ npm i @webgal/language-service
11
+ ```
12
+
13
+ ## 仓库
14
+
15
+ https://github.com/xiaoxustudio/webgal-language-tools/tree/main/packages/language-service
@@ -1,4 +1,4 @@
1
- import { t as getState } from "./providerState-DrFcJbqe.mjs";
1
+ import { t as getState } from "./providerState-_ZvKXErw.mjs";
2
2
  import { FileType } from "@volar/language-service";
3
3
  import { URI } from "vscode-uri";
4
4
 
@@ -33,6 +33,12 @@ const toVfsPath = (value) => value.startsWith("file://") ? uriToPath(value) : va
33
33
 
34
34
  //#endregion
35
35
  //#region src/vfs/adapter.ts
36
+ /**
37
+ * 创建虚拟文件系统适配器
38
+ * 将Volar可写文件系统封装为统一的虚拟文件系统接口
39
+ * @param fs - Volar可写文件系统实例
40
+ * @returns 返回虚拟文件系统实例,提供文件读写、目录操作等功能
41
+ */
36
42
  function createVirtualFileSystem(fs) {
37
43
  const root = fs.root;
38
44
  return {
@@ -116,6 +122,14 @@ function createVirtualFileSystem(fs) {
116
122
  onDidChange: (listener) => fs.onDidChange(listener)
117
123
  };
118
124
  }
125
+ /**
126
+ * 创建Volar文件系统适配器
127
+ * 将虚拟文件系统封装为Volar语言服务所需的FileSystem接口
128
+ * @param vfs - 虚拟文件系统实例
129
+ * @param options - 配置选项
130
+ * @param options.uriToPath - 可选的URI到路径的转换函数,默认使用内置的转换函数
131
+ * @returns 返回符合Volar FileSystem接口的文件系统实例
132
+ */
119
133
  function createVolarFileSystem(vfs, options) {
120
134
  const uriToPathImpl = options?.uriToPath ?? ((uri) => uriToPath(uri));
121
135
  return {
@@ -145,6 +159,14 @@ function createVolarFileSystem(vfs, options) {
145
159
 
146
160
  //#endregion
147
161
  //#region src/vfs/memory.ts
162
+ /**
163
+ * 创建基于内存的Volar可写文件系统
164
+ * 该文件系统将所有文件和目录存储在内存中,不持久化到磁盘
165
+ * @param options - 配置选项
166
+ * @param options.root - 根目录路径,默认为"/"
167
+ * @param options.tree - 可选的初始虚拟文件树结构
168
+ * @returns 返回Volar可写文件系统实例,支持文件读写、目录操作和变更监听
169
+ */
148
170
  function createMemoryVolarFileSystem(options) {
149
171
  const root = normalizePath(toVfsPath(options?.root ?? "/"));
150
172
  let rootEntry = options?.tree && options.tree.type === "dir" ? options.tree : {
@@ -298,6 +320,12 @@ function createMemoryVolarFileSystem(options) {
298
320
 
299
321
  //#endregion
300
322
  //#region src/client-handlers.ts
323
+ /**
324
+ * 创建Webgal客户端处理器
325
+ *
326
+ * @param options - 创建处理器的配置选项
327
+ * @returns 返回一个包含各种客户端处理器方法的对象
328
+ */
301
329
  function createWebgalClientHandlers(options) {
302
330
  const normalizeChange = (change) => {
303
331
  if (change.type === "writeFile") return {
@@ -324,7 +352,10 @@ function createWebgalClientHandlers(options) {
324
352
  "workspace/documentLink/refresh": () => null,
325
353
  "client/showTip": options.showTip ?? (() => null),
326
354
  "client/currentDirectory": () => options.vfs.currentDirectory(),
327
- "client/FJoin": (args) => options.vfs.join(...Array.isArray(args) ? args : [args]),
355
+ "client/FJoin": (args) => {
356
+ const parts = Array.isArray(args) ? args : [args];
357
+ return options.vfs.join(...parts.map(toVfsPath));
358
+ },
328
359
  "client/FStat": (path) => options.vfs.stat(toVfsPath(path)),
329
360
  "client/findFile": ([startPath, targetName]) => options.vfs.findFile(toVfsPath(startPath), targetName),
330
361
  "client/goPropertyDoc": options.goPropertyDoc ?? ((path) => getState(path)),
@@ -342,6 +373,12 @@ function createWebgalClientHandlers(options) {
342
373
  ...options.overrides ?? {}
343
374
  };
344
375
  }
376
+ /**
377
+ * 注册WebGal客户端处理器
378
+ *
379
+ * @param client - 语言客户端实例,实现了LanguageClientLike接口
380
+ * @param handlers - WebGal客户端处理器的可选映射对象,包含要注册的各种处理器方法
381
+ */
345
382
  function registerWebgalClientHandlers(client, handlers) {
346
383
  for (const [method, handler] of Object.entries(handlers)) client.onRequest(method, handler);
347
384
  }
@@ -1,5 +1,5 @@
1
1
  const require_chunk = require('./chunk-C0xms8kb.cjs');
2
- const require_providerState = require('./providerState-Du_Ge3bW.cjs');
2
+ const require_providerState = require('./providerState-Dip2XHx4.cjs');
3
3
  let _volar_language_service = require("@volar/language-service");
4
4
  let vscode_uri = require("vscode-uri");
5
5
 
@@ -34,6 +34,12 @@ const toVfsPath = (value) => value.startsWith("file://") ? uriToPath(value) : va
34
34
 
35
35
  //#endregion
36
36
  //#region src/vfs/adapter.ts
37
+ /**
38
+ * 创建虚拟文件系统适配器
39
+ * 将Volar可写文件系统封装为统一的虚拟文件系统接口
40
+ * @param fs - Volar可写文件系统实例
41
+ * @returns 返回虚拟文件系统实例,提供文件读写、目录操作等功能
42
+ */
37
43
  function createVirtualFileSystem(fs) {
38
44
  const root = fs.root;
39
45
  return {
@@ -117,6 +123,14 @@ function createVirtualFileSystem(fs) {
117
123
  onDidChange: (listener) => fs.onDidChange(listener)
118
124
  };
119
125
  }
126
+ /**
127
+ * 创建Volar文件系统适配器
128
+ * 将虚拟文件系统封装为Volar语言服务所需的FileSystem接口
129
+ * @param vfs - 虚拟文件系统实例
130
+ * @param options - 配置选项
131
+ * @param options.uriToPath - 可选的URI到路径的转换函数,默认使用内置的转换函数
132
+ * @returns 返回符合Volar FileSystem接口的文件系统实例
133
+ */
120
134
  function createVolarFileSystem(vfs, options) {
121
135
  const uriToPathImpl = options?.uriToPath ?? ((uri) => uriToPath(uri));
122
136
  return {
@@ -146,6 +160,14 @@ function createVolarFileSystem(vfs, options) {
146
160
 
147
161
  //#endregion
148
162
  //#region src/vfs/memory.ts
163
+ /**
164
+ * 创建基于内存的Volar可写文件系统
165
+ * 该文件系统将所有文件和目录存储在内存中,不持久化到磁盘
166
+ * @param options - 配置选项
167
+ * @param options.root - 根目录路径,默认为"/"
168
+ * @param options.tree - 可选的初始虚拟文件树结构
169
+ * @returns 返回Volar可写文件系统实例,支持文件读写、目录操作和变更监听
170
+ */
149
171
  function createMemoryVolarFileSystem(options) {
150
172
  const root = normalizePath(toVfsPath(options?.root ?? "/"));
151
173
  let rootEntry = options?.tree && options.tree.type === "dir" ? options.tree : {
@@ -299,6 +321,12 @@ function createMemoryVolarFileSystem(options) {
299
321
 
300
322
  //#endregion
301
323
  //#region src/client-handlers.ts
324
+ /**
325
+ * 创建Webgal客户端处理器
326
+ *
327
+ * @param options - 创建处理器的配置选项
328
+ * @returns 返回一个包含各种客户端处理器方法的对象
329
+ */
302
330
  function createWebgalClientHandlers(options) {
303
331
  const normalizeChange = (change) => {
304
332
  if (change.type === "writeFile") return {
@@ -325,7 +353,10 @@ function createWebgalClientHandlers(options) {
325
353
  "workspace/documentLink/refresh": () => null,
326
354
  "client/showTip": options.showTip ?? (() => null),
327
355
  "client/currentDirectory": () => options.vfs.currentDirectory(),
328
- "client/FJoin": (args) => options.vfs.join(...Array.isArray(args) ? args : [args]),
356
+ "client/FJoin": (args) => {
357
+ const parts = Array.isArray(args) ? args : [args];
358
+ return options.vfs.join(...parts.map(toVfsPath));
359
+ },
329
360
  "client/FStat": (path) => options.vfs.stat(toVfsPath(path)),
330
361
  "client/findFile": ([startPath, targetName]) => options.vfs.findFile(toVfsPath(startPath), targetName),
331
362
  "client/goPropertyDoc": options.goPropertyDoc ?? ((path) => require_providerState.getState(path)),
@@ -343,6 +374,12 @@ function createWebgalClientHandlers(options) {
343
374
  ...options.overrides ?? {}
344
375
  };
345
376
  }
377
+ /**
378
+ * 注册WebGal客户端处理器
379
+ *
380
+ * @param client - 语言客户端实例,实现了LanguageClientLike接口
381
+ * @param handlers - WebGal客户端处理器的可选映射对象,包含要注册的各种处理器方法
382
+ */
346
383
  function registerWebgalClientHandlers(client, handlers) {
347
384
  for (const [method, handler] of Object.entries(handlers)) client.onRequest(method, handler);
348
385
  }
@@ -0,0 +1,46 @@
1
+ import { c as VirtualFileSystem, d as VolarWritableFileSystem, o as VirtualEntry } from "./types-B7zc-Eke.mjs";
2
+ import { FileSystem } from "@volar/language-service";
3
+ import { URI } from "vscode-uri";
4
+
5
+ //#region src/vfs/adapter.d.ts
6
+ /**
7
+ * 创建虚拟文件系统适配器
8
+ * 将Volar可写文件系统封装为统一的虚拟文件系统接口
9
+ * @param fs - Volar可写文件系统实例
10
+ * @returns 返回虚拟文件系统实例,提供文件读写、目录操作等功能
11
+ */
12
+ declare function createVirtualFileSystem(fs: VolarWritableFileSystem): VirtualFileSystem;
13
+ /**
14
+ * 创建Volar文件系统适配器
15
+ * 将虚拟文件系统封装为Volar语言服务所需的FileSystem接口
16
+ * @param vfs - 虚拟文件系统实例
17
+ * @param options - 配置选项
18
+ * @param options.uriToPath - 可选的URI到路径的转换函数,默认使用内置的转换函数
19
+ * @returns 返回符合Volar FileSystem接口的文件系统实例
20
+ */
21
+ declare function createVolarFileSystem(vfs: VirtualFileSystem, options?: {
22
+ uriToPath?: (uri: URI) => string;
23
+ }): FileSystem;
24
+ //#endregion
25
+ //#region src/vfs/memory.d.ts
26
+ /**
27
+ * 创建基于内存的Volar可写文件系统
28
+ * 该文件系统将所有文件和目录存储在内存中,不持久化到磁盘
29
+ * @param options - 配置选项
30
+ * @param options.root - 根目录路径,默认为"/"
31
+ * @param options.tree - 可选的初始虚拟文件树结构
32
+ * @returns 返回Volar可写文件系统实例,支持文件读写、目录操作和变更监听
33
+ */
34
+ declare function createMemoryVolarFileSystem(options?: {
35
+ root?: string;
36
+ tree?: VirtualEntry;
37
+ }): VolarWritableFileSystem;
38
+ //#endregion
39
+ //#region src/vfs/utils.d.ts
40
+ declare const normalizePath: (input: string) => string;
41
+ declare const joinPaths: (...parts: string[]) => string;
42
+ declare const uriToPath: (value: string | URI) => string;
43
+ declare const pathToUri: (path: string) => URI;
44
+ declare const toVfsPath: (value: string) => string;
45
+ //#endregion
46
+ export { uriToPath as a, createVolarFileSystem as c, toVfsPath as i, normalizePath as n, createMemoryVolarFileSystem as o, pathToUri as r, createVirtualFileSystem as s, joinPaths as t };
package/build/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_client_handlers = require('./client-handlers-B-uz20CX.cjs');
2
+ const require_client_handlers = require('./client-handlers-bQ116UIT.cjs');
3
3
 
4
4
  exports.createMemoryVolarFileSystem = require_client_handlers.createMemoryVolarFileSystem;
5
5
  exports.createVirtualFileSystem = require_client_handlers.createVirtualFileSystem;
package/build/index.d.cts CHANGED
@@ -1,14 +1,36 @@
1
- import { a as VirtualDirectoryEntry, c as VirtualFileSystem, d as VolarWritableFileSystem, f as WebgalClientHandlers, i as MaybePromise, l as VirtualFileSystemChange, n as DirectoryEntry, o as VirtualEntry, r as LanguageClientLike, s as VirtualFileEntry, t as CreateWebgalClientHandlersOptions, u as VirtualFileSystemChangeListener } from "./types-BPQnQEAd.cjs";
1
+ import { a as VirtualDirectoryEntry, c as VirtualFileSystem, d as VolarWritableFileSystem, f as WebgalClientHandlers, i as MaybePromise, l as VirtualFileSystemChange, n as DirectoryEntry, o as VirtualEntry, r as LanguageClientLike, s as VirtualFileEntry, t as CreateWebgalClientHandlersOptions, u as VirtualFileSystemChangeListener } from "./types-DwRo8Zlp.cjs";
2
2
  import { FileSystem } from "@volar/language-service";
3
3
  import { URI } from "vscode-uri";
4
4
 
5
5
  //#region src/vfs/adapter.d.ts
6
+ /**
7
+ * 创建虚拟文件系统适配器
8
+ * 将Volar可写文件系统封装为统一的虚拟文件系统接口
9
+ * @param fs - Volar可写文件系统实例
10
+ * @returns 返回虚拟文件系统实例,提供文件读写、目录操作等功能
11
+ */
6
12
  declare function createVirtualFileSystem(fs: VolarWritableFileSystem): VirtualFileSystem;
13
+ /**
14
+ * 创建Volar文件系统适配器
15
+ * 将虚拟文件系统封装为Volar语言服务所需的FileSystem接口
16
+ * @param vfs - 虚拟文件系统实例
17
+ * @param options - 配置选项
18
+ * @param options.uriToPath - 可选的URI到路径的转换函数,默认使用内置的转换函数
19
+ * @returns 返回符合Volar FileSystem接口的文件系统实例
20
+ */
7
21
  declare function createVolarFileSystem(vfs: VirtualFileSystem, options?: {
8
22
  uriToPath?: (uri: URI) => string;
9
23
  }): FileSystem;
10
24
  //#endregion
11
25
  //#region src/vfs/memory.d.ts
26
+ /**
27
+ * 创建基于内存的Volar可写文件系统
28
+ * 该文件系统将所有文件和目录存储在内存中,不持久化到磁盘
29
+ * @param options - 配置选项
30
+ * @param options.root - 根目录路径,默认为"/"
31
+ * @param options.tree - 可选的初始虚拟文件树结构
32
+ * @returns 返回Volar可写文件系统实例,支持文件读写、目录操作和变更监听
33
+ */
12
34
  declare function createMemoryVolarFileSystem(options?: {
13
35
  root?: string;
14
36
  tree?: VirtualEntry;
@@ -22,7 +44,19 @@ declare const pathToUri: (path: string) => URI;
22
44
  declare const toVfsPath: (value: string) => string;
23
45
  //#endregion
24
46
  //#region src/client-handlers.d.ts
47
+ /**
48
+ * 创建Webgal客户端处理器
49
+ *
50
+ * @param options - 创建处理器的配置选项
51
+ * @returns 返回一个包含各种客户端处理器方法的对象
52
+ */
25
53
  declare function createWebgalClientHandlers(options: CreateWebgalClientHandlersOptions): WebgalClientHandlers;
54
+ /**
55
+ * 注册WebGal客户端处理器
56
+ *
57
+ * @param client - 语言客户端实例,实现了LanguageClientLike接口
58
+ * @param handlers - WebGal客户端处理器的可选映射对象,包含要注册的各种处理器方法
59
+ */
26
60
  declare function registerWebgalClientHandlers(client: LanguageClientLike, handlers: Partial<WebgalClientHandlers>): void;
27
61
  //#endregion
28
62
  export { CreateWebgalClientHandlersOptions, DirectoryEntry, LanguageClientLike, MaybePromise, VirtualDirectoryEntry, VirtualEntry, VirtualFileEntry, VirtualFileSystem, VirtualFileSystemChange, VirtualFileSystemChangeListener, VolarWritableFileSystem, WebgalClientHandlers, createMemoryVolarFileSystem, createVirtualFileSystem, createVolarFileSystem, createWebgalClientHandlers, joinPaths, normalizePath, pathToUri, registerWebgalClientHandlers, toVfsPath, uriToPath };
package/build/index.d.mts CHANGED
@@ -1,8 +1,20 @@
1
- import { a as VirtualDirectoryEntry, c as VirtualFileSystem, d as VolarWritableFileSystem, f as WebgalClientHandlers, i as MaybePromise, l as VirtualFileSystemChange, n as DirectoryEntry, o as VirtualEntry, r as LanguageClientLike, s as VirtualFileEntry, t as CreateWebgalClientHandlersOptions, u as VirtualFileSystemChangeListener } from "./types-CBH-p_Iu.mjs";
2
- import { a as uriToPath, c as createVolarFileSystem, i as toVfsPath, n as normalizePath, o as createMemoryVolarFileSystem, r as pathToUri, s as createVirtualFileSystem, t as joinPaths } from "./index-BF2WhBpG.mjs";
1
+ import { a as VirtualDirectoryEntry, c as VirtualFileSystem, d as VolarWritableFileSystem, f as WebgalClientHandlers, i as MaybePromise, l as VirtualFileSystemChange, n as DirectoryEntry, o as VirtualEntry, r as LanguageClientLike, s as VirtualFileEntry, t as CreateWebgalClientHandlersOptions, u as VirtualFileSystemChangeListener } from "./types-B7zc-Eke.mjs";
2
+ import { a as uriToPath, c as createVolarFileSystem, i as toVfsPath, n as normalizePath, o as createMemoryVolarFileSystem, r as pathToUri, s as createVirtualFileSystem, t as joinPaths } from "./index-Bbu_H5AG.mjs";
3
3
 
4
4
  //#region src/client-handlers.d.ts
5
+ /**
6
+ * 创建Webgal客户端处理器
7
+ *
8
+ * @param options - 创建处理器的配置选项
9
+ * @returns 返回一个包含各种客户端处理器方法的对象
10
+ */
5
11
  declare function createWebgalClientHandlers(options: CreateWebgalClientHandlersOptions): WebgalClientHandlers;
12
+ /**
13
+ * 注册WebGal客户端处理器
14
+ *
15
+ * @param client - 语言客户端实例,实现了LanguageClientLike接口
16
+ * @param handlers - WebGal客户端处理器的可选映射对象,包含要注册的各种处理器方法
17
+ */
6
18
  declare function registerWebgalClientHandlers(client: LanguageClientLike, handlers: Partial<WebgalClientHandlers>): void;
7
19
  //#endregion
8
20
  export { CreateWebgalClientHandlersOptions, DirectoryEntry, LanguageClientLike, MaybePromise, VirtualDirectoryEntry, VirtualEntry, VirtualFileEntry, VirtualFileSystem, VirtualFileSystemChange, VirtualFileSystemChangeListener, VolarWritableFileSystem, WebgalClientHandlers, createMemoryVolarFileSystem, createVirtualFileSystem, createVolarFileSystem, createWebgalClientHandlers, joinPaths, normalizePath, pathToUri, registerWebgalClientHandlers, toVfsPath, uriToPath };
package/build/index.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { a as createVolarFileSystem, c as pathToUri, i as createVirtualFileSystem, l as toVfsPath, n as registerWebgalClientHandlers, o as joinPaths, r as createMemoryVolarFileSystem, s as normalizePath, t as createWebgalClientHandlers, u as uriToPath } from "./client-handlers-niazfK9_.mjs";
1
+ import { a as createVolarFileSystem, c as pathToUri, i as createVirtualFileSystem, l as toVfsPath, n as registerWebgalClientHandlers, o as joinPaths, r as createMemoryVolarFileSystem, s as normalizePath, t as createWebgalClientHandlers, u as uriToPath } from "./client-handlers--qNaay52.mjs";
2
2
 
3
3
  export { createMemoryVolarFileSystem, createVirtualFileSystem, createVolarFileSystem, createWebgalClientHandlers, joinPaths, normalizePath, pathToUri, registerWebgalClientHandlers, toVfsPath, uriToPath };
@@ -187,10 +187,6 @@ var language_configuration_default = {
187
187
  "close": "`",
188
188
  "notIn": ["string", "comment"]
189
189
  },
190
- {
191
- "open": ":",
192
- "close": ";"
193
- },
194
190
  {
195
191
  "open": ";area",
196
192
  "close": ";endarea"
@@ -186,10 +186,6 @@ var language_configuration_default = {
186
186
  "close": "`",
187
187
  "notIn": ["string", "comment"]
188
188
  },
189
- {
190
- "open": ":",
191
- "close": ";"
192
- },
193
189
  {
194
190
  "open": ";area",
195
191
  "close": ";endarea"
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_chunk = require('../chunk-C0xms8kb.cjs');
3
- const require_client_handlers = require('../client-handlers-B-uz20CX.cjs');
3
+ const require_client_handlers = require('../client-handlers-bQ116UIT.cjs');
4
4
  const require_syntaxes = require('../syntaxes.cjs');
5
5
  const require_themes = require('../themes.cjs');
6
6
  let vscode_ws_jsonrpc = require("vscode-ws-jsonrpc");
@@ -15,11 +15,28 @@ _codingame_monaco_vscode_theme_service_override = require_chunk.__toESM(_codinga
15
15
  let _codingame_monaco_vscode_textmate_service_override = require("@codingame/monaco-vscode-textmate-service-override");
16
16
  _codingame_monaco_vscode_textmate_service_override = require_chunk.__toESM(_codingame_monaco_vscode_textmate_service_override);
17
17
  require("vscode/localExtensionHost");
18
+ let monaco_editor = require("monaco-editor");
19
+ monaco_editor = require_chunk.__toESM(monaco_editor);
18
20
 
19
21
  //#region src/monaco/monaco.ts
22
+ /**
23
+ * 创建虚拟文件系统
24
+ * @param options - 配置选项
25
+ * @param options.root - 根目录路径,默认为 "file:///"
26
+ * @param options.tree - 可选的虚拟文件树结构
27
+ * @returns 返回一个虚拟文件系统实例
28
+ */
20
29
  function createMemoryFileSystem(options) {
21
30
  return require_client_handlers.createVirtualFileSystem(require_client_handlers.createMemoryVolarFileSystem(options));
22
31
  }
32
+ /**
33
+ * 创建WebGAL Monaco语言客户端(WebSocket连接模式)
34
+ * @param options - 配置选项
35
+ * @param options.languageServerUrl - 语言服务器WebSocket URL
36
+ * @param options.editor - Monaco编辑器实例
37
+ * @param options.virtualFileSystem - 可选的虚拟文件系统,未提供时将创建默认的内存文件系统
38
+ * @returns 返回包含WebSocket连接和虚拟文件系统的对象
39
+ */
23
40
  const createWebgalMonacoLanguageClient = (options) => {
24
41
  const { languageServerUrl, editor } = options;
25
42
  const editorInstance = editor;
@@ -47,6 +64,14 @@ const createWebgalMonacoLanguageClient = (options) => {
47
64
  vfs
48
65
  };
49
66
  };
67
+ /**
68
+ * 创建WebGAL Monaco语言客户端(Worker模式)
69
+ * @param options - 配置选项
70
+ * @param options.editor - Monaco编辑器实例
71
+ * @param options.worker - Web Worker实例
72
+ * @param options.virtualFileSystem - 可选的虚拟文件系统,未提供时将创建默认的内存文件系统
73
+ * @returns 返回包含Worker实例和虚拟文件系统的对象
74
+ */
50
75
  const createWebgalMonacoLanguageClientWithWorker = (options) => {
51
76
  const { worker, editor } = options;
52
77
  const editorInstance = editor;
@@ -138,6 +163,10 @@ const createLanguageClient = (messageTransports, options) => {
138
163
  //#endregion
139
164
  //#region src/monaco/monaco-init.ts
140
165
  let initPromise = null;
166
+ /**
167
+ * 初始化资源映射对象
168
+ * 包含WebGAL语言服务所需的语法高亮、语言配置和主题等资源
169
+ */
141
170
  const initResources = {
142
171
  "./webgal.tmLanguage.json": require_syntaxes.webgalGrammar,
143
172
  "./webgal-config.tmLanguage.json": require_syntaxes.webgalConfigGrammar,
@@ -145,6 +174,12 @@ const initResources = {
145
174
  "./dark.json": require_themes.webgalDarkTheme,
146
175
  "./white.json": require_themes.webgalWhiteTheme
147
176
  };
177
+ /**
178
+ * 初始化WebGAL Monaco编辑器环境
179
+ * 该函数会注册WebGAL语言扩展、语法高亮、主题配置等,并初始化Monaco编辑器的服务
180
+ * 使用单例模式,多次调用只会执行一次初始化
181
+ * @returns Promise<void> 初始化完成的Promise
182
+ */
148
183
  async function initWebgalMonaco() {
149
184
  if (initPromise) return initPromise;
150
185
  initPromise = (async () => {
@@ -197,9 +232,148 @@ async function initWebgalMonaco() {
197
232
  return initPromise;
198
233
  }
199
234
 
235
+ //#endregion
236
+ //#region src/monaco/workspace.ts
237
+ /**
238
+ * 规范化根URI,将输入的路径或文件URI转换为标准的URI格式
239
+ *
240
+ * @param value - 输入的路径字符串,可以是普通路径或file URI
241
+ * @returns 标准化的URI字符串
242
+ */
243
+ const normalizeRootUri = (value) => {
244
+ if (value.startsWith("file://")) return require_client_handlers.pathToUri(require_client_handlers.uriToPath(value)).toString();
245
+ return require_client_handlers.pathToUri(value).toString();
246
+ };
247
+ /**
248
+ * 创建一个Webgal Monaco工作区实例
249
+ *
250
+ * @param options - 创建工作区所需的配置选项
251
+ * @returns 返回一个包含各种操作方法的WebgalMonacoWorkspace对象
252
+ */
253
+ const createWebgalMonacoWorkspace = (options) => {
254
+ const { editor, vfs } = options;
255
+ const getLanguageFromPath = options.getLanguageFromPath ?? ((path) => path.toLowerCase().endsWith("config.txt") ? "webgal-config" : "webgal");
256
+ let rootPath = normalizeRootUri(options.rootPath ?? vfs.root);
257
+ let rootPathForJoin = require_client_handlers.normalizePath(rootPath.startsWith("file://") ? require_client_handlers.uriToPath(rootPath) : rootPath);
258
+ let activePath = null;
259
+ let skipWrite = false;
260
+ const activePathListeners = /* @__PURE__ */ new Set();
261
+ if (options.onActivePathChange) activePathListeners.add(options.onActivePathChange);
262
+ const toFileUri = (value) => {
263
+ const trimmed = value.trim();
264
+ if (!trimmed) return null;
265
+ if (trimmed.startsWith("file://")) return require_client_handlers.pathToUri(require_client_handlers.uriToPath(trimmed)).toString();
266
+ if (trimmed.startsWith("/")) return require_client_handlers.pathToUri(require_client_handlers.normalizePath(trimmed)).toString();
267
+ return require_client_handlers.pathToUri(require_client_handlers.joinPaths(rootPathForJoin, trimmed)).toString();
268
+ };
269
+ const getDisplayPath = (path) => {
270
+ const normalizedPath = require_client_handlers.normalizePath(path.startsWith("file://") ? require_client_handlers.uriToPath(path) : path);
271
+ if (normalizedPath === rootPathForJoin) return "";
272
+ if (normalizedPath.startsWith(`${rootPathForJoin}/`)) return normalizedPath.slice(rootPathForJoin.length + 1);
273
+ return normalizedPath;
274
+ };
275
+ const openFile = async (path) => {
276
+ const normalizedPath = toFileUri(path);
277
+ if (!normalizedPath) return false;
278
+ const content = await vfs.readFile(normalizedPath);
279
+ if (content === null) return false;
280
+ const uri = monaco_editor.Uri.parse(normalizedPath);
281
+ let model = monaco_editor.editor.getModel(uri);
282
+ if (!model) model = monaco_editor.editor.createModel(content, getLanguageFromPath(normalizedPath), uri);
283
+ else model.setValue(content);
284
+ skipWrite = true;
285
+ editor.setModel(model);
286
+ skipWrite = false;
287
+ activePath = normalizedPath;
288
+ activePathListeners.forEach((listener) => listener(activePath));
289
+ return true;
290
+ };
291
+ const parseFragment = (fragment) => {
292
+ const trimmed = fragment.trim();
293
+ if (!trimmed) return null;
294
+ if (trimmed.includes("=")) {
295
+ const params = new URLSearchParams(trimmed);
296
+ const lineValue = params.get("line") ?? params.get("L");
297
+ const columnValue = params.get("column") ?? params.get("col") ?? params.get("C");
298
+ const lineNumber = lineValue ? Number(lineValue) : NaN;
299
+ const column = columnValue ? Number(columnValue) : NaN;
300
+ if (!Number.isNaN(lineNumber) && lineNumber > 0) return {
301
+ lineNumber,
302
+ column: Number.isNaN(column) ? void 0 : column
303
+ };
304
+ }
305
+ const match = trimmed.match(/^L?(\d+)(?:[,.:](\d+))?$/i);
306
+ if (!match) return null;
307
+ const lineNumber = Number(match[1]);
308
+ const column = match[2] ? Number(match[2]) : void 0;
309
+ if (Number.isNaN(lineNumber) || lineNumber <= 0) return null;
310
+ return {
311
+ lineNumber,
312
+ column
313
+ };
314
+ };
315
+ const openExternalLink = (uri) => {
316
+ const scheme = uri.scheme.toLowerCase();
317
+ if (scheme !== "http" && scheme !== "https") return false;
318
+ if (typeof window === "undefined" || !window.open) return false;
319
+ window.open(uri.toString(), "_blank", "noopener,noreferrer");
320
+ return true;
321
+ };
322
+ const linkOpener = monaco_editor.editor.registerLinkOpener({ open: async (resource) => {
323
+ const scheme = resource.scheme.toLowerCase();
324
+ if (scheme === "http" || scheme === "https") return openExternalLink(resource);
325
+ if (scheme !== "file") return false;
326
+ if (!await openFile(resource.with({ fragment: "" }).toString())) return false;
327
+ const location = parseFragment(resource.fragment);
328
+ if (location) {
329
+ const position = {
330
+ lineNumber: location.lineNumber,
331
+ column: location.column ?? 1
332
+ };
333
+ editor.setPosition(position);
334
+ editor.revealPositionInCenter(position);
335
+ editor.focus();
336
+ }
337
+ return true;
338
+ } });
339
+ const changeListener = editor.onDidChangeModelContent(() => {
340
+ if (skipWrite) return;
341
+ if (!activePath) return;
342
+ vfs.writeFile(activePath, editor.getValue());
343
+ });
344
+ return {
345
+ toFileUri,
346
+ getDisplayPath,
347
+ getLanguageFromPath,
348
+ getActivePath: () => activePath,
349
+ setActivePath: (path) => {
350
+ activePath = path;
351
+ activePathListeners.forEach((listener) => listener(activePath));
352
+ },
353
+ onActivePathChange: (listener) => {
354
+ activePathListeners.add(listener);
355
+ return () => {
356
+ activePathListeners.delete(listener);
357
+ };
358
+ },
359
+ setRootPath: (nextRootPath) => {
360
+ rootPath = normalizeRootUri(nextRootPath);
361
+ rootPathForJoin = require_client_handlers.normalizePath(rootPath.startsWith("file://") ? require_client_handlers.uriToPath(rootPath) : rootPath);
362
+ },
363
+ openFile,
364
+ dispose: () => {
365
+ linkOpener.dispose();
366
+ changeListener.dispose();
367
+ activePathListeners.clear();
368
+ }
369
+ };
370
+ };
371
+
200
372
  //#endregion
201
373
  exports.createMemoryFileSystem = createMemoryFileSystem;
202
374
  exports.createWebgalMonacoLanguageClient = createWebgalMonacoLanguageClient;
203
375
  exports.createWebgalMonacoLanguageClientWithWorker = createWebgalMonacoLanguageClientWithWorker;
376
+ exports.createWebgalMonacoWorkspace = createWebgalMonacoWorkspace;
204
377
  exports.initResources = initResources;
205
- exports.initWebgalMonaco = initWebgalMonaco;
378
+ exports.initWebgalMonaco = initWebgalMonaco;
379
+ exports.normalizeRootUri = normalizeRootUri;