@lvce-editor/shared-process 0.11.7 → 0.11.9

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.
Files changed (31) hide show
  1. package/config/defaultKeyBindings.json +4 -0
  2. package/config/defaultSettings.json +2 -0
  3. package/extensions/builtin.language-basics-cpp/src/tokenizeCpp.js +29 -6
  4. package/extensions/builtin.language-basics-css/src/tokenizeCss.js +176 -25
  5. package/extensions/builtin.language-basics-gn/README.md +14 -0
  6. package/extensions/builtin.language-basics-gn/extension.json +12 -0
  7. package/extensions/builtin.language-basics-gn/src/tokenizeGn.js +178 -0
  8. package/extensions/builtin.language-basics-javascript/src/tokenizeJavaScript.js +5 -0
  9. package/extensions/builtin.language-basics-json5/README.md +16 -0
  10. package/extensions/builtin.language-basics-json5/extension.json +12 -0
  11. package/extensions/builtin.language-basics-json5/src/tokenizeJson5.js +321 -0
  12. package/extensions/builtin.language-basics-perl/extension.json +2 -1
  13. package/extensions/builtin.language-basics-perl/src/tokenizePerl.js +53 -6
  14. package/extensions/builtin.language-basics-python/extension.json +2 -1
  15. package/extensions/builtin.language-basics-python/src/tokenizePython.js +129 -36
  16. package/extensions/builtin.language-basics-shellscript/src/tokenizeShellScript.js +274 -13
  17. package/extensions/builtin.language-basics-typescript/src/tokenizeTypeScript.js +197 -15
  18. package/extensions/builtin.theme-ayu/color-theme.json +2 -0
  19. package/extensions/builtin.theme-slime/color-theme.json +6 -0
  20. package/package.json +4 -4
  21. package/src/parts/Command/Command.js +38 -40
  22. package/src/parts/ErrorCodes/ErrorCodes.js +9 -17
  23. package/src/parts/GetResponse/GetResponse.js +2 -2
  24. package/src/parts/Module/Module.js +2 -2
  25. package/src/parts/ModuleMap/ModuleMap.js +1 -1
  26. package/src/parts/PrettyError/PrettyError.js +55 -5
  27. package/src/parts/RipGrep/RipGrep.js +30 -0
  28. package/src/parts/SearchFile/SearchFile.js +12 -16
  29. package/src/parts/TextSearch/TextSearch.ipc.js +7 -0
  30. package/src/parts/{Search/Search.js → TextSearch/TextSearch.js} +11 -17
  31. package/src/parts/Search/Search.ipc.js +0 -7
@@ -25,6 +25,15 @@ const State = {
25
25
  AfterKeywordEnumAfterVariableName: 22,
26
26
  InsideEnum: 23,
27
27
  InsideEnumAfterVariableName: 24,
28
+ InsideObjectDestructuring: 25,
29
+ InsideObjectDestructuringAfterValue: 26,
30
+ AfterKeywordInterface: 27,
31
+ InsideTypeObject: 28,
32
+ AfterMethodName: 29,
33
+ InsideMethodParameters: 30,
34
+ InsideMethodParametersAfterVariableName: 31,
35
+ AfterMethodParameters: 32,
36
+ // AfterKeywordImport: 27,
28
37
  }
29
38
 
30
39
  /**
@@ -53,6 +62,7 @@ export const TokenType = {
53
62
  Class: 17,
54
63
  StorageModifier: 18,
55
64
  KeywordVoid: 19,
65
+ Function: 20,
56
66
  }
57
67
 
58
68
  export const TokenMap = {
@@ -78,6 +88,7 @@ export const TokenMap = {
78
88
  [TokenType.Class]: 'Class',
79
89
  [TokenType.StorageModifier]: 'StorageModifier',
80
90
  [TokenType.KeywordVoid]: 'KeywordVoid',
91
+ [TokenType.Function]: 'Function',
81
92
  }
82
93
 
83
94
  export const initialLineState = {
@@ -89,14 +100,14 @@ export const initialLineState = {
89
100
  }
90
101
 
91
102
  const RE_KEYWORD =
92
- /^(?:yield|with|while|void|var|typeof|type|true|try|throw|this|static|switch|super|return|public|protected|private|package|null|new|let|interface|instanceof|in|import|implements|if|function|for|finally|from|false|extends|export|enum|else|do|delete|default|debugger|declare|continue|const|class|catch|case|break|await)\b/
103
+ /^(?:yield|with|while|void|var|typeof|type|true|try|throw|this|static|switch|super|return|public|protected|private|package|null|new|let|interface|instanceof|in|import|implements|if|function|for|finally|from|false|extends|export|enum|else|do|delete|default|debugger|declare|continue|const|class|catch|case|break|await|async)\b/
93
104
  const RE_WHITESPACE = /^\s+/
94
- const RE_VARIABLE_NAME = /^[\$a-zA-Z]+/
105
+ const RE_VARIABLE_NAME = /^[\$a-zA-Z\_][\$a-zA-Z\_\d]*/
95
106
  const RE_PUNCTUATION = /^[:,;\{\}\[\]\.=\(\)>\+]/
96
107
  const RE_QUOTE_SINGLE = /^'/
97
108
  const RE_QUOTE_DOUBLE = /^"/
98
- const RE_STRING_SINGLE_QUOTE_CONTENT = /^[^']+/
99
- const RE_STRING_DOUBLE_QUOTE_CONTENT = /^[^"]+/
109
+ const RE_STRING_SINGLE_QUOTE_CONTENT = /^[^\\']+/
110
+ const RE_STRING_DOUBLE_QUOTE_CONTENT = /^[^\\"]+/
100
111
  const RE_NUMERIC = /^\d+/
101
112
  const RE_COLON = /^\:/
102
113
  const RE_TYPE_PRIMITIVE = /^(?:string|boolean|number|bigint|symbol|void|any)\b/
@@ -131,6 +142,15 @@ const RE_COMMA = /^\,/
131
142
  const RE_DOT = /^\./
132
143
  const RE_SQUARE_OPEN = /^\[/
133
144
  const RE_SQUARE_CLOSE = /^\]/
145
+ const RE_QUESTION_MARK = /^\?/
146
+ const RE_EXCLAMATION_MARK = /^\!/
147
+ const RE_STAR = /^\*/
148
+ const RE_AS = /^as/
149
+ const RE_ESCAPE = /^\\.?/
150
+ const RE_ANGLE_OPEN = /^</
151
+ const RE_ANGLE_CLOSE = /^>/
152
+ const RE_OPERATOR = /^[!\*\?\.\:\|\%\&\^@]/
153
+ const RE_METHOD_NAME = /^[\w\d]+(?=\s*(\(|\:\s*function|\:\s*\())/
134
154
 
135
155
  export const hasArrayReturn = true
136
156
 
@@ -149,8 +169,6 @@ export const tokenizeLine = (line, lineState) => {
149
169
  let stack = lineState.stack
150
170
  while (index < line.length) {
151
171
  const part = line.slice(index)
152
- part
153
- state
154
172
  switch (state) {
155
173
  case State.TopLevelContent:
156
174
  if ((next = part.match(RE_WHITESPACE))) {
@@ -178,6 +196,10 @@ export const tokenizeLine = (line, lineState) => {
178
196
  case 'if':
179
197
  case 'break':
180
198
  case 'throw':
199
+ case 'while':
200
+ case 'try':
201
+ case 'catch':
202
+ case 'finally':
181
203
  token = TokenType.KeywordControl
182
204
  state = State.TopLevelContent
183
205
  break
@@ -211,6 +233,10 @@ export const tokenizeLine = (line, lineState) => {
211
233
  token = TokenType.KeywordVoid
212
234
  state = State.TopLevelContent
213
235
  break
236
+ case 'interface':
237
+ token = TokenType.Keyword
238
+ state = State.AfterKeywordInterface
239
+ break
214
240
  default:
215
241
  token = TokenType.Keyword
216
242
  state = State.TopLevelContent
@@ -246,7 +272,10 @@ export const tokenizeLine = (line, lineState) => {
246
272
  } else if ((next = part.match(RE_QUOTE_DOUBLE))) {
247
273
  token = TokenType.Punctuation
248
274
  state = State.InsideDoubleQuoteString
249
- } else if ((next = part.match(RE_VERTICAL_LINE))) {
275
+ } else if ((next = part.match(RE_OPERATOR))) {
276
+ token = TokenType.Punctuation
277
+ state = State.TopLevelContent
278
+ } else if ((next = part.match(RE_ANGLE_OPEN))) {
250
279
  token = TokenType.Punctuation
251
280
  state = State.TopLevelContent
252
281
  } else {
@@ -261,6 +290,9 @@ export const tokenizeLine = (line, lineState) => {
261
290
  } else if ((next = part.match(RE_STRING_SINGLE_QUOTE_CONTENT))) {
262
291
  token = TokenType.String
263
292
  state = State.InsideSingleQuoteString
293
+ } else if ((next = part.match(RE_ESCAPE))) {
294
+ token = TokenType.String
295
+ state = State.InsideSingleQuoteString
264
296
  } else {
265
297
  throw new Error('no')
266
298
  }
@@ -272,6 +304,9 @@ export const tokenizeLine = (line, lineState) => {
272
304
  } else if ((next = part.match(RE_STRING_DOUBLE_QUOTE_CONTENT))) {
273
305
  token = TokenType.String
274
306
  state = State.InsideDoubleQuoteString
307
+ } else if ((next = part.match(RE_ESCAPE))) {
308
+ token = TokenType.String
309
+ state = State.InsideDoubleQuoteString
275
310
  } else {
276
311
  throw new Error('no')
277
312
  }
@@ -292,13 +327,18 @@ export const tokenizeLine = (line, lineState) => {
292
327
  } else if ((next = part.match(RE_EQUAL))) {
293
328
  token = TokenType.Punctuation
294
329
  state = State.TopLevelContent
330
+ } else if ((next = part.match(RE_CURLY_OPEN))) {
331
+ token = TokenType.Punctuation
332
+ state = State.InsideObjectDestructuring
333
+ } else if ((next = part.match(RE_DOT))) {
334
+ token = TokenType.Punctuation
335
+ state = State.TopLevelContent
295
336
  } else {
296
337
  line
297
338
  part
298
339
  throw new Error('no')
299
340
  }
300
341
  break
301
-
302
342
  case State.AfterKeywordTypeDeclaration:
303
343
  if ((next = part.match(RE_WHITESPACE))) {
304
344
  token = TokenType.Whitespace
@@ -315,14 +355,13 @@ export const tokenizeLine = (line, lineState) => {
315
355
  }
316
356
  break
317
357
  case State.BeforeType:
318
- part
319
358
  if ((next = part.match(RE_WHITESPACE))) {
320
359
  token = TokenType.Whitespace
321
360
  state = State.BeforeType
322
361
  } else if ((next = part.match(RE_TYPE_PRIMITIVE))) {
323
362
  part
324
363
  token = TokenType.TypePrimitive
325
- state = State.AfterType
364
+ state = stack.pop() || State.AfterType
326
365
  } else if ((next = part.match(RE_VARIABLE_NAME))) {
327
366
  part
328
367
  token = TokenType.Type
@@ -333,6 +372,7 @@ export const tokenizeLine = (line, lineState) => {
333
372
  } else if ((next = part.match(RE_ROUND_OPEN))) {
334
373
  token = TokenType.Punctuation
335
374
  state = State.InsideTypeExpression
375
+ stack.push(State.AfterTypeExpression)
336
376
  } else if ((next = part.match(RE_ARROW))) {
337
377
  token = TokenType.Punctuation
338
378
  state = State.BeforeType
@@ -345,20 +385,25 @@ export const tokenizeLine = (line, lineState) => {
345
385
  } else if ((next = part.match(RE_NUMERIC))) {
346
386
  token = TokenType.Numeric
347
387
  state = State.AfterType
388
+ } else if ((next = part.match(RE_CURLY_OPEN))) {
389
+ token = TokenType.Punctuation
390
+ state = State.InsideTypeObject
391
+ } else if ((next = part.match(RE_QUOTE_SINGLE))) {
392
+ token = TokenType.Punctuation
393
+ state = State.InsideSingleQuoteString
394
+ stack.push(State.BeforeType)
348
395
  } else {
349
396
  part
350
397
  throw new Error('no')
351
398
  }
352
399
  break
353
400
  case State.InsideTypeExpression:
354
- part
355
401
  if ((next = part.match(RE_ROUND_CLOSE))) {
356
402
  token = TokenType.Punctuation
357
403
  state = State.AfterTypeExpression
358
404
  } else if ((next = part.match(RE_VARIABLE_NAME))) {
359
405
  token = TokenType.VariableName
360
406
  state = State.AfterVariableName
361
- stack.push(State.InsideTypeExpression)
362
407
  } else if ((next = part.match(RE_WHITESPACE))) {
363
408
  token = TokenType.Whitespace
364
409
  state = State.InsideTypeExpression
@@ -376,6 +421,15 @@ export const tokenizeLine = (line, lineState) => {
376
421
  } else if ((next = part.match(RE_WHITESPACE))) {
377
422
  token = TokenType.Whitespace
378
423
  state = State.AfterTypeExpression
424
+ } else if ((next = part.match(RE_COMMA))) {
425
+ token = TokenType.Punctuation
426
+ state = State.InsideTypeExpression
427
+ } else if ((next = part.match(RE_ROUND_CLOSE))) {
428
+ token = TokenType.Punctuation
429
+ state = stack.pop() || State.AfterTypeExpression
430
+ } else if ((next = part.match(RE_CURLY_CLOSE))) {
431
+ token = TokenType.Punctuation
432
+ state = stack.pop() || State.TopLevelContent
379
433
  } else {
380
434
  part
381
435
  throw new Error('no')
@@ -404,7 +458,6 @@ export const tokenizeLine = (line, lineState) => {
404
458
  }
405
459
  break
406
460
  case State.AfterType:
407
- part
408
461
  if ((next = part.match(RE_SEMICOLON))) {
409
462
  token = TokenType.Punctuation
410
463
  state = stack.pop() || State.TopLevelContent
@@ -423,7 +476,7 @@ export const tokenizeLine = (line, lineState) => {
423
476
  state = State.BeforeType
424
477
  } else if ((next = part.match(RE_ROUND_CLOSE))) {
425
478
  token = TokenType.Punctuation
426
- state = State.BeforeType
479
+ state = stack.pop() || State.BeforeType
427
480
  } else if ((next = part.match(RE_COMMA))) {
428
481
  token = TokenType.Punctuation
429
482
  state = stack.pop() || State.TopLevelContent
@@ -433,9 +486,23 @@ export const tokenizeLine = (line, lineState) => {
433
486
  } else if ((next = part.match(RE_SQUARE_OPEN))) {
434
487
  token = TokenType.Punctuation
435
488
  state = State.AfterType
489
+ stack.push(State.AfterType)
436
490
  } else if ((next = part.match(RE_SQUARE_CLOSE))) {
437
491
  token = TokenType.Punctuation
438
492
  state = State.AfterType
493
+ } else if ((next = part.match(RE_VERTICAL_LINE))) {
494
+ token = TokenType.Punctuation
495
+ state = State.BeforeType
496
+ } else if ((next = part.match(RE_ANGLE_OPEN))) {
497
+ token = TokenType.Punctuation
498
+ state = State.BeforeType
499
+ stack.push(State.AfterType)
500
+ } else if ((next = part.match(RE_VARIABLE_NAME))) {
501
+ token = TokenType.Type
502
+ state = State.AfterType
503
+ } else if ((next = part.match(RE_ANGLE_CLOSE))) {
504
+ token = TokenType.Punctuation
505
+ state = State.AfterType
439
506
  } else {
440
507
  // stack.push(State.AfterType)
441
508
  part
@@ -525,7 +592,7 @@ export const tokenizeLine = (line, lineState) => {
525
592
  state = State.InsideBlockComment
526
593
  } else if ((next = part.match(RE_BLOCK_COMMENT_END))) {
527
594
  token = TokenType.Comment
528
- state = State.TopLevelContent
595
+ state = stack.pop() || State.TopLevelContent
529
596
  } else if ((next = part.match(RE_ANYTHING_UNTIL_END))) {
530
597
  token = TokenType.Comment
531
598
  state = State.InsideBlockComment
@@ -582,11 +649,124 @@ export const tokenizeLine = (line, lineState) => {
582
649
  stack
583
650
  token = TokenType.Punctuation
584
651
  state = stack.pop() || State.TopLevelContent
652
+ } else if ((next = part.match(RE_SEMICOLON))) {
653
+ token = TokenType.Punctuation
654
+ state = State.InsideClass
655
+ } else {
656
+ part
657
+ throw new Error('no')
658
+ }
659
+ break
660
+ case State.InsideObjectDestructuring:
661
+ if ((next = part.match(RE_WHITESPACE))) {
662
+ token = TokenType.Whitespace
663
+ state = State.InsideObjectDestructuring
664
+ } else if ((next = part.match(RE_VARIABLE_NAME))) {
665
+ token = TokenType.VariableName
666
+ state = State.InsideObjectDestructuringAfterValue
667
+ } else {
668
+ throw new Error('no')
669
+ }
670
+ break
671
+ case State.InsideObjectDestructuringAfterValue:
672
+ if ((next = part.match(RE_WHITESPACE))) {
673
+ token = TokenType.Whitespace
674
+ state = State.InsideObjectDestructuringAfterValue
675
+ } else if ((next = part.match(RE_CURLY_CLOSE))) {
676
+ token = TokenType.Punctuation
677
+ state = State.AfterKeywordDeclaration
678
+ } else {
679
+ throw new Error('no')
680
+ }
681
+ break
682
+ case State.AfterKeywordInterface:
683
+ if ((next = part.match(RE_WHITESPACE))) {
684
+ token = TokenType.Whitespace
685
+ state = State.AfterKeywordInterface
686
+ } else if ((next = part.match(RE_VARIABLE_NAME))) {
687
+ token = TokenType.Type
688
+ state = State.BeforeType
689
+ } else {
690
+ throw new Error('no')
691
+ }
692
+ break
693
+ case State.InsideTypeObject:
694
+ if ((next = part.match(RE_WHITESPACE))) {
695
+ token = TokenType.Whitespace
696
+ state = State.InsideTypeObject
697
+ } else if ((next = part.match(RE_BLOCK_COMMENT_START))) {
698
+ token = TokenType.Comment
699
+ state = State.InsideBlockComment
700
+ stack.push(State.InsideTypeObject)
701
+ } else if ((next = part.match(RE_METHOD_NAME))) {
702
+ token = TokenType.Function
703
+ state = State.AfterMethodName
704
+ } else if ((next = part.match(RE_VARIABLE_NAME))) {
705
+ token = TokenType.VariableName
706
+ state = State.InsideTypeObject
707
+ } else if ((next = part.match(RE_CURLY_CLOSE))) {
708
+ token = TokenType.Punctuation
709
+ state = stack.pop() || State.TopLevelContent
710
+ } else if ((next = part.match(RE_COLON))) {
711
+ token = TokenType.Punctuation
712
+ state = State.BeforeType
713
+ stack.push(State.InsideTypeObject)
714
+ } else if ((next = part.match(RE_COMMA))) {
715
+ token = TokenType.Punctuation
716
+ state = State.InsideTypeObject
717
+ } else if ((next = part.match(RE_SEMICOLON))) {
718
+ token = TokenType.Punctuation
719
+ state = State.InsideTypeObject
585
720
  } else {
586
721
  part
587
722
  throw new Error('no')
588
723
  }
589
724
  break
725
+ case State.AfterMethodName:
726
+ if ((next = part.match(RE_ROUND_OPEN))) {
727
+ token = TokenType.Punctuation
728
+ state = State.InsideMethodParameters
729
+ // stack.push()
730
+ } else {
731
+ throw new Error('no')
732
+ }
733
+ break
734
+ case State.InsideMethodParameters:
735
+ if ((next = part.match(RE_VARIABLE_NAME))) {
736
+ token = TokenType.VariableName
737
+ state = State.InsideMethodParametersAfterVariableName
738
+ } else if ((next = part.match(RE_ROUND_CLOSE))) {
739
+ token = TokenType.Punctuation
740
+ state = State.AfterMethodParameters
741
+ } else if ((next = part.match(RE_CURLY_CLOSE))) {
742
+ token = TokenType.Punctuation
743
+ state = stack.pop() || State.TopLevelContent
744
+ } else if ((next = part.match(RE_COLON))) {
745
+ token = TokenType.Punctuation
746
+ state = State.BeforeType
747
+ } else {
748
+ part
749
+ throw new Error('no')
750
+ }
751
+ break
752
+ case State.InsideMethodParametersAfterVariableName:
753
+ if ((next = part.match(RE_COLON))) {
754
+ token = TokenType.Punctuation
755
+ state = State.BeforeType
756
+ stack.push(State.InsideMethodParameters)
757
+ } else {
758
+ throw new Error('no')
759
+ }
760
+ break
761
+ case State.AfterMethodParameters:
762
+ if ((next = part.match(RE_COLON))) {
763
+ token = TokenType.Punctuation
764
+ state = State.BeforeType
765
+ stack.push(State.InsideTypeObject)
766
+ } else {
767
+ throw new Error('no')
768
+ }
769
+ break
590
770
  default:
591
771
  state
592
772
  throw new Error('no')
@@ -598,6 +778,8 @@ export const tokenizeLine = (line, lineState) => {
598
778
  if (state === State.AfterType && stack[0] === State.InsideClass) {
599
779
  state = State.InsideClass
600
780
  stack.pop()
781
+ } else if (state === State.AfterType) {
782
+ state = stack.pop() || State.TopLevelContent
601
783
  }
602
784
  return {
603
785
  state,
@@ -12,6 +12,8 @@
12
12
  "ContextMenuBackground": "rgb(252, 252, 252)",
13
13
  "ContextMenuForeground": "rgb(138, 145, 153)",
14
14
 
15
+ "DebugSectionHeaderBackground": "#f8f9fa",
16
+
15
17
  "EditorBackGround": "",
16
18
  "EditorScrollBarBackground": "rgba(138, 145, 153, 0.6)",
17
19
  "EditorCursorBackground": "#ffaa33",
@@ -19,6 +19,8 @@
19
19
  "InputBackground": "rgb(36, 41, 42)",
20
20
  "InputForeground": "rgb(225, 225, 225)",
21
21
 
22
+ "LinkForeground": "#3794ff",
23
+
22
24
  "ListActiveSelectionBackground": "#515f59",
23
25
  "ListActiveSelectionForeground": "#ffffff",
24
26
  "ListHoverBackground": "#405c5033",
@@ -224,6 +226,10 @@
224
226
  {
225
227
  "name": "CssAtRule",
226
228
  "foreground": "#E78484"
229
+ },
230
+ {
231
+ "name": "KeywordThis",
232
+ "foreground": "#BE9296"
227
233
  }
228
234
  ]
229
235
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/shared-process",
3
- "version": "0.11.7",
3
+ "version": "0.11.9",
4
4
  "description": "Utility package for @lvce-editor/server",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -17,9 +17,9 @@
17
17
  },
18
18
  "dependencies": {
19
19
  "@babel/code-frame": "^7.18.6",
20
- "@lvce-editor/extension-host": "0.11.7",
21
- "@lvce-editor/extension-host-helper-process": "0.11.7",
22
- "@lvce-editor/pty-host": "0.11.7",
20
+ "@lvce-editor/extension-host": "0.11.9",
21
+ "@lvce-editor/extension-host-helper-process": "0.11.9",
22
+ "@lvce-editor/pty-host": "0.11.9",
23
23
  "debug": "^4.3.4",
24
24
  "execa": "^6.1.0",
25
25
  "exit-hook": "^3.1.4",
@@ -1,8 +1,8 @@
1
1
  import * as ModuleMap from '../ModuleMap/ModuleMap.js'
2
+ import { VError } from '../VError/VError.js'
2
3
 
3
4
  export const state = {
4
5
  commands: Object.create(null),
5
- invocables: Object.create(null),
6
6
  pendingModules: Object.create(null),
7
7
  async load(moduleId) {},
8
8
  }
@@ -19,67 +19,65 @@ const initializeModule = (module) => {
19
19
  }
20
20
  return
21
21
  }
22
- throw new Error(`module ${module.name} is missing commands`)
22
+ throw new Error(
23
+ `module ${module.name} is missing an initialize function and commands`
24
+ )
25
+ }
26
+
27
+ const loadModule = async (moduleId) => {
28
+ try {
29
+ const module = await state.load(moduleId)
30
+ initializeModule(module)
31
+ } catch (error) {
32
+ if (
33
+ error &&
34
+ error instanceof SyntaxError &&
35
+ error.stack === `SyntaxError: ${error.message}`
36
+ ) {
37
+ Error.captureStackTrace(error, loadModule)
38
+ }
39
+ throw new VError(error, `failed to load module ${moduleId}`)
40
+ }
23
41
  }
24
42
 
25
43
  const getOrLoadModule = (moduleId) => {
26
44
  if (!state.pendingModules[moduleId]) {
27
- const importPromise = state.load(moduleId)
28
- state.pendingModules[moduleId] = importPromise
29
- .then(initializeModule)
30
- .catch((error) => {
31
- console.error(error)
32
- })
45
+ state.pendingModules[moduleId] = loadModule(moduleId)
33
46
  }
34
47
  return state.pendingModules[moduleId]
35
48
  }
36
49
 
37
- const loadCommand = (command) => getOrLoadModule(ModuleMap.getModuleId(command))
50
+ const loadCommand = async (command) => {
51
+ await getOrLoadModule(ModuleMap.getModuleId(command))
52
+ }
38
53
 
39
54
  export const register = (commandId, listener) => {
40
55
  state.commands[commandId] = listener
41
56
  }
42
57
 
43
- export const registerInvocable = (commandId, listener) => {
44
- state.invocables[commandId] = listener
45
- }
58
+ const hasThrown = new Set()
46
59
 
47
- export const invoke = async (command, ...args) => {
48
- if (!(command in state.commands)) {
60
+ const executeCommandAsync = async (command, ...args) => {
61
+ try {
49
62
  await loadCommand(command)
50
- if (!(command in state.commands)) {
51
- console.warn(`[shared process] Unknown command "${command}"`)
52
- throw new Error(`Command ${command} not found`)
53
- }
63
+ } catch (error) {
64
+ throw new VError(error, `Failed to load command ${command}`)
54
65
  }
55
- if (typeof state.commands[command] !== 'function') {
56
- throw new TypeError(`Command ${command} is not a function`)
66
+ if (!(command in state.commands)) {
67
+ if (hasThrown.has(command)) {
68
+ return
69
+ }
70
+ hasThrown.add(command)
71
+ throw new Error(`Command did not register "${command}"`)
57
72
  }
58
- return state.commands[command](...args)
73
+ return execute(command, ...args)
59
74
  }
60
75
 
61
76
  export const execute = (command, ...args) => {
62
77
  if (command in state.commands) {
63
- state.commands[command](...args)
64
- } else {
65
- loadCommand(command)
66
- // TODO can skip then block in prod (only to prevent endless loop in dev)
67
- .then(() => {
68
- if (!(command in state.commands)) {
69
- console.warn(`Unknown command "${command}"`)
70
- return
71
- }
72
- try {
73
- execute(command, ...args)
74
- } catch (error) {
75
- console.error('[shared process] command failed to execute')
76
- console.error(error)
77
- }
78
- })
79
- .catch((error) => {
80
- console.error(error)
81
- })
78
+ return state.commands[command](...args)
82
79
  }
80
+ return executeCommandAsync(command, ...args)
83
81
  }
84
82
 
85
83
  export const setLoad = (load) => {
@@ -1,21 +1,13 @@
1
- export const ENOENT = 'ENOENT'
2
-
3
- export const EXDEV = 'EXDEV'
4
-
5
- export const EEXIST = 'EEXIST'
6
-
7
- export const ENOTDIR = 'ENOTDIR'
8
-
9
- export const E_MANIFEST_NOT_FOUND = 'E_MANIFEST_NOT_FOUND'
10
-
11
- export const EPIPE = 'EPIPE'
12
-
13
- export const ERR_IPC_CHANNEL_CLOSED = 'ERR_IPC_CHANNEL_CLOSED'
14
-
15
1
  export const E_COLOR_THEME_NOT_FOUND = 'E_COLOR_THEME_NOT_FOUND'
16
-
17
2
  export const E_ICON_THEME_NOT_FOUND = 'E_ICON_THEME_NOT_FOUND'
18
-
3
+ export const E_MANIFEST_NOT_FOUND = 'E_MANIFEST_NOT_FOUND'
19
4
  export const ECONNRESET = 'ECONNRESET'
20
-
5
+ export const EEXIST = 'EEXIST'
6
+ export const ELOOP = 'ELOOP'
7
+ export const ENOENT = 'ENOENT'
8
+ export const ENOTDIR = 'ENOTDIR'
21
9
  export const EPERM = 'EPERM'
10
+ export const EPIPE = 'EPIPE'
11
+ export const ERR_IPC_CHANNEL_CLOSED = 'ERR_IPC_CHANNEL_CLOSED'
12
+ export const ERR_MODULE_NOT_FOUND = 'ERR_MODULE_NOT_FOUND'
13
+ export const EXDEV = 'EXDEV'
@@ -7,8 +7,8 @@ import { requiresSocket } from '../RequiresSocket/RequiresSocket.js'
7
7
  export const getResponse = async (message, handle) => {
8
8
  try {
9
9
  const result = requiresSocket(message.method)
10
- ? await Command.invoke(message.method, handle, ...message.params)
11
- : await Command.invoke(message.method, ...message.params)
10
+ ? await Command.execute(message.method, handle, ...message.params)
11
+ : await Command.execute(message.method, ...message.params)
12
12
 
13
13
  return {
14
14
  jsonrpc: JsonRpc.Version,
@@ -28,14 +28,14 @@ export const load = (moduleId) => {
28
28
  return import('../Preferences/Preferences.ipc.js')
29
29
  case ModuleId.RecentlyOpened:
30
30
  return import('../RecentlyOpened/RecentlyOpened.ipc.js')
31
- case ModuleId.Search:
32
- return import('../Search/Search.ipc.js')
33
31
  case ModuleId.SearchFile:
34
32
  return import('../SearchFile/SearchFile.ipc.js')
35
33
  case ModuleId.Terminal:
36
34
  return import('../Terminal/Terminal.ipc.js')
37
35
  case ModuleId.TextDocument:
38
36
  return import('../TextDocument/TextDocument.ipc.js')
37
+ case ModuleId.Search:
38
+ return import('../TextSearch/TextSearch.ipc.js')
39
39
  case ModuleId.WebSocketServer:
40
40
  return import('../WebSocketServer/WebSocketServer.ipc.js')
41
41
  case ModuleId.Workspace:
@@ -120,7 +120,7 @@ export const getModuleId = (commandId) => {
120
120
  return ModuleId.Preferences
121
121
  case 'RecentlyOpened.addPath':
122
122
  return ModuleId.RecentlyOpened
123
- case 'Search.search':
123
+ case 'TextSearch.search':
124
124
  return ModuleId.Search
125
125
  case 'SearchFile.searchFile':
126
126
  return ModuleId.SearchFile