@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.
@@ -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,6 +1,6 @@
1
1
  {
2
2
  "name": "@mirascript/monaco",
3
- "version": "0.1.9",
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
- "monaco-editor": "npm:@private/monaco-editor@^0.0.55",
32
- "@mirascript/wasm": "~0.1.9",
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.control` },
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*)(\??:)(?!:)/, ['support.type.property-name', '', 'delimiter']],
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.control', '', 'keyword', '', { cases: identifierCases() }, '', 'keyword.control'],
78
+ ['keyword.flow', '', 'keyword', '', { cases: identifierCases() }, '', 'keyword.flow'],
85
79
  ],
86
80
  [
87
81
  /(for)(@whitespace+)(@identifier)(@whitespace+)(in)/,
88
- ['keyword.control', '', { cases: identifierCases() }, '', 'keyword.control'],
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*(?=!?\.))`, ['entity.name.namespace', '']],
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
- doc_mode: [
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
- /^(\0@inlineDocParam)(@whitespace+)(\.\.|)(mut)(@whitespace+)(@identifier)/,
264
+ /(@inlineDocParam)(@whitespace+)(\.\.|)(mut)(@whitespace+)(@identifier)/,
266
265
  ['entity.name.label', '', 'delimiter', 'keyword.mut', '', 'variable.emphasis'],
267
266
  ],
268
267
  [
269
- /^(\0@inlineDocParam)(@whitespace+)(\.\.|)(@identifier)/,
268
+ /(@inlineDocParam)(@whitespace+)(\.\.|)(@identifier)/,
270
269
  ['entity.name.label', '', 'delimiter', 'variable.other.constant.emphasis'],
271
270
  ],
272
- [/^(\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
+ ],
273
275
 
276
+ doc_mode: [
274
277
  [
275
- /(@identifier)(@whitespace*)(:)(@whitespace*)(\/\*@whitespace*<)(extern )([.\w]*Function)(>@whitespace*\*\/)/,
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
- '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',
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+)/, ['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
+ ],
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
- /(let)(@whitespace+)(mut)(@whitespace+)(@identifier)/,
315
- [{ 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' }],
316
374
  ],
317
375
  [
318
- /(let|const)(@whitespace+)(@identifier)/,
319
- [{ token: 'keyword.$1' }, '', { token: 'variable.other.constant', next: '@root' }],
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
- /(\.\.|)(@identifier)(\s*)(:|,|\))/,
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
- [/[()]/, '@brackets'],
360
- [/;/, { token: 'delimiter', next: '@pop', goBack: 1 }],
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
- 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
  }
@@ -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, wordAt } from '../utils.js';
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 compiled = await this.getCompileResult(model);
135
- if (!compiled) {
136
- return undefined;
137
- }
138
- const d = compiled.variableAccessAt(model, position);
139
- if (d) {
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
  }