@mirascript/monaco 0.1.9 → 0.1.10
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/language-configuration.d.ts.map +1 -1
- package/dist/basic/tokens-provider.d.ts.map +1 -1
- package/dist/{chunk-OTLGDSYY.js → chunk-KA3F2DFK.js} +105 -71
- package/dist/chunk-KA3F2DFK.js.map +6 -0
- package/dist/constants.d.ts +0 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/contribute.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/lsp/index.js +114 -91
- package/dist/lsp/index.js.map +2 -2
- package/dist/lsp/providers/base.d.ts +11 -2
- package/dist/lsp/providers/base.d.ts.map +1 -1
- package/dist/lsp/providers/completion-item-provider.d.ts.map +1 -1
- package/dist/lsp/providers/definition-reference-provider.d.ts.map +1 -1
- package/dist/lsp/providers/hover-provider.d.ts.map +1 -1
- package/dist/lsp/utils.d.ts +4 -4
- package/dist/lsp/utils.d.ts.map +1 -1
- package/package.json +3 -4
- package/src/basic/language-configuration.ts +2 -1
- package/src/basic/tokens-provider.ts +100 -64
- package/src/constants.ts +0 -3
- package/src/contribute.ts +7 -0
- package/src/lsp/providers/base.ts +23 -3
- package/src/lsp/providers/completion-item-provider.ts +7 -5
- package/src/lsp/providers/definition-reference-provider.ts +58 -52
- package/src/lsp/providers/hover-provider.ts +7 -19
- package/src/lsp/providers/semantic-tokens-provider.ts +3 -3
- package/src/lsp/utils.ts +39 -17
- package/dist/chunk-OTLGDSYY.js.map +0 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definition-reference-provider.d.ts","sourceRoot":"","sources":["../../../src/lsp/providers/definition-reference-provider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"definition-reference-provider.d.ts","sourceRoot":"","sources":["../../../src/lsp/providers/definition-reference-provider.ts"],"names":[],"mappings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AClB,KAAK,EAAE,iBAAiB,EACxB,OAAO,CAAC,EAAE,SAAS,CAAC,YAAY,CAAC,SAAS,CAAC,KAAK,CAAC,GAClD,OAAO,CAAC,SAAS,CAAC,KAAK,GAAG,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"hover-provider.d.ts","sourceRoot":"","sources":["../../../src/lsp/providers/hover-provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,EAA2B,SAAS,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACnH,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAKrC,kBAAkB;AAClB,qBAAa,aAAc,SAAQ,QAAS,YAAW,SAAS,CAAC,aAAa;IAC1E,WAAW;YACG,oBAAoB;IAiGlC,WAAW;YACG,iBAAiB;IAmB/B,kBAAkB;IACZ,YAAY,CACd,KAAK,EAAE,MAAM,CAAC,UAAU,EACxB,QAAQ,EAAE,QAAQ,EAClB,KAAK,EAAE,iBAAiB,EACxB,OAAO,CAAC,EAAE,SAAS,CAAC,YAAY,CAAC,SAAS,CAAC,KAAK,CAAC,GAClD,OAAO,CAAC,SAAS,CAAC,KAAK,GAAG,SAAS,CAAC;CAS1C"}
|
package/dist/lsp/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type editor, Range, type IPosition, type IRange } from '../monaco-api.js';
|
|
2
|
-
import { type VmAny, type VmFunctionInfo
|
|
2
|
+
import { type VmAny, type VmFunctionInfo } from '@mirascript/mirascript';
|
|
3
3
|
import type { LocalDefinition } from './compile-result.js';
|
|
4
4
|
/** 参数签名 */
|
|
5
5
|
export type ParamSignature = [name: string, sig: string, doc: string];
|
|
@@ -25,13 +25,13 @@ export declare function wordAt(model: editor.ITextModel, position: IPosition): {
|
|
|
25
25
|
word: string;
|
|
26
26
|
range: Range;
|
|
27
27
|
} | undefined;
|
|
28
|
-
/**
|
|
29
|
-
export declare function
|
|
28
|
+
/** 生成 doc comment */
|
|
29
|
+
export declare function docComment(doc: string[]): string[];
|
|
30
30
|
/** 获取变量文档 */
|
|
31
31
|
export declare function valueDoc(name: string, value: VmAny, type: 'field' | 'declare' | 'hint'): {
|
|
32
32
|
script: string;
|
|
33
33
|
doc: string[];
|
|
34
34
|
};
|
|
35
35
|
/** 获取深层属性 */
|
|
36
|
-
export declare function getDeep(value: VmAny, path: readonly string[]):
|
|
36
|
+
export declare function getDeep(value: VmAny, path: readonly string[]): VmAny;
|
|
37
37
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/lsp/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/lsp/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,EAAE,KAAK,SAAS,EAAE,KAAK,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACnF,OAAO,EASH,KAAK,KAAK,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/lsp/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,EAAE,KAAK,SAAS,EAAE,KAAK,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACnF,OAAO,EASH,KAAK,KAAK,EAEV,KAAK,cAAc,EAGtB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAE3D,WAAW;AACX,MAAM,MAAM,cAAc,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;AAmBtE,aAAa;AACb,wBAAgB,WAAW,CACvB,EAAE,EAAE,MAAM,GAAG,SAAS,EACtB,IAAI,EAAE,cAAc,GACrB;IACC,MAAM,EAAE,cAAc,EAAE,CAAC;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,kBAAk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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mirascript/monaco",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.10",
|
|
4
4
|
"author": "CloudPSS",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Monaco Editor integration for Mirascript.",
|
|
@@ -28,9 +28,8 @@
|
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"
|
|
32
|
-
"@mirascript/
|
|
33
|
-
"@mirascript/mirascript": "~0.1.9"
|
|
31
|
+
"@mirascript/wasm": "~0.1.10",
|
|
32
|
+
"@mirascript/mirascript": "~0.1.10"
|
|
34
33
|
},
|
|
35
34
|
"peerDependencies": {
|
|
36
35
|
"monaco-editor": ">= 0.0.40 < 0.55.0"
|
|
@@ -14,7 +14,7 @@ function indentAction(action: keyof typeof languages.IndentAction): { indentActi
|
|
|
14
14
|
|
|
15
15
|
export const configuration = (): languages.LanguageConfiguration => ({
|
|
16
16
|
comments: {
|
|
17
|
-
lineComment: '//',
|
|
17
|
+
lineComment: { comment: '//' },
|
|
18
18
|
blockComment: ['/*', '*/'],
|
|
19
19
|
},
|
|
20
20
|
brackets: [
|
|
@@ -86,5 +86,6 @@ export function setLanguageConfiguration(): IDisposable[] {
|
|
|
86
86
|
return [
|
|
87
87
|
languages.setLanguageConfiguration('mirascript', configuration()),
|
|
88
88
|
languages.setLanguageConfiguration('mirascript-template', configuration()),
|
|
89
|
+
languages.setLanguageConfiguration('mirascript-doc', configuration()),
|
|
89
90
|
];
|
|
90
91
|
}
|
|
@@ -7,7 +7,6 @@ import {
|
|
|
7
7
|
REG_HEX,
|
|
8
8
|
REG_NUMBER,
|
|
9
9
|
REG_IDENTIFIER,
|
|
10
|
-
DOC_HEADER,
|
|
11
10
|
MAX_VERBATIM_LENGTH,
|
|
12
11
|
constantKeywords,
|
|
13
12
|
controlKeywords,
|
|
@@ -27,7 +26,7 @@ function identifierCases(
|
|
|
27
26
|
return {
|
|
28
27
|
'@numericKeywords': { ...data, token: `constant.numeric` },
|
|
29
28
|
'@constantKeywords': { ...data, token: `constant.language` },
|
|
30
|
-
'@controlKeywords': { ...data, token: `keyword.
|
|
29
|
+
'@controlKeywords': { ...data, token: `keyword.flow` },
|
|
31
30
|
'@keywords': { ...data, token: `keyword` },
|
|
32
31
|
'[@]+.*': { ...data, token: `variable.other.constant` },
|
|
33
32
|
'~it': { ...data, token: `variable.other.constant.emphasis` },
|
|
@@ -50,7 +49,6 @@ function getTokensProvider(mode: string): languages.IMonarchLanguage {
|
|
|
50
49
|
|
|
51
50
|
whitespace: REG_WHITESPACE,
|
|
52
51
|
identifier: REG_IDENTIFIER,
|
|
53
|
-
docHeader: DOC_HEADER,
|
|
54
52
|
|
|
55
53
|
keywords: keywords(),
|
|
56
54
|
controlKeywords: controlKeywords(),
|
|
@@ -58,34 +56,30 @@ function getTokensProvider(mode: string): languages.IMonarchLanguage {
|
|
|
58
56
|
numericKeywords: numericKeywords(),
|
|
59
57
|
|
|
60
58
|
inlineDocParam: /\(parameter(?: pattern)?\)/,
|
|
59
|
+
inlineDocMod: ['local', 'global', 'field', 'module'].join('|'),
|
|
61
60
|
|
|
62
|
-
start: mode === 'template' ? 'root_template' : 'root',
|
|
61
|
+
start: mode === 'template' ? 'root_template' : mode === 'doc' ? 'root_doc' : 'root',
|
|
63
62
|
tokenPostfix: '.mirascript',
|
|
64
63
|
tokenizer: {
|
|
65
|
-
root: [
|
|
66
|
-
[/^(?=\0)/, '', '@doc_mode'],
|
|
67
|
-
[/^\/\*\*@docHeader\*\*\/$/, 'comment.doc', '@doc_mode'],
|
|
68
|
-
[/[[\](){}]/, '@brackets'],
|
|
69
|
-
{ include: '@common' },
|
|
70
|
-
],
|
|
64
|
+
root: [[/[[\](){}]/, '@brackets'], { include: '@common' }],
|
|
71
65
|
root_template: [
|
|
72
66
|
[/[^$]+/, 'string'],
|
|
73
67
|
[/(?=\$)/, '', '@string_interpolation.$S3'],
|
|
74
68
|
[/[$]/, 'string'],
|
|
75
69
|
],
|
|
76
70
|
common: [
|
|
77
|
-
[/(@identifier)(@whitespace*)(\??:)(?!:)/, ['
|
|
71
|
+
[/(@identifier)(@whitespace*)(\??:)(?!:)/, ['variable.other.property', '', 'delimiter']],
|
|
78
72
|
[
|
|
79
73
|
/(fn)(@whitespace+)(@identifier)(?=$|@whitespace|[[({,;])/,
|
|
80
74
|
['keyword', '', { cases: identifierCases(undefined, 'entity.name.function') }],
|
|
81
75
|
],
|
|
82
76
|
[
|
|
83
77
|
/(for)(@whitespace+)(mut)(@whitespace+)(@identifier)(@whitespace+)(in)/,
|
|
84
|
-
['keyword.
|
|
78
|
+
['keyword.flow', '', 'keyword', '', { cases: identifierCases() }, '', 'keyword.flow'],
|
|
85
79
|
],
|
|
86
80
|
[
|
|
87
81
|
/(for)(@whitespace+)(@identifier)(@whitespace+)(in)/,
|
|
88
|
-
['keyword.
|
|
82
|
+
['keyword.flow', '', { cases: identifierCases() }, '', 'keyword.flow'],
|
|
89
83
|
],
|
|
90
84
|
[
|
|
91
85
|
/(\.)(@whitespace*)(\d+)/,
|
|
@@ -100,7 +94,7 @@ function getTokensProvider(mode: string): languages.IMonarchLanguage {
|
|
|
100
94
|
},
|
|
101
95
|
],
|
|
102
96
|
],
|
|
103
|
-
[String.raw`\b(${moduleNames.join('|')})(@whitespace*(?=!?\.))`, ['
|
|
97
|
+
[String.raw`\b(${moduleNames.join('|')})(@whitespace*(?=!?\.))`, ['type', '']],
|
|
104
98
|
[
|
|
105
99
|
/(\.)(@whitespace*)(@identifier)(@whitespace*)(!?)(@whitespace*(?=\())/,
|
|
106
100
|
['delimiter', '', 'entity.name.function', '', 'delimiter', ''],
|
|
@@ -259,28 +253,68 @@ function getTokensProvider(mode: string): languages.IMonarchLanguage {
|
|
|
259
253
|
[/[*@\\]/, { token: 'comment.doc' }],
|
|
260
254
|
],
|
|
261
255
|
|
|
262
|
-
|
|
256
|
+
root_doc: [
|
|
263
257
|
// inline doc, start with `\0`
|
|
258
|
+
[/^\0/, { token: '', switchTo: '@inline_doc' }],
|
|
259
|
+
[/(?=.)/, { token: '', switchTo: '@doc_mode' }],
|
|
260
|
+
],
|
|
261
|
+
|
|
262
|
+
inline_doc: [
|
|
264
263
|
[
|
|
265
|
-
|
|
264
|
+
/(@inlineDocParam)(@whitespace+)(\.\.|)(mut)(@whitespace+)(@identifier)/,
|
|
266
265
|
['entity.name.label', '', 'delimiter', 'keyword.mut', '', 'variable.emphasis'],
|
|
267
266
|
],
|
|
268
267
|
[
|
|
269
|
-
|
|
268
|
+
/(@inlineDocParam)(@whitespace+)(\.\.|)(@identifier)/,
|
|
270
269
|
['entity.name.label', '', 'delimiter', 'variable.other.constant.emphasis'],
|
|
271
270
|
],
|
|
272
|
-
[
|
|
271
|
+
[/(@whitespace*)(\(module\))(\s*)(@identifier)/, ['', 'entity.name.label', '', 'type']],
|
|
272
|
+
[/(\(@inlineDocMod\))(@whitespace+)/, ['entity.name.label', '']],
|
|
273
|
+
{ include: '@doc_mode' },
|
|
274
|
+
],
|
|
273
275
|
|
|
276
|
+
doc_mode: [
|
|
274
277
|
[
|
|
275
|
-
/(@identifier)(@whitespace*)(:)(@whitespace*)(\/\*@whitespace*<)(extern )([
|
|
278
|
+
/(@identifier)(@whitespace*)(:)(@whitespace*)(\/\*@whitespace*<)(extern )((?:async )?function\*?)(@whitespace*)([<>.\w]*)(\(\))(>@whitespace*\*\/)/,
|
|
276
279
|
[
|
|
277
280
|
'entity.name.function.doc',
|
|
278
281
|
'',
|
|
279
282
|
'delimiter',
|
|
280
283
|
'',
|
|
281
284
|
'comment.doc',
|
|
282
|
-
'type',
|
|
283
|
-
'
|
|
285
|
+
'type.doc',
|
|
286
|
+
'keyword.javascript',
|
|
287
|
+
'',
|
|
288
|
+
'entity.name.function.javascript',
|
|
289
|
+
'delimiter',
|
|
290
|
+
'comment.doc',
|
|
291
|
+
],
|
|
292
|
+
],
|
|
293
|
+
[
|
|
294
|
+
/(@identifier)(@whitespace*)(:)(@whitespace*)(\/\*@whitespace*<)(extern )(class)(@whitespace*)([<>.\w]*)(>@whitespace*\*\/)/,
|
|
295
|
+
[
|
|
296
|
+
'type.doc',
|
|
297
|
+
'',
|
|
298
|
+
'delimiter',
|
|
299
|
+
'',
|
|
300
|
+
'comment.doc',
|
|
301
|
+
'type.doc',
|
|
302
|
+
'keyword.javascript',
|
|
303
|
+
'',
|
|
304
|
+
'type.javascript',
|
|
305
|
+
'comment.doc',
|
|
306
|
+
],
|
|
307
|
+
],
|
|
308
|
+
[
|
|
309
|
+
/(@identifier)(@whitespace*)(:)(@whitespace*)(\/\*@whitespace*<)(extern )([\w]*)(>@whitespace*\*\/)/,
|
|
310
|
+
[
|
|
311
|
+
'variable.other.property.doc',
|
|
312
|
+
'',
|
|
313
|
+
'delimiter',
|
|
314
|
+
'',
|
|
315
|
+
'comment.doc',
|
|
316
|
+
'type.doc',
|
|
317
|
+
'type.javascript',
|
|
284
318
|
'comment.doc',
|
|
285
319
|
],
|
|
286
320
|
],
|
|
@@ -292,72 +326,73 @@ function getTokensProvider(mode: string): languages.IMonarchLanguage {
|
|
|
292
326
|
'delimiter',
|
|
293
327
|
'',
|
|
294
328
|
'comment.doc',
|
|
295
|
-
'type',
|
|
329
|
+
'type.doc',
|
|
296
330
|
'entity.name.label',
|
|
297
331
|
'comment.doc',
|
|
298
332
|
],
|
|
299
333
|
],
|
|
300
|
-
[/(@identifier)(@whitespace*)(:)(@whitespace+)/, ['
|
|
334
|
+
[/(@identifier)(@whitespace*)(:)(@whitespace+)/, ['variable.other.property', '', 'delimiter', '']],
|
|
335
|
+
|
|
336
|
+
[
|
|
337
|
+
/(\/\*@whitespace*<)(extern )((?:async )?function\*?)(@whitespace*)([<>.\w]*)(\(\))(>@whitespace*\*\/)/,
|
|
338
|
+
[
|
|
339
|
+
'comment.doc',
|
|
340
|
+
'type.doc',
|
|
341
|
+
'keyword.javascript',
|
|
342
|
+
'',
|
|
343
|
+
'entity.name.function.javascript',
|
|
344
|
+
'delimiter',
|
|
345
|
+
'comment.doc',
|
|
346
|
+
],
|
|
347
|
+
],
|
|
348
|
+
[
|
|
349
|
+
/(\/\*@whitespace*<)(extern )(class)(@whitespace*)([<>.\w]*)(>@whitespace*\*\/)/,
|
|
350
|
+
['comment.doc', 'type.doc', 'keyword.javascript', '', 'type.javascript', 'comment.doc'],
|
|
351
|
+
],
|
|
352
|
+
[
|
|
353
|
+
/(\/\*@whitespace*<)(extern )([\w]*)(>@whitespace*\*\/)/,
|
|
354
|
+
['comment.doc', 'type.doc', 'type.javascript', 'comment.doc'],
|
|
355
|
+
],
|
|
356
|
+
[
|
|
357
|
+
/(\/\*@whitespace*<)(function )([.\w]*)(>@whitespace*\*\/)/,
|
|
358
|
+
['comment.doc', 'type.doc', 'entity.name.label', 'comment.doc'],
|
|
359
|
+
],
|
|
301
360
|
[
|
|
302
361
|
/(\/\*@whitespace*<)(\w+@whitespace*)([.\w]*)(>@whitespace*\*\/)/,
|
|
303
|
-
['comment.doc', 'type', 'entity.name.label', 'comment.doc'],
|
|
362
|
+
['comment.doc', 'type.doc', 'entity.name.label', 'comment.doc'],
|
|
304
363
|
],
|
|
305
|
-
[/(\s*)(\(module\))(\s*)(@identifier)/, ['', 'entity.name.label', '', 'entity.name.namespace']],
|
|
306
364
|
|
|
365
|
+
[/(let|const)(@whitespace+)(@identifier)/, [{ token: 'keyword.$1' }, '', 'variable.other.constant']],
|
|
307
366
|
[/(fn)(@whitespace+)(@identifier)$/, ['keyword.fn.doc', '', 'entity.name.function.doc']],
|
|
308
367
|
[
|
|
309
|
-
/(fn)(@whitespace+)(@identifier)(\()(\.\.)(\))
|
|
368
|
+
/(fn)(@whitespace+)(@identifier)(\()(\.\.)(\))/,
|
|
310
369
|
['keyword.fn.doc', '', 'entity.name.function.doc', '@brackets', 'delimiter', '@brackets'],
|
|
311
370
|
],
|
|
312
|
-
[/fn/, 'keyword.fn.doc', '@type_doc_fn'],
|
|
313
371
|
[
|
|
314
|
-
/(
|
|
315
|
-
[
|
|
372
|
+
/(fn)(@whitespace+)(@identifier)/,
|
|
373
|
+
['keyword.fn.doc', '', { token: 'entity.name.function.doc', next: '@type_doc' }],
|
|
316
374
|
],
|
|
317
375
|
[
|
|
318
|
-
/(let
|
|
319
|
-
[{ token: 'keyword.$1' }, '',
|
|
376
|
+
/(let)(@whitespace+)(mut)(@whitespace+)(@identifier)/,
|
|
377
|
+
[{ token: 'keyword.$1' }, '', 'keyword.mut', '', 'variable'],
|
|
320
378
|
],
|
|
321
|
-
{ include: '@common' },
|
|
322
379
|
[/[[\](){}]/, '@brackets'],
|
|
380
|
+
{ include: '@common' },
|
|
323
381
|
],
|
|
324
382
|
type_doc: [
|
|
325
|
-
{ include: '@type_doc_common' },
|
|
326
|
-
[/[,)]/, 'delimiter', '@pop'],
|
|
327
383
|
[/;/, { token: 'delimiter', next: '@pop', goBack: 1 }],
|
|
328
|
-
|
|
329
|
-
type_doc_inner: [{ include: '@type_doc_common' }, [/[,;]/, 'delimiter']],
|
|
330
|
-
type_doc_common: [
|
|
331
|
-
[/fn\b/, 'type', '@type_doc_fn'],
|
|
384
|
+
[/(fn)(\()/, ['type', '@brackets']],
|
|
332
385
|
[/(type)(\()(@identifier)(\))/, ['type', '@brackets', 'variable.emphasis.doc', '@brackets']],
|
|
333
|
-
[/@identifier/, 'type'],
|
|
334
|
-
[/[[(]/, '@brackets', '@type_doc_inner'],
|
|
335
|
-
[/[\])]/, '@brackets', '@pop'],
|
|
336
|
-
[/[&|.]/, 'delimiter'],
|
|
337
|
-
[/->/, 'delimiter'],
|
|
338
|
-
[/@whitespace+/, ''],
|
|
339
|
-
],
|
|
340
|
-
type_doc_fn: [
|
|
341
|
-
[/(@identifier)(\()/, ['entity.name.function.doc', '@brackets']],
|
|
342
|
-
[/@whitespace+/, ''],
|
|
343
|
-
[/(->)/, { token: 'delimiter', switchTo: '@type_doc' }],
|
|
344
386
|
[
|
|
345
|
-
/(
|
|
346
|
-
[
|
|
347
|
-
'delimiter',
|
|
348
|
-
'variable.emphasis.doc',
|
|
349
|
-
'',
|
|
350
|
-
{
|
|
351
|
-
cases: {
|
|
352
|
-
':': { token: 'delimiter', next: '@type_doc' },
|
|
353
|
-
'\\)': '@brackets',
|
|
354
|
-
'@default': 'delimiter',
|
|
355
|
-
},
|
|
356
|
-
},
|
|
357
|
-
],
|
|
387
|
+
/(@identifier)(:)(@whitespace*)(fn)(\()/,
|
|
388
|
+
['entity.name.function.emphasis.doc', 'delimiter', '', 'type', '@brackets'],
|
|
358
389
|
],
|
|
359
|
-
[/
|
|
360
|
-
[
|
|
390
|
+
[/(@identifier)(:)/, ['variable.emphasis', 'delimiter']],
|
|
391
|
+
[/@identifier/, 'type'],
|
|
392
|
+
[/[&|.,]/, 'delimiter'],
|
|
393
|
+
[/->/, 'delimiter'],
|
|
394
|
+
[/[[\]()]/, '@brackets'],
|
|
395
|
+
{ include: '@whitespace' },
|
|
361
396
|
],
|
|
362
397
|
},
|
|
363
398
|
};
|
|
@@ -368,5 +403,6 @@ export function registerMiraScriptTokensProvider(): IDisposable[] {
|
|
|
368
403
|
return [
|
|
369
404
|
languages.setMonarchTokensProvider('mirascript', getTokensProvider('script')),
|
|
370
405
|
languages.setMonarchTokensProvider('mirascript-template', getTokensProvider('template')),
|
|
406
|
+
languages.setMonarchTokensProvider('mirascript-doc', getTokensProvider('doc')),
|
|
371
407
|
];
|
|
372
408
|
}
|
package/src/constants.ts
CHANGED
|
@@ -49,8 +49,5 @@ export const REG_OCT = /0[oO][0-7_]*[0-7]/;
|
|
|
49
49
|
export const REG_BIN = /0[bB][01_]*[01]/;
|
|
50
50
|
export const REG_NUMBER = /\d[\d_]*(?:\.[\d_]+)?(?:[eE][+-]?[\d_]*\d)?/u;
|
|
51
51
|
|
|
52
|
-
// Special characters
|
|
53
|
-
export const DOC_HEADER = ' 𝙼𝚒𝚛𝚊𝚂𝚌𝚛𝚒𝚙𝚝 𝙶𝚕𝚘𝚋𝚊𝚕 𝙳𝚎𝚏𝚒𝚗𝚒𝚝𝚒𝚘𝚗𝚜 ';
|
|
54
|
-
|
|
55
52
|
/** 基础语言服务支持的最大插值字符串 `$` 数量 */
|
|
56
53
|
export const MAX_VERBATIM_LENGTH = 16;
|
package/src/contribute.ts
CHANGED
|
@@ -15,4 +15,11 @@ export function registerContribution(): void {
|
|
|
15
15
|
aliases: ['MiraScriptTemplate', 'mirascript-template', 'miratpl'],
|
|
16
16
|
mimetypes: ['text/x-mirascript-template'],
|
|
17
17
|
});
|
|
18
|
+
|
|
19
|
+
languages.register({
|
|
20
|
+
id: 'mirascript-doc',
|
|
21
|
+
extensions: [],
|
|
22
|
+
aliases: [],
|
|
23
|
+
mimetypes: ['text/x-mirascript-doc'],
|
|
24
|
+
});
|
|
18
25
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { VmContext } from '@mirascript/mirascript';
|
|
2
|
-
import { DefaultVmContext } from '@mirascript/mirascript/subtle';
|
|
2
|
+
import { DefaultVmContext, type IRange } from '@mirascript/mirascript/subtle';
|
|
3
3
|
import type { VmContextProvider } from '../../index.js';
|
|
4
|
-
import { type editor, Emitter, type IEvent } from '../../monaco-api.js';
|
|
5
|
-
import type { CompileResult } from '../compile-result.js';
|
|
4
|
+
import { type editor, Emitter, type IEvent, type IPosition } from '../../monaco-api.js';
|
|
5
|
+
import type { CompileResult, FieldsAccessAt, VariableAccessAt } from '../compile-result.js';
|
|
6
6
|
import { compile } from '../worker-helper.js';
|
|
7
|
+
import { wordAt } from '../utils.js';
|
|
7
8
|
|
|
8
9
|
let contextProvider: VmContextProvider | undefined;
|
|
9
10
|
/** 设置全局变量提供者 */
|
|
@@ -24,6 +25,25 @@ export abstract class Provider {
|
|
|
24
25
|
async getContext(model: editor.ITextModel): Promise<Readonly<VmContext>> {
|
|
25
26
|
return (await contextProvider?.(model)) ?? DefaultVmContext;
|
|
26
27
|
}
|
|
28
|
+
/** 获取当前位置的值 */
|
|
29
|
+
async getValueAt(
|
|
30
|
+
model: editor.ITextModel,
|
|
31
|
+
position: IPosition,
|
|
32
|
+
): Promise<({ range: IRange } & ({ variable: VariableAccessAt } | { fields: FieldsAccessAt })) | undefined> {
|
|
33
|
+
const compiled = await this.getCompileResult(model);
|
|
34
|
+
if (!compiled) return undefined;
|
|
35
|
+
const d = compiled.variableAccessAt(model, position);
|
|
36
|
+
if (d) return { range: d.range, variable: d };
|
|
37
|
+
const word = wordAt(model, position);
|
|
38
|
+
if (word) {
|
|
39
|
+
const a = compiled.fieldAccessAt(model, {
|
|
40
|
+
lineNumber: position.lineNumber,
|
|
41
|
+
column: word.range.endColumn,
|
|
42
|
+
});
|
|
43
|
+
if (a) return { range: word.range, fields: a };
|
|
44
|
+
}
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
27
47
|
|
|
28
48
|
readonly displayName = 'MiraScript LSP';
|
|
29
49
|
readonly _debugDisplayName = 'MiraScript LSP';
|
|
@@ -192,7 +192,9 @@ interface CustomCompletionItem extends languages.CompletionItem {
|
|
|
192
192
|
/** 构造 filterText */
|
|
193
193
|
function filterText(key: string, char: string | undefined): string {
|
|
194
194
|
if (char == null || key.startsWith(char)) return key;
|
|
195
|
-
|
|
195
|
+
if (key.startsWith('@')) return key.replace(/^@+/, '');
|
|
196
|
+
if (key.startsWith('$')) return key.replace(/^\$+/, '');
|
|
197
|
+
return key;
|
|
196
198
|
}
|
|
197
199
|
|
|
198
200
|
/** 构造选项 */
|
|
@@ -316,11 +318,11 @@ export class CompletionItemProvider extends Provider implements languages.Comple
|
|
|
316
318
|
const locals = new Set<string>();
|
|
317
319
|
while (scope) {
|
|
318
320
|
for (const { definition, fn } of scope.locals) {
|
|
319
|
-
const name =
|
|
321
|
+
const name =
|
|
322
|
+
definition.code === DiagnosticCode.ParameterIt ? 'it' : model.getValueInRange(definition.range);
|
|
323
|
+
if (char && !name.toLowerCase().includes(char)) continue;
|
|
320
324
|
if (locals.has(name)) continue; // 子作用域可能会覆盖父作用域的变量
|
|
321
|
-
|
|
322
|
-
continue;
|
|
323
|
-
}
|
|
325
|
+
|
|
324
326
|
locals.add(name);
|
|
325
327
|
suggestions.push({
|
|
326
328
|
insertText: name,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { VmAny } from '@mirascript/mirascript';
|
|
2
1
|
import {
|
|
3
2
|
editor,
|
|
4
3
|
Uri,
|
|
@@ -9,8 +8,7 @@ import {
|
|
|
9
8
|
Range,
|
|
10
9
|
} from '../../monaco-api.js';
|
|
11
10
|
import { Provider } from './base.js';
|
|
12
|
-
import { valueDoc } from '../utils.js';
|
|
13
|
-
import { DOC_HEADER } from '../../constants.js';
|
|
11
|
+
import { docComment, getDeep, valueDoc } from '../utils.js';
|
|
14
12
|
|
|
15
13
|
/**
|
|
16
14
|
* 转到定义/引用
|
|
@@ -20,23 +18,27 @@ export class DefinitionReferenceProvider
|
|
|
20
18
|
implements languages.DefinitionProvider, languages.ReferenceProvider
|
|
21
19
|
{
|
|
22
20
|
constructor(
|
|
23
|
-
private readonly globalModel = editor.createModel(
|
|
21
|
+
private readonly globalModel = editor.createModel(
|
|
22
|
+
``,
|
|
23
|
+
'mirascript-doc',
|
|
24
|
+
Uri.parse('mirascript:///lib/global.mira'),
|
|
25
|
+
),
|
|
24
26
|
) {
|
|
25
27
|
super();
|
|
26
28
|
}
|
|
27
29
|
/** 准备要显示的定义 */
|
|
28
|
-
private prepareGlobal(
|
|
30
|
+
private async prepareGlobal(
|
|
31
|
+
model: editor.ITextModel,
|
|
32
|
+
path: readonly string[],
|
|
33
|
+
): Promise<{ uri: Uri; range: IRange } | undefined> {
|
|
29
34
|
const { globalModel } = this;
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
script,
|
|
38
|
-
'',
|
|
39
|
-
];
|
|
35
|
+
const globals = await this.getContext(model);
|
|
36
|
+
const [name, ...access] = path;
|
|
37
|
+
if (!globals.has(name!)) return undefined;
|
|
38
|
+
const value = getDeep(globals.get(name!), access);
|
|
39
|
+
if (value === undefined) return undefined;
|
|
40
|
+
const { script, doc } = valueDoc(path.at(-1)!, value, 'declare');
|
|
41
|
+
const code = ['', ...docComment(doc), script, ''];
|
|
40
42
|
globalModel.setValue(code.join('\n'));
|
|
41
43
|
return {
|
|
42
44
|
uri: globalModel.uri,
|
|
@@ -54,26 +56,32 @@ export class DefinitionReferenceProvider
|
|
|
54
56
|
position: Position,
|
|
55
57
|
token: CancellationToken,
|
|
56
58
|
): Promise<languages.LocationLink[] | undefined> {
|
|
57
|
-
const
|
|
58
|
-
if (!
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
if ('name' in def) {
|
|
71
|
-
link = this.prepareGlobal(def.name, globals.get(def.name));
|
|
59
|
+
const value = await this.getValueAt(model, position);
|
|
60
|
+
if (!value) return undefined;
|
|
61
|
+
if ('variable' in value) {
|
|
62
|
+
const { def } = value.variable;
|
|
63
|
+
let link: languages.LocationLink | undefined;
|
|
64
|
+
if ('name' in def) {
|
|
65
|
+
link = await this.prepareGlobal(model, [def.name]);
|
|
66
|
+
} else {
|
|
67
|
+
link = { uri: model.uri, range: def.definition.range };
|
|
68
|
+
}
|
|
69
|
+
if (!link) return undefined;
|
|
70
|
+
link.originSelectionRange = value.range;
|
|
71
|
+
return [link];
|
|
72
72
|
} else {
|
|
73
|
-
|
|
73
|
+
const {
|
|
74
|
+
def: { def },
|
|
75
|
+
fields,
|
|
76
|
+
} = value.fields;
|
|
77
|
+
if ('name' in def) {
|
|
78
|
+
const link: languages.LocationLink | undefined = await this.prepareGlobal(model, [def.name, ...fields]);
|
|
79
|
+
if (!link) return undefined;
|
|
80
|
+
link.originSelectionRange = value.range;
|
|
81
|
+
return [link];
|
|
82
|
+
}
|
|
74
83
|
}
|
|
75
|
-
|
|
76
|
-
return [link];
|
|
84
|
+
return undefined;
|
|
77
85
|
}
|
|
78
86
|
/** @inheritdoc */
|
|
79
87
|
async provideReferences(
|
|
@@ -82,26 +90,24 @@ export class DefinitionReferenceProvider
|
|
|
82
90
|
context: languages.ReferenceContext,
|
|
83
91
|
token: CancellationToken,
|
|
84
92
|
): Promise<languages.Location[] | undefined> {
|
|
85
|
-
const
|
|
86
|
-
if (!
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
uri: model.uri,
|
|
101
|
-
range: def.definition.range,
|
|
102
|
-
});
|
|
93
|
+
const value = await this.getValueAt(model, position);
|
|
94
|
+
if (!value) return undefined;
|
|
95
|
+
if ('variable' in value) {
|
|
96
|
+
const { def } = value.variable;
|
|
97
|
+
const links: languages.Location[] = def.references.map((u) => ({
|
|
98
|
+
uri: model.uri,
|
|
99
|
+
range: u.range,
|
|
100
|
+
}));
|
|
101
|
+
if (context.includeDeclaration) {
|
|
102
|
+
if ('name' in def) {
|
|
103
|
+
const link = await this.prepareGlobal(model, [def.name]);
|
|
104
|
+
if (link) links.push(link);
|
|
105
|
+
} else if (!Range.isEmpty(def.definition.range)) {
|
|
106
|
+
links.push({ uri: model.uri, range: def.definition.range });
|
|
107
|
+
}
|
|
103
108
|
}
|
|
109
|
+
return links;
|
|
104
110
|
}
|
|
105
|
-
return
|
|
111
|
+
return undefined;
|
|
106
112
|
}
|
|
107
113
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { CancellationToken, editor, IMarkdownString, IRange, languages, Position } from '../../monaco-api.js';
|
|
2
2
|
import { Provider } from './base.js';
|
|
3
3
|
import { DiagnosticCode } from '@mirascript/wasm';
|
|
4
|
-
import { codeblock, getDeep, valueDoc, paramsList
|
|
4
|
+
import { codeblock, getDeep, valueDoc, paramsList } from '../utils.js';
|
|
5
5
|
import type { FieldsAccessAt, VariableAccessAt } from '../compile-result.js';
|
|
6
6
|
|
|
7
7
|
/** @inheritdoc */
|
|
@@ -131,24 +131,12 @@ export class HoverProvider extends Provider implements languages.HoverProvider {
|
|
|
131
131
|
token: CancellationToken,
|
|
132
132
|
context?: languages.HoverContext<languages.Hover>,
|
|
133
133
|
): Promise<languages.Hover | undefined> {
|
|
134
|
-
const
|
|
135
|
-
if (!
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
return this.provideVariableHover(model, d);
|
|
141
|
-
}
|
|
142
|
-
const word = wordAt(model, position);
|
|
143
|
-
if (word) {
|
|
144
|
-
const a = compiled.fieldAccessAt(model, {
|
|
145
|
-
lineNumber: position.lineNumber,
|
|
146
|
-
column: word.range.endColumn,
|
|
147
|
-
});
|
|
148
|
-
if (a) {
|
|
149
|
-
return this.provideFieldHover(model, word.range, a);
|
|
150
|
-
}
|
|
134
|
+
const value = await this.getValueAt(model, position);
|
|
135
|
+
if (!value) return undefined;
|
|
136
|
+
if ('fields' in value) {
|
|
137
|
+
return this.provideFieldHover(model, value.range, value.fields);
|
|
138
|
+
} else {
|
|
139
|
+
return this.provideVariableHover(model, value.variable);
|
|
151
140
|
}
|
|
152
|
-
return undefined;
|
|
153
141
|
}
|
|
154
142
|
}
|