@mirascript/monaco 0.1.7 → 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.
@@ -1 +1 @@
1
- {"version":3,"file":"definition-reference-provider.d.ts","sourceRoot":"","sources":["../../../src/lsp/providers/definition-reference-provider.ts"],"names":[],"mappings":"AACA,OAAO,EACH,MAAM,EAEN,KAAK,SAAS,EACd,KAAK,iBAAiB,EAEtB,KAAK,QAAQ,EAEhB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAIrC;;GAEG;AACH,qBAAa,2BACT,SAAQ,QACR,YAAW,SAAS,CAAC,kBAAkB,EAAE,SAAS,CAAC,iBAAiB;IAGhE,OAAO,CAAC,QAAQ,CAAC,WAAW;gBAAX,WAAW,oBAAmF;IAInH,eAAe;IACf,OAAO,CAAC,aAAa;IAuBrB,kBAAkB;IACZ,iBAAiB,CACnB,KAAK,EAAE,MAAM,CAAC,UAAU,EACxB,QAAQ,EAAE,QAAQ,EAClB,KAAK,EAAE,iBAAiB,GACzB,OAAO,CAAC,SAAS,CAAC,YAAY,EAAE,GAAG,SAAS,CAAC;IAsBhD,kBAAkB;IACZ,iBAAiB,CACnB,KAAK,EAAE,MAAM,CAAC,UAAU,EACxB,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,SAAS,CAAC,gBAAgB,EACnC,KAAK,EAAE,iBAAiB,GACzB,OAAO,CAAC,SAAS,CAAC,QAAQ,EAAE,GAAG,SAAS,CAAC;CAuB/C"}
1
+ {"version":3,"file":"definition-reference-provider.d.ts","sourceRoot":"","sources":["../../../src/lsp/providers/definition-reference-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,MAAM,EAEN,KAAK,SAAS,EACd,KAAK,iBAAiB,EAEtB,KAAK,QAAQ,EAEhB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;A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"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"}
@@ -1,5 +1,5 @@
1
1
  import { type editor, Range, type IPosition, type IRange } from '../monaco-api.js';
2
- import { type VmAny, type VmFunctionInfo, type VmValue } from '@mirascript/mirascript';
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 serializeForDisplay(value: VmValue, maxEntries?: number, maxWidth?: number): string;
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[]): VmValue;
36
+ export declare function getDeep(value: VmAny, path: readonly string[]): VmAny;
37
37
  //# sourceMappingURL=utils.d.ts.map
@@ -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,EACV,KAAK,cAAc,EACnB,KAAK,OAAO,EACf,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,kBAAkB;IAClB,QAAQ,IAAI,MAAM,CAAC;CACtB,CAqBA;AACD,aAAa;AACb,wBAAgB,mBAAmB,CAC/B,KAAK,EAAE,MAAM,CAAC,UAAU,EACxB,IAAI,EAAE,WAAW,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,GACzC,cAAc,EAAE,CAqBlB;AAED,eAAe;AACf,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,CAAC,UAAU,EAAE,IAAI,EAAE,cAAc,GAAG,eAAe,CAAC,IAAI,CAAC,GAAG,SAAS,GAAG,MAAM,CAWrH;AAED,aAAa;AACb,wBAAgB,WAAW,CAAC,IAAI,EAAE,cAAc,GAAG,MAAM,EAAE,CA0B1D;AAED,kBAAkB;AAClB,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAI/C;AAED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AAgB,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,KAAK,CAQpE"}
package/package.json CHANGED
@@ -1,8 +1,10 @@
1
1
  {
2
2
  "name": "@mirascript/monaco",
3
- "version": "0.1.7",
4
- "type": "module",
3
+ "version": "0.1.10",
4
+ "author": "CloudPSS",
5
+ "license": "MIT",
5
6
  "description": "Monaco Editor integration for Mirascript.",
7
+ "type": "module",
6
8
  "main": "./dist/index.js",
7
9
  "types": "./dist/index.d.ts",
8
10
  "exports": {
@@ -26,8 +28,8 @@
26
28
  }
27
29
  },
28
30
  "dependencies": {
29
- "@mirascript/mirascript": "~0.1.7",
30
- "@mirascript/wasm": "~0.1.7"
31
+ "@mirascript/wasm": "~0.1.10",
32
+ "@mirascript/mirascript": "~0.1.10"
31
33
  },
32
34
  "peerDependencies": {
33
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,13 +7,16 @@ 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,
14
13
  keywords,
15
14
  numericKeywords,
16
15
  } from '../constants.js';
16
+ import { lib } from '@mirascript/mirascript/subtle';
17
+ import { isVmModule } from '@mirascript/mirascript';
18
+
19
+ const moduleNames = Object.keys(lib).filter((name) => isVmModule(lib[name as never]));
17
20
 
18
21
  /** 匹配 identifier */
19
22
  function identifierCases(
@@ -23,7 +26,7 @@ function identifierCases(
23
26
  return {
24
27
  '@numericKeywords': { ...data, token: `constant.numeric` },
25
28
  '@constantKeywords': { ...data, token: `constant.language` },
26
- '@controlKeywords': { ...data, token: `keyword.control` },
29
+ '@controlKeywords': { ...data, token: `keyword.flow` },
27
30
  '@keywords': { ...data, token: `keyword` },
28
31
  '[@]+.*': { ...data, token: `variable.other.constant` },
29
32
  '~it': { ...data, token: `variable.other.constant.emphasis` },
@@ -46,7 +49,6 @@ function getTokensProvider(mode: string): languages.IMonarchLanguage {
46
49
 
47
50
  whitespace: REG_WHITESPACE,
48
51
  identifier: REG_IDENTIFIER,
49
- docHeader: DOC_HEADER,
50
52
 
51
53
  keywords: keywords(),
52
54
  controlKeywords: controlKeywords(),
@@ -54,34 +56,30 @@ function getTokensProvider(mode: string): languages.IMonarchLanguage {
54
56
  numericKeywords: numericKeywords(),
55
57
 
56
58
  inlineDocParam: /\(parameter(?: pattern)?\)/,
59
+ inlineDocMod: ['local', 'global', 'field', 'module'].join('|'),
57
60
 
58
- start: mode === 'template' ? 'root_template' : 'root',
61
+ start: mode === 'template' ? 'root_template' : mode === 'doc' ? 'root_doc' : 'root',
59
62
  tokenPostfix: '.mirascript',
60
63
  tokenizer: {
61
- root: [
62
- [/^(?=\0)/, '', '@doc_mode'],
63
- [/^\/\*\*@docHeader\*\*\/$/, 'comment.doc', '@doc_mode'],
64
- [/[[\](){}]/, '@brackets'],
65
- { include: '@common' },
66
- ],
64
+ root: [[/[[\](){}]/, '@brackets'], { include: '@common' }],
67
65
  root_template: [
68
66
  [/[^$]+/, 'string'],
69
67
  [/(?=\$)/, '', '@string_interpolation.$S3'],
70
68
  [/[$]/, 'string'],
71
69
  ],
72
70
  common: [
73
- [/(@identifier)(@whitespace*)(\??:)(?!:)/, ['support.type.property-name', '', 'delimiter']],
71
+ [/(@identifier)(@whitespace*)(\??:)(?!:)/, ['variable.other.property', '', 'delimiter']],
74
72
  [
75
73
  /(fn)(@whitespace+)(@identifier)(?=$|@whitespace|[[({,;])/,
76
74
  ['keyword', '', { cases: identifierCases(undefined, 'entity.name.function') }],
77
75
  ],
78
76
  [
79
77
  /(for)(@whitespace+)(mut)(@whitespace+)(@identifier)(@whitespace+)(in)/,
80
- ['keyword.control', '', 'keyword', '', { cases: identifierCases() }, '', 'keyword.control'],
78
+ ['keyword.flow', '', 'keyword', '', { cases: identifierCases() }, '', 'keyword.flow'],
81
79
  ],
82
80
  [
83
81
  /(for)(@whitespace+)(@identifier)(@whitespace+)(in)/,
84
- ['keyword.control', '', { cases: identifierCases() }, '', 'keyword.control'],
82
+ ['keyword.flow', '', { cases: identifierCases() }, '', 'keyword.flow'],
85
83
  ],
86
84
  [
87
85
  /(\.)(@whitespace*)(\d+)/,
@@ -96,6 +94,7 @@ function getTokensProvider(mode: string): languages.IMonarchLanguage {
96
94
  },
97
95
  ],
98
96
  ],
97
+ [String.raw`\b(${moduleNames.join('|')})(@whitespace*(?=!?\.))`, ['type', '']],
99
98
  [
100
99
  /(\.)(@whitespace*)(@identifier)(@whitespace*)(!?)(@whitespace*(?=\())/,
101
100
  ['delimiter', '', 'entity.name.function', '', 'delimiter', ''],
@@ -254,28 +253,68 @@ function getTokensProvider(mode: string): languages.IMonarchLanguage {
254
253
  [/[*@\\]/, { token: 'comment.doc' }],
255
254
  ],
256
255
 
257
- doc_mode: [
256
+ root_doc: [
258
257
  // inline doc, start with `\0`
258
+ [/^\0/, { token: '', switchTo: '@inline_doc' }],
259
+ [/(?=.)/, { token: '', switchTo: '@doc_mode' }],
260
+ ],
261
+
262
+ inline_doc: [
259
263
  [
260
- /^(\0@inlineDocParam)(@whitespace+)(\.\.|)(mut)(@whitespace+)(@identifier)/,
264
+ /(@inlineDocParam)(@whitespace+)(\.\.|)(mut)(@whitespace+)(@identifier)/,
261
265
  ['entity.name.label', '', 'delimiter', 'keyword.mut', '', 'variable.emphasis'],
262
266
  ],
263
267
  [
264
- /^(\0@inlineDocParam)(@whitespace+)(\.\.|)(@identifier)/,
268
+ /(@inlineDocParam)(@whitespace+)(\.\.|)(@identifier)/,
265
269
  ['entity.name.label', '', 'delimiter', 'variable.other.constant.emphasis'],
266
270
  ],
267
- [/^(\0\(@identifier\))(@whitespace+)/, ['entity.name.label', '']],
271
+ [/(@whitespace*)(\(module\))(\s*)(@identifier)/, ['', 'entity.name.label', '', 'type']],
272
+ [/(\(@inlineDocMod\))(@whitespace+)/, ['entity.name.label', '']],
273
+ { include: '@doc_mode' },
274
+ ],
268
275
 
276
+ doc_mode: [
269
277
  [
270
- /(@identifier)(@whitespace*)(:)(@whitespace*)(\/\*@whitespace*<)(extern )([.\w]*Function)(>@whitespace*\*\/)/,
278
+ /(@identifier)(@whitespace*)(:)(@whitespace*)(\/\*@whitespace*<)(extern )((?:async )?function\*?)(@whitespace*)([<>.\w]*)(\(\))(>@whitespace*\*\/)/,
271
279
  [
272
280
  'entity.name.function.doc',
273
281
  '',
274
282
  'delimiter',
275
283
  '',
276
284
  'comment.doc',
277
- 'type',
278
- 'entity.name.label',
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',
279
318
  'comment.doc',
280
319
  ],
281
320
  ],
@@ -287,72 +326,73 @@ function getTokensProvider(mode: string): languages.IMonarchLanguage {
287
326
  'delimiter',
288
327
  '',
289
328
  'comment.doc',
290
- 'type',
329
+ 'type.doc',
291
330
  'entity.name.label',
292
331
  'comment.doc',
293
332
  ],
294
333
  ],
295
- [/(@identifier)(@whitespace*)(:)(@whitespace+)/, ['support.type.property-name', '', 'delimiter', '']],
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
+ ],
296
360
  [
297
361
  /(\/\*@whitespace*<)(\w+@whitespace*)([.\w]*)(>@whitespace*\*\/)/,
298
- ['comment.doc', 'type', 'entity.name.label', 'comment.doc'],
362
+ ['comment.doc', 'type.doc', 'entity.name.label', 'comment.doc'],
299
363
  ],
300
- [/(\s*)(\(module\))(\s*)(@identifier)/, ['', 'entity.name.label', '', 'entity.name.namespace']],
301
364
 
365
+ [/(let|const)(@whitespace+)(@identifier)/, [{ token: 'keyword.$1' }, '', 'variable.other.constant']],
302
366
  [/(fn)(@whitespace+)(@identifier)$/, ['keyword.fn.doc', '', 'entity.name.function.doc']],
303
367
  [
304
- /(fn)(@whitespace+)(@identifier)(\()(\.\.)(\))$/,
368
+ /(fn)(@whitespace+)(@identifier)(\()(\.\.)(\))/,
305
369
  ['keyword.fn.doc', '', 'entity.name.function.doc', '@brackets', 'delimiter', '@brackets'],
306
370
  ],
307
- [/fn/, 'keyword.fn.doc', '@type_doc_fn'],
308
371
  [
309
- /(let)(@whitespace+)(mut)(@whitespace+)(@identifier)/,
310
- [{ token: 'keyword.$1' }, '', 'keyword.mut', '', { token: 'variable', next: '@root' }],
372
+ /(fn)(@whitespace+)(@identifier)/,
373
+ ['keyword.fn.doc', '', { token: 'entity.name.function.doc', next: '@type_doc' }],
311
374
  ],
312
375
  [
313
- /(let|const)(@whitespace+)(@identifier)/,
314
- [{ token: 'keyword.$1' }, '', { token: 'variable.other.constant', next: '@root' }],
376
+ /(let)(@whitespace+)(mut)(@whitespace+)(@identifier)/,
377
+ [{ token: 'keyword.$1' }, '', 'keyword.mut', '', 'variable'],
315
378
  ],
316
- { include: '@common' },
317
379
  [/[[\](){}]/, '@brackets'],
380
+ { include: '@common' },
318
381
  ],
319
382
  type_doc: [
320
- { include: '@type_doc_common' },
321
- [/[,)]/, 'delimiter', '@pop'],
322
383
  [/;/, { token: 'delimiter', next: '@pop', goBack: 1 }],
323
- ],
324
- type_doc_inner: [{ include: '@type_doc_common' }, [/[,;]/, 'delimiter']],
325
- type_doc_common: [
326
- [/fn\b/, 'type', '@type_doc_fn'],
384
+ [/(fn)(\()/, ['type', '@brackets']],
327
385
  [/(type)(\()(@identifier)(\))/, ['type', '@brackets', 'variable.emphasis.doc', '@brackets']],
328
- [/@identifier/, 'type'],
329
- [/[[(]/, '@brackets', '@type_doc_inner'],
330
- [/[\])]/, '@brackets', '@pop'],
331
- [/[&|.]/, 'delimiter'],
332
- [/->/, 'delimiter'],
333
- [/@whitespace+/, ''],
334
- ],
335
- type_doc_fn: [
336
- [/(@identifier)(\()/, ['entity.name.function.doc', '@brackets']],
337
- [/@whitespace+/, ''],
338
- [/(->)/, { token: 'delimiter', switchTo: '@type_doc' }],
339
386
  [
340
- /(\.\.|)(@identifier)(\s*)(:|,|\))/,
341
- [
342
- 'delimiter',
343
- 'variable.emphasis.doc',
344
- '',
345
- {
346
- cases: {
347
- ':': { token: 'delimiter', next: '@type_doc' },
348
- '\\)': '@brackets',
349
- '@default': 'delimiter',
350
- },
351
- },
352
- ],
387
+ /(@identifier)(:)(@whitespace*)(fn)(\()/,
388
+ ['entity.name.function.emphasis.doc', 'delimiter', '', 'type', '@brackets'],
353
389
  ],
354
- [/[()]/, '@brackets'],
355
- [/;/, { token: 'delimiter', next: '@pop', goBack: 1 }],
390
+ [/(@identifier)(:)/, ['variable.emphasis', 'delimiter']],
391
+ [/@identifier/, 'type'],
392
+ [/[&|.,]/, 'delimiter'],
393
+ [/->/, 'delimiter'],
394
+ [/[[\]()]/, '@brackets'],
395
+ { include: '@whitespace' },
356
396
  ],
357
397
  },
358
398
  };
@@ -363,5 +403,6 @@ export function registerMiraScriptTokensProvider(): IDisposable[] {
363
403
  return [
364
404
  languages.setMonarchTokensProvider('mirascript', getTokensProvider('script')),
365
405
  languages.setMonarchTokensProvider('mirascript-template', getTokensProvider('template')),
406
+ languages.setMonarchTokensProvider('mirascript-doc', getTokensProvider('doc')),
366
407
  ];
367
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
- return key.startsWith('@') || key.startsWith('$') ? key.slice(1) : key;
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 = model.getValueInRange(definition.range);
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
- if (char && !name.toLowerCase().includes(char)) {
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(``, 'mirascript', Uri.parse('mirascript:///lib/global.mira')),
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(name: string, value: VmAny): { uri: Uri; range: IRange } {
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 { script, doc } = valueDoc(name, value, 'declare');
31
- const code = [
32
- `/**${DOC_HEADER}**/`,
33
- '',
34
- `/**`,
35
- ...doc.flatMap((sec) => sec.split('\n')).map((line) => ` * ${line}`),
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 compiled = await this.getCompileResult(model);
58
- if (!compiled) return undefined;
59
- const globals = await this.getContext(model);
60
- const d = compiled.variableAccessAt(model, position);
61
- if (!d) return [];
62
- const { def, ref } = d;
63
- let originSelectionRange;
64
- if (ref != null) {
65
- originSelectionRange = def.references[ref]?.range;
66
- } else if ('definition' in def) {
67
- originSelectionRange = def.definition.range;
68
- }
69
- let link: languages.LocationLink;
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
- link = { uri: model.uri, range: def.definition.range };
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
- link.originSelectionRange = originSelectionRange;
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 compiled = await this.getCompileResult(model);
86
- if (!compiled) return undefined;
87
- const globals = await this.getContext(model);
88
- const d = compiled.variableAccessAt(model, position);
89
- if (!d) return [];
90
- const { def } = d;
91
- const links: languages.Location[] = def.references.map((u) => ({
92
- uri: model.uri,
93
- range: u.range,
94
- }));
95
- if (context.includeDeclaration) {
96
- if ('name' in def) {
97
- links.push(this.prepareGlobal(def.name, globals.get(def.name)));
98
- } else if (!Range.isEmpty(def.definition.range)) {
99
- links.push({
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 links;
111
+ return undefined;
106
112
  }
107
113
  }