@mirascript/monaco 0.1.83 → 0.1.84
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/dist/basic/index.js +1 -1
- package/dist/basic/tokens-provider.d.ts.map +1 -1
- package/dist/{chunk-7ZK72GPH.js → chunk-7NT3EI6C.js} +21 -16
- package/dist/{chunk-7ZK72GPH.js.map → chunk-7NT3EI6C.js.map} +1 -1
- package/dist/lsp/compile-result.d.ts +1 -1
- package/dist/lsp/compile-result.d.ts.map +1 -1
- package/dist/lsp/index.js +148 -178
- package/dist/lsp/index.js.map +1 -1
- package/dist/lsp/providers/color-provider.d.ts.map +1 -1
- package/dist/lsp/providers/hover-provider.d.ts.map +1 -1
- package/dist/lsp/providers/inlay-hints-provider.d.ts.map +1 -1
- package/dist/lsp/utils.d.ts.map +1 -1
- package/dist/lsp/worker-core.d.ts +23 -0
- package/dist/lsp/worker-core.d.ts.map +1 -0
- package/dist/lsp/worker.d.ts +1 -22
- package/dist/lsp/worker.d.ts.map +1 -1
- package/dist/lsp/worker.js +3 -45
- package/dist/lsp/worker.js.map +1 -1
- package/dist/worker-core-MG2FDDNN.js +45 -0
- package/dist/worker-core-MG2FDDNN.js.map +6 -0
- package/package.json +7 -9
- package/src/basic/tokens-provider.ts +23 -18
- package/src/lsp/compile-result.ts +1 -1
- package/src/lsp/providers/color-provider.ts +42 -44
- package/src/lsp/providers/hover-provider.ts +27 -59
- package/src/lsp/providers/inlay-hints-provider.ts +93 -89
- package/src/lsp/utils.ts +1 -3
- package/src/lsp/worker-core.ts +68 -0
- package/src/lsp/worker-helper.ts +3 -3
- package/src/lsp/worker.ts +5 -70
package/src/lsp/worker.ts
CHANGED
|
@@ -1,73 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
import type {
|
|
3
|
-
import type { Tagged } from 'type-fest';
|
|
1
|
+
/// <reference lib="webworker" />
|
|
2
|
+
import type { Ready, Req, ResErr, ResOk } from './worker-core.js';
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
const { wasm, createConfig } = mod;
|
|
8
|
-
|
|
9
|
-
/** Monaco 编译结果 */
|
|
10
|
-
export interface MonacoResult extends BcModule.CompileResult {
|
|
11
|
-
/** 格式化结果 */
|
|
12
|
-
formatted?: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/** 缓存 Key (model id) */
|
|
16
|
-
export type CacheKey = Tagged<string, 'modelId'>;
|
|
17
|
-
/** 请求参数 */
|
|
18
|
-
export type Req = [key: CacheKey, version: number, script: string, mode: InputMode];
|
|
19
|
-
/** 编译结果 */
|
|
20
|
-
export type ResOk = [key: CacheKey, version: number, result: MonacoResult];
|
|
21
|
-
/** 编译结果 */
|
|
22
|
-
export type ResErr = [key: CacheKey, version: number, error: Error];
|
|
23
|
-
/** 编译结果 */
|
|
24
|
-
export type Res = ResOk | ResErr;
|
|
25
|
-
/** Ready */
|
|
26
|
-
export type Ready = 'mirascript lsp ready';
|
|
27
|
-
|
|
28
|
-
const configTemplate = createConfig({
|
|
29
|
-
diagnostic_position_encoding: 'Utf16',
|
|
30
|
-
diagnostic_tag: true,
|
|
31
|
-
diagnostic_sourcemap: true,
|
|
32
|
-
trivia: true,
|
|
33
|
-
input_mode: 'Template',
|
|
34
|
-
});
|
|
35
|
-
const configScript = createConfig({
|
|
36
|
-
diagnostic_position_encoding: 'Utf16',
|
|
37
|
-
diagnostic_tag: true,
|
|
38
|
-
diagnostic_sourcemap: true,
|
|
39
|
-
trivia: true,
|
|
40
|
-
input_mode: 'Script',
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
/** 编译 */
|
|
44
|
-
export function compile(script: string, mode: InputMode): MonacoResult {
|
|
45
|
-
const config = mode === 'Script' ? configScript : configTemplate;
|
|
46
|
-
const compiler = new wasm.MonacoCompiler(script, config);
|
|
47
|
-
try {
|
|
48
|
-
const parseOk = compiler.parse();
|
|
49
|
-
if (!parseOk) {
|
|
50
|
-
return { diagnostics: compiler.diagnostics(), chunk: undefined };
|
|
51
|
-
}
|
|
52
|
-
const chunk = compiler.emit();
|
|
53
|
-
const formatted = compiler.format();
|
|
54
|
-
return {
|
|
55
|
-
diagnostics: compiler.diagnostics(),
|
|
56
|
-
chunk,
|
|
57
|
-
formatted,
|
|
58
|
-
};
|
|
59
|
-
} finally {
|
|
60
|
-
try {
|
|
61
|
-
compiler.free();
|
|
62
|
-
} catch (ex) {
|
|
63
|
-
/* 忽略错误 */
|
|
64
|
-
// eslint-disable-next-line no-console
|
|
65
|
-
console.error(ex);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (typeof Worker == 'function' && typeof addEventListener == 'function' && typeof postMessage == 'function') {
|
|
4
|
+
void Promise.resolve().then(async () => {
|
|
5
|
+
const { compile } = await import('./worker-core.js');
|
|
71
6
|
addEventListener('message', (event: MessageEvent) => {
|
|
72
7
|
const data = event.data as Req;
|
|
73
8
|
if (!Array.isArray(data)) return;
|
|
@@ -84,4 +19,4 @@ if (typeof Worker == 'function' && typeof addEventListener == 'function' && type
|
|
|
84
19
|
}
|
|
85
20
|
});
|
|
86
21
|
postMessage('mirascript lsp ready' satisfies Ready);
|
|
87
|
-
}
|
|
22
|
+
});
|