@lvce-editor/shared-process 0.0.17 → 0.0.20
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/extensions/builtin.language-basics-typescript/README.md +14 -0
- package/extensions/builtin.language-basics-typescript/extension.json +12 -0
- package/extensions/builtin.language-basics-typescript/src/tokenizeTypeScript.js +551 -0
- package/package.json +4 -8
- package/src/parts/Command/Command.js +1 -1
- package/src/parts/ExtensionManagement/ExtensionManagement.js +6 -2
- package/src/parts/FileSystem/FileSystem.js +1 -2
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Language Basics TypeScript
|
|
2
|
+
|
|
3
|
+
## Contributing
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
git clone git@github.com:lvce-editor/language-basics-typescript.git &&
|
|
7
|
+
cd language-basics-typescript &&
|
|
8
|
+
npm ci &&
|
|
9
|
+
npm test
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Gitpod
|
|
13
|
+
|
|
14
|
+
[](https://gitpod.io/#https://github.com/lvce-editor/language-basics-typescript)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "builtin.language-basics-typescript",
|
|
3
|
+
"name": "Language Basics TypeScript",
|
|
4
|
+
"description": "Provides syntax highlighting and bracket matching in TypeScript files.",
|
|
5
|
+
"languages": [
|
|
6
|
+
{
|
|
7
|
+
"id": "typescript",
|
|
8
|
+
"extensions": [".ts"],
|
|
9
|
+
"tokenize": "src/tokenizeTypeScript.js"
|
|
10
|
+
}
|
|
11
|
+
]
|
|
12
|
+
}
|
|
@@ -0,0 +1,551 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @enum number
|
|
3
|
+
*/
|
|
4
|
+
const State = {
|
|
5
|
+
None: 0,
|
|
6
|
+
TopLevelContent: 1,
|
|
7
|
+
InsideSingleQuoteString: 2,
|
|
8
|
+
InsideDoubleQuoteString: 3,
|
|
9
|
+
AfterKeywordDeclaration: 4,
|
|
10
|
+
BeforeValue: 5,
|
|
11
|
+
AfterKeywordTypeDeclaration: 8,
|
|
12
|
+
BeforeType: 9,
|
|
13
|
+
AfterKeywordDeclare: 10,
|
|
14
|
+
InsideBlockComment: 11,
|
|
15
|
+
InsideLineComment: 12,
|
|
16
|
+
AfterKeywordClass: 13,
|
|
17
|
+
AfterKeywordClassAfterClassName: 14,
|
|
18
|
+
InsideClass: 15,
|
|
19
|
+
AfterType: 16,
|
|
20
|
+
InsideTypeExpression: 17,
|
|
21
|
+
AfterTypeExpression: 18,
|
|
22
|
+
AfterVariableName: 19,
|
|
23
|
+
BeforePropertyAccess: 20,
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @enum number
|
|
28
|
+
*/
|
|
29
|
+
export const TokenType = {
|
|
30
|
+
None: 99999999,
|
|
31
|
+
Keyword: 951,
|
|
32
|
+
Whitespace: 0,
|
|
33
|
+
NewLine: 771,
|
|
34
|
+
VariableName: 2,
|
|
35
|
+
Punctuation: 3,
|
|
36
|
+
String: 4,
|
|
37
|
+
Numeric: 5,
|
|
38
|
+
TypePrimitive: 6,
|
|
39
|
+
LanguageConstant: 7,
|
|
40
|
+
KeywordImport: 8,
|
|
41
|
+
KeywordControl: 9,
|
|
42
|
+
KeywordModifier: 10,
|
|
43
|
+
KeywordReturn: 11,
|
|
44
|
+
KeywordNew: 12,
|
|
45
|
+
Type: 13,
|
|
46
|
+
KeywordDeclare: 14,
|
|
47
|
+
Comment: 15,
|
|
48
|
+
Regex: 16,
|
|
49
|
+
Class: 17,
|
|
50
|
+
StorageModifier: 18,
|
|
51
|
+
KeywordVoid: 19,
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export const TokenMap = {
|
|
55
|
+
[TokenType.None]: 'None',
|
|
56
|
+
[TokenType.Keyword]: 'Keyword',
|
|
57
|
+
[TokenType.Whitespace]: 'Whitespace',
|
|
58
|
+
[TokenType.NewLine]: 'NewLine',
|
|
59
|
+
[TokenType.VariableName]: 'VariableName',
|
|
60
|
+
[TokenType.Punctuation]: 'Punctuation',
|
|
61
|
+
[TokenType.String]: 'String',
|
|
62
|
+
[TokenType.Numeric]: 'Numeric',
|
|
63
|
+
[TokenType.TypePrimitive]: 'TypePrimitive',
|
|
64
|
+
[TokenType.LanguageConstant]: 'LanguageConstant',
|
|
65
|
+
[TokenType.KeywordImport]: 'KeywordImport',
|
|
66
|
+
[TokenType.KeywordControl]: 'KeywordControl',
|
|
67
|
+
[TokenType.KeywordModifier]: 'KeywordModifier',
|
|
68
|
+
[TokenType.KeywordReturn]: 'KeywordReturn',
|
|
69
|
+
[TokenType.KeywordNew]: 'KeywordNew',
|
|
70
|
+
[TokenType.Type]: 'Type',
|
|
71
|
+
[TokenType.KeywordDeclare]: 'KeywordDeclare',
|
|
72
|
+
[TokenType.Comment]: 'Comment',
|
|
73
|
+
[TokenType.Regex]: 'Regex',
|
|
74
|
+
[TokenType.Class]: 'Class',
|
|
75
|
+
[TokenType.StorageModifier]: 'StorageModifier',
|
|
76
|
+
[TokenType.KeywordVoid]: 'KeywordVoid',
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export const initialLineState = {
|
|
80
|
+
state: State.TopLevelContent,
|
|
81
|
+
stack: [],
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const RE_KEYWORD =
|
|
85
|
+
/^(?: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|false|extends|export|enum|else|do|delete|default|debugger|declare|continue|const|class|catch|case|break|await)\b/
|
|
86
|
+
const RE_WHITESPACE = /^\s+/
|
|
87
|
+
const RE_VARIABLE_NAME = /^[\$a-zA-Z]+/
|
|
88
|
+
const RE_PUNCTUATION = /^[:,;\{\}\[\]\.=\(\)>\+]/
|
|
89
|
+
const RE_QUOTE_SINGLE = /^'/
|
|
90
|
+
const RE_QUOTE_DOUBLE = /^"/
|
|
91
|
+
const RE_STRING_SINGLE_QUOTE_CONTENT = /^[^']+/
|
|
92
|
+
const RE_STRING_DOUBLE_QUOTE_CONTENT = /^[^"]+/
|
|
93
|
+
const RE_NUMERIC = /^\d+/
|
|
94
|
+
const RE_COLON = /^\:/
|
|
95
|
+
const RE_TYPE_PRIMITIVE = /^(?:string|boolean|number|bigint|symbol|void|any)\b/
|
|
96
|
+
const RE_EQUAL = /^=/
|
|
97
|
+
const RE_SEMICOLON = /^;/
|
|
98
|
+
const RE_KEYWORD_CONST = /^(?:const)/
|
|
99
|
+
const RE_KEYWORD_LET = /^(?:let)/
|
|
100
|
+
const RE_KEYWORD_ENUM = /^(?:enum)/
|
|
101
|
+
const RE_KEYWORD_CLASS = /^(?:class)/
|
|
102
|
+
const RE_LINE_COMMENT_START = /^\/\//
|
|
103
|
+
const RE_LINE_COMMENT_CONTENT = /^[^\n]+/
|
|
104
|
+
const RE_NEWLINE_WHITESPACE = /^\n\s*/
|
|
105
|
+
const RE_BLOCK_COMMENT_START = /^\/\*/
|
|
106
|
+
const RE_BLOCK_COMMENT_CONTENT = /^.+?(?=\*\/)/
|
|
107
|
+
const RE_BLOCK_COMMENT_END = /^\*\//
|
|
108
|
+
const RE_SLASH = /^\//
|
|
109
|
+
// copied from https://github.com/PrismJS/prism/blob/master/components/prism-javascript.js#L57
|
|
110
|
+
const RE_REGEX =
|
|
111
|
+
/((?:^|[^$\w\xA0-\uFFFF."'\])\s]|\b(?:return|yield))\s*)\/(?:\[(?:[^\]\\\r\n]|\\.)*\]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/
|
|
112
|
+
const RE_ANYTHING_UNTIL_END = /^.+/s
|
|
113
|
+
const RE_CURLY_OPEN = /^\{/
|
|
114
|
+
const RE_CURLY_CLOSE = /^\}/
|
|
115
|
+
const RE_KEYWORD_CLASS_PROPERTY_MODIFIER =
|
|
116
|
+
/^(?:override|public|protected|private|readonly)\b/
|
|
117
|
+
const RE_VERTICAL_LINE = /^\|/
|
|
118
|
+
const RE_ROUND_OPEN = /^\(/
|
|
119
|
+
const RE_ROUND_CLOSE = /^\)/
|
|
120
|
+
const RE_QUESTION_MARK_COLON = /^\?\:/
|
|
121
|
+
const RE_ARROW = /^\=\>/
|
|
122
|
+
const RE_AMPERSAND = /^\&/
|
|
123
|
+
const RE_COMMA = /^\,/
|
|
124
|
+
const RE_DOT = /^\./
|
|
125
|
+
const RE_SQUARE_OPEN = /^\[/
|
|
126
|
+
const RE_SQUARE_CLOSE = /^\]/
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
*
|
|
130
|
+
* @param {string} line
|
|
131
|
+
* @param {object} lineState
|
|
132
|
+
* @returns
|
|
133
|
+
*/
|
|
134
|
+
export const tokenizeLine = (line, lineState) => {
|
|
135
|
+
let next = null
|
|
136
|
+
let index = 0
|
|
137
|
+
let tokens = []
|
|
138
|
+
let token = TokenType.None
|
|
139
|
+
let state = lineState.state
|
|
140
|
+
let stack = lineState.stack
|
|
141
|
+
while (index < line.length) {
|
|
142
|
+
const part = line.slice(index)
|
|
143
|
+
switch (state) {
|
|
144
|
+
case State.TopLevelContent:
|
|
145
|
+
if ((next = part.match(RE_WHITESPACE))) {
|
|
146
|
+
token = TokenType.Whitespace
|
|
147
|
+
state = State.TopLevelContent
|
|
148
|
+
} else if ((next = part.match(RE_KEYWORD))) {
|
|
149
|
+
next[0] //?
|
|
150
|
+
switch (next[0]) {
|
|
151
|
+
case 'true':
|
|
152
|
+
case 'false':
|
|
153
|
+
case 'null':
|
|
154
|
+
token = TokenType.LanguageConstant
|
|
155
|
+
state = State.TopLevelContent
|
|
156
|
+
break
|
|
157
|
+
case 'import':
|
|
158
|
+
case 'export':
|
|
159
|
+
case 'from':
|
|
160
|
+
token = TokenType.KeywordImport
|
|
161
|
+
state = State.TopLevelContent
|
|
162
|
+
break
|
|
163
|
+
case 'as':
|
|
164
|
+
case 'switch':
|
|
165
|
+
case 'default':
|
|
166
|
+
case 'case':
|
|
167
|
+
case 'else':
|
|
168
|
+
case 'if':
|
|
169
|
+
case 'break':
|
|
170
|
+
case 'throw':
|
|
171
|
+
token = TokenType.KeywordControl
|
|
172
|
+
state = State.TopLevelContent
|
|
173
|
+
break
|
|
174
|
+
case 'async':
|
|
175
|
+
case 'await':
|
|
176
|
+
token = TokenType.KeywordModifier
|
|
177
|
+
state = State.TopLevelContent
|
|
178
|
+
break
|
|
179
|
+
case 'return':
|
|
180
|
+
token = TokenType.KeywordReturn
|
|
181
|
+
state = State.TopLevelContent
|
|
182
|
+
break
|
|
183
|
+
case 'new':
|
|
184
|
+
token = TokenType.KeywordNew
|
|
185
|
+
state = State.TopLevelContent
|
|
186
|
+
break
|
|
187
|
+
case 'let':
|
|
188
|
+
case 'const':
|
|
189
|
+
token = TokenType.Keyword
|
|
190
|
+
state = State.AfterKeywordDeclaration
|
|
191
|
+
break
|
|
192
|
+
case 'type':
|
|
193
|
+
token = TokenType.Keyword
|
|
194
|
+
state = State.AfterKeywordTypeDeclaration
|
|
195
|
+
break
|
|
196
|
+
case 'declare':
|
|
197
|
+
token = TokenType.KeywordDeclare
|
|
198
|
+
state = State.AfterKeywordDeclare
|
|
199
|
+
break
|
|
200
|
+
case 'void':
|
|
201
|
+
token = TokenType.KeywordVoid
|
|
202
|
+
state = State.TopLevelContent
|
|
203
|
+
break
|
|
204
|
+
default:
|
|
205
|
+
token = TokenType.Keyword
|
|
206
|
+
state = State.TopLevelContent
|
|
207
|
+
break
|
|
208
|
+
}
|
|
209
|
+
} else if ((next = part.match(RE_VARIABLE_NAME))) {
|
|
210
|
+
token = TokenType.VariableName
|
|
211
|
+
state = State.TopLevelContent
|
|
212
|
+
} else if ((next = part.match(RE_PUNCTUATION))) {
|
|
213
|
+
token = TokenType.Punctuation
|
|
214
|
+
state = State.TopLevelContent
|
|
215
|
+
} else if ((next = part.match(RE_SLASH))) {
|
|
216
|
+
if ((next = part.match(RE_BLOCK_COMMENT_START))) {
|
|
217
|
+
token = TokenType.Comment
|
|
218
|
+
state = State.InsideBlockComment
|
|
219
|
+
} else if ((next = part.match(RE_REGEX))) {
|
|
220
|
+
token = TokenType.Regex
|
|
221
|
+
state = State.TopLevelContent
|
|
222
|
+
} else if ((next = part.match(RE_LINE_COMMENT_START))) {
|
|
223
|
+
token = TokenType.Comment
|
|
224
|
+
state = State.InsideLineComment
|
|
225
|
+
} else {
|
|
226
|
+
next = part.match(RE_PUNCTUATION)
|
|
227
|
+
token = TokenType.Punctuation
|
|
228
|
+
state = State.TopLevelContent
|
|
229
|
+
}
|
|
230
|
+
} else if ((next = part.match(RE_NUMERIC))) {
|
|
231
|
+
token = TokenType.Numeric
|
|
232
|
+
state = State.TopLevelContent
|
|
233
|
+
} else if ((next = part.match(RE_QUOTE_SINGLE))) {
|
|
234
|
+
token = TokenType.Punctuation
|
|
235
|
+
state = State.InsideSingleQuoteString
|
|
236
|
+
} else if ((next = part.match(RE_QUOTE_DOUBLE))) {
|
|
237
|
+
token = TokenType.Punctuation
|
|
238
|
+
state = State.InsideDoubleQuoteString
|
|
239
|
+
} else if ((next = part.match(RE_VERTICAL_LINE))) {
|
|
240
|
+
token = TokenType.Punctuation
|
|
241
|
+
state = State.TopLevelContent
|
|
242
|
+
} else {
|
|
243
|
+
part //?
|
|
244
|
+
throw new Error('no')
|
|
245
|
+
}
|
|
246
|
+
break
|
|
247
|
+
case State.InsideSingleQuoteString:
|
|
248
|
+
if ((next = part.match(RE_QUOTE_SINGLE))) {
|
|
249
|
+
token = TokenType.Punctuation
|
|
250
|
+
state = State.TopLevelContent
|
|
251
|
+
} else if ((next = part.match(RE_STRING_SINGLE_QUOTE_CONTENT))) {
|
|
252
|
+
token = TokenType.String
|
|
253
|
+
state = State.InsideSingleQuoteString
|
|
254
|
+
} else {
|
|
255
|
+
throw new Error('no')
|
|
256
|
+
}
|
|
257
|
+
break
|
|
258
|
+
case State.InsideDoubleQuoteString:
|
|
259
|
+
if ((next = part.match(RE_QUOTE_DOUBLE))) {
|
|
260
|
+
token = TokenType.Punctuation
|
|
261
|
+
state = State.TopLevelContent
|
|
262
|
+
} else if ((next = part.match(RE_STRING_DOUBLE_QUOTE_CONTENT))) {
|
|
263
|
+
token = TokenType.String
|
|
264
|
+
state = State.InsideDoubleQuoteString
|
|
265
|
+
} else {
|
|
266
|
+
throw new Error('no')
|
|
267
|
+
}
|
|
268
|
+
break
|
|
269
|
+
case State.AfterKeywordDeclaration:
|
|
270
|
+
if ((next = part.match(RE_WHITESPACE))) {
|
|
271
|
+
token = TokenType.Whitespace
|
|
272
|
+
state = State.AfterKeywordDeclaration
|
|
273
|
+
} else if ((next = part.match(RE_COLON))) {
|
|
274
|
+
token = TokenType.Punctuation
|
|
275
|
+
state = State.BeforeType
|
|
276
|
+
} else if ((next = part.match(RE_VARIABLE_NAME))) {
|
|
277
|
+
token = TokenType.VariableName
|
|
278
|
+
state = State.AfterKeywordDeclaration
|
|
279
|
+
} else if ((next = part.match(RE_EQUAL))) {
|
|
280
|
+
token = TokenType.Punctuation
|
|
281
|
+
state = State.TopLevelContent
|
|
282
|
+
} else {
|
|
283
|
+
part
|
|
284
|
+
throw new Error('no')
|
|
285
|
+
}
|
|
286
|
+
break
|
|
287
|
+
|
|
288
|
+
case State.AfterKeywordTypeDeclaration:
|
|
289
|
+
if ((next = part.match(RE_WHITESPACE))) {
|
|
290
|
+
token = TokenType.Whitespace
|
|
291
|
+
state = State.AfterKeywordTypeDeclaration
|
|
292
|
+
} else if ((next = part.match(RE_VARIABLE_NAME))) {
|
|
293
|
+
token = TokenType.Type
|
|
294
|
+
state = State.AfterKeywordTypeDeclaration
|
|
295
|
+
} else if ((next = part.match(RE_EQUAL))) {
|
|
296
|
+
token = TokenType.Punctuation
|
|
297
|
+
state = State.BeforeType
|
|
298
|
+
} else {
|
|
299
|
+
part
|
|
300
|
+
throw new Error('no')
|
|
301
|
+
}
|
|
302
|
+
break
|
|
303
|
+
case State.BeforeType:
|
|
304
|
+
part
|
|
305
|
+
if ((next = part.match(RE_WHITESPACE))) {
|
|
306
|
+
token = TokenType.Whitespace
|
|
307
|
+
state = State.BeforeType
|
|
308
|
+
} else if ((next = part.match(RE_TYPE_PRIMITIVE))) {
|
|
309
|
+
part
|
|
310
|
+
token = TokenType.TypePrimitive
|
|
311
|
+
state = State.AfterType
|
|
312
|
+
} else if ((next = part.match(RE_VARIABLE_NAME))) {
|
|
313
|
+
part
|
|
314
|
+
token = TokenType.Type
|
|
315
|
+
state = State.AfterType
|
|
316
|
+
} else if ((next = part.match(RE_SEMICOLON))) {
|
|
317
|
+
token = TokenType.Punctuation
|
|
318
|
+
state = stack.pop() || State.TopLevelContent
|
|
319
|
+
} else if ((next = part.match(RE_ROUND_OPEN))) {
|
|
320
|
+
token = TokenType.Punctuation
|
|
321
|
+
state = State.InsideTypeExpression
|
|
322
|
+
} else if ((next = part.match(RE_ARROW))) {
|
|
323
|
+
token = TokenType.Punctuation
|
|
324
|
+
state = State.BeforeType
|
|
325
|
+
} else if ((next = part.match(RE_ROUND_CLOSE))) {
|
|
326
|
+
token = TokenType.Punctuation
|
|
327
|
+
state = State.TopLevelContent
|
|
328
|
+
} else if ((next = part.match(RE_COLON))) {
|
|
329
|
+
token = TokenType.Punctuation
|
|
330
|
+
state = State.BeforeType
|
|
331
|
+
} else if ((next = part.match(RE_NUMERIC))) {
|
|
332
|
+
token = TokenType.Numeric
|
|
333
|
+
state = State.AfterType
|
|
334
|
+
} else {
|
|
335
|
+
part
|
|
336
|
+
throw new Error('no')
|
|
337
|
+
}
|
|
338
|
+
break
|
|
339
|
+
case State.InsideTypeExpression:
|
|
340
|
+
part
|
|
341
|
+
if ((next = part.match(RE_ROUND_CLOSE))) {
|
|
342
|
+
token = TokenType.Punctuation
|
|
343
|
+
state = State.AfterTypeExpression
|
|
344
|
+
} else if ((next = part.match(RE_VARIABLE_NAME))) {
|
|
345
|
+
token = TokenType.VariableName
|
|
346
|
+
state = State.AfterVariableName
|
|
347
|
+
stack.push(State.InsideTypeExpression)
|
|
348
|
+
} else if ((next = part.match(RE_WHITESPACE))) {
|
|
349
|
+
token = TokenType.Whitespace
|
|
350
|
+
state = State.InsideTypeExpression
|
|
351
|
+
} else {
|
|
352
|
+
throw new Error('no')
|
|
353
|
+
}
|
|
354
|
+
break
|
|
355
|
+
case State.AfterTypeExpression:
|
|
356
|
+
if ((next = part.match(RE_SEMICOLON))) {
|
|
357
|
+
token = TokenType.Punctuation
|
|
358
|
+
state = State.TopLevelContent
|
|
359
|
+
} else if ((next = part.match(RE_ARROW))) {
|
|
360
|
+
token = TokenType.Punctuation
|
|
361
|
+
state = State.BeforeType
|
|
362
|
+
} else if ((next = part.match(RE_WHITESPACE))) {
|
|
363
|
+
token = TokenType.Whitespace
|
|
364
|
+
state = State.AfterTypeExpression
|
|
365
|
+
} else {
|
|
366
|
+
part
|
|
367
|
+
throw new Error('no')
|
|
368
|
+
}
|
|
369
|
+
break
|
|
370
|
+
case State.AfterVariableName:
|
|
371
|
+
if ((next = part.match(RE_COLON))) {
|
|
372
|
+
token = TokenType.Punctuation
|
|
373
|
+
state = State.BeforeType
|
|
374
|
+
} else if ((next = part.match(RE_WHITESPACE))) {
|
|
375
|
+
token = TokenType.Whitespace
|
|
376
|
+
state = State.AfterVariableName
|
|
377
|
+
} else if ((next = part.match(RE_AMPERSAND))) {
|
|
378
|
+
token = TokenType.Punctuation
|
|
379
|
+
state = State.TopLevelContent
|
|
380
|
+
} else if ((next = part.match(RE_QUESTION_MARK_COLON))) {
|
|
381
|
+
token = TokenType.Punctuation
|
|
382
|
+
state = State.BeforeType
|
|
383
|
+
} else if ((next = part.match(RE_CURLY_OPEN))) {
|
|
384
|
+
token = TokenType.Punctuation
|
|
385
|
+
state = State.TopLevelContent
|
|
386
|
+
} else {
|
|
387
|
+
tokens
|
|
388
|
+
part
|
|
389
|
+
throw new Error('no')
|
|
390
|
+
}
|
|
391
|
+
break
|
|
392
|
+
case State.AfterType:
|
|
393
|
+
part
|
|
394
|
+
if ((next = part.match(RE_SEMICOLON))) {
|
|
395
|
+
token = TokenType.Punctuation
|
|
396
|
+
state = stack.pop() || State.TopLevelContent
|
|
397
|
+
} else if ((next = part.match(RE_WHITESPACE))) {
|
|
398
|
+
token = TokenType.Whitespace
|
|
399
|
+
state = State.AfterType
|
|
400
|
+
} else if ((next = part.match(RE_EQUAL))) {
|
|
401
|
+
token = TokenType.Punctuation
|
|
402
|
+
state = State.TopLevelContent
|
|
403
|
+
} else if ((next = part.match(RE_QUESTION_MARK_COLON))) {
|
|
404
|
+
next
|
|
405
|
+
token = TokenType.Punctuation
|
|
406
|
+
state = State.BeforeType
|
|
407
|
+
} else if ((next = part.match(RE_COLON))) {
|
|
408
|
+
token = TokenType.Punctuation
|
|
409
|
+
state = State.BeforeType
|
|
410
|
+
} else if ((next = part.match(RE_ROUND_CLOSE))) {
|
|
411
|
+
token = TokenType.Punctuation
|
|
412
|
+
state = State.BeforeType
|
|
413
|
+
} else if ((next = part.match(RE_COMMA))) {
|
|
414
|
+
token = TokenType.Punctuation
|
|
415
|
+
state = stack.pop() || State.TopLevelContent
|
|
416
|
+
} else if ((next = part.match(RE_DOT))) {
|
|
417
|
+
token = TokenType.Punctuation
|
|
418
|
+
state = State.BeforePropertyAccess
|
|
419
|
+
} else if ((next = part.match(RE_SQUARE_OPEN))) {
|
|
420
|
+
token = TokenType.Punctuation
|
|
421
|
+
state = State.AfterType
|
|
422
|
+
} else if ((next = part.match(RE_SQUARE_CLOSE))) {
|
|
423
|
+
token = TokenType.Punctuation
|
|
424
|
+
state = State.AfterType
|
|
425
|
+
} else {
|
|
426
|
+
// stack.push(State.AfterType)
|
|
427
|
+
part
|
|
428
|
+
throw new Error('no')
|
|
429
|
+
}
|
|
430
|
+
break
|
|
431
|
+
case State.AfterKeywordDeclare:
|
|
432
|
+
part
|
|
433
|
+
if ((next = part.match(RE_WHITESPACE))) {
|
|
434
|
+
token = TokenType.Whitespace
|
|
435
|
+
state = State.AfterKeywordDeclare
|
|
436
|
+
} else if ((next = part.match(RE_KEYWORD_CONST))) {
|
|
437
|
+
token = TokenType.Keyword
|
|
438
|
+
state = State.AfterKeywordDeclare
|
|
439
|
+
} else if ((next = part.match(RE_KEYWORD_LET))) {
|
|
440
|
+
token = TokenType.Keyword
|
|
441
|
+
state = State.AfterKeywordDeclare
|
|
442
|
+
} else if ((next = part.match(RE_KEYWORD_ENUM))) {
|
|
443
|
+
token = TokenType.Keyword
|
|
444
|
+
state = State.AfterKeywordDeclare
|
|
445
|
+
} else if ((next = part.match(RE_KEYWORD_CLASS))) {
|
|
446
|
+
token = TokenType.Keyword
|
|
447
|
+
state = State.AfterKeywordClass
|
|
448
|
+
} else if ((next = part.match(RE_VARIABLE_NAME))) {
|
|
449
|
+
token = TokenType.Type
|
|
450
|
+
state = State.AfterVariableName
|
|
451
|
+
} else {
|
|
452
|
+
part
|
|
453
|
+
throw new Error('no')
|
|
454
|
+
}
|
|
455
|
+
break
|
|
456
|
+
case State.InsideLineComment:
|
|
457
|
+
if ((next = part.match(RE_ANYTHING_UNTIL_END))) {
|
|
458
|
+
token = TokenType.Comment
|
|
459
|
+
state = State.TopLevelContent
|
|
460
|
+
} else {
|
|
461
|
+
throw new Error('no')
|
|
462
|
+
}
|
|
463
|
+
break
|
|
464
|
+
case State.InsideBlockComment:
|
|
465
|
+
if ((next = part.match(RE_BLOCK_COMMENT_CONTENT))) {
|
|
466
|
+
token = TokenType.Comment
|
|
467
|
+
state = State.InsideBlockComment
|
|
468
|
+
} else if ((next = part.match(RE_BLOCK_COMMENT_END))) {
|
|
469
|
+
token = TokenType.Comment
|
|
470
|
+
state = State.TopLevelContent
|
|
471
|
+
} else if ((next = part.match(RE_ANYTHING_UNTIL_END))) {
|
|
472
|
+
token = TokenType.Comment
|
|
473
|
+
state = State.InsideBlockComment
|
|
474
|
+
} else {
|
|
475
|
+
throw new Error('no')
|
|
476
|
+
}
|
|
477
|
+
break
|
|
478
|
+
case State.BeforePropertyAccess:
|
|
479
|
+
if ((next = part.match(RE_VARIABLE_NAME))) {
|
|
480
|
+
token = TokenType.VariableName
|
|
481
|
+
state = stack.pop() || State.TopLevelContent
|
|
482
|
+
} else {
|
|
483
|
+
throw new Error('no')
|
|
484
|
+
}
|
|
485
|
+
break
|
|
486
|
+
case State.AfterKeywordClass:
|
|
487
|
+
if ((next = part.match(RE_WHITESPACE))) {
|
|
488
|
+
token = TokenType.Whitespace
|
|
489
|
+
state = State.AfterKeywordClass
|
|
490
|
+
} else if ((next = part.match(RE_VARIABLE_NAME))) {
|
|
491
|
+
token = TokenType.Class
|
|
492
|
+
state = State.AfterKeywordClassAfterClassName
|
|
493
|
+
} else {
|
|
494
|
+
part
|
|
495
|
+
throw new Error('no')
|
|
496
|
+
}
|
|
497
|
+
break
|
|
498
|
+
case State.AfterKeywordClassAfterClassName:
|
|
499
|
+
if ((next = part.match(RE_WHITESPACE))) {
|
|
500
|
+
token = TokenType.Whitespace
|
|
501
|
+
state = State.AfterKeywordClassAfterClassName
|
|
502
|
+
} else if ((next = part.match(RE_CURLY_OPEN))) {
|
|
503
|
+
token = TokenType.Punctuation
|
|
504
|
+
state = State.InsideClass
|
|
505
|
+
} else {
|
|
506
|
+
throw new Error('no')
|
|
507
|
+
}
|
|
508
|
+
break
|
|
509
|
+
case State.InsideClass:
|
|
510
|
+
if ((next = part.match(RE_WHITESPACE))) {
|
|
511
|
+
token = TokenType.Whitespace
|
|
512
|
+
state = State.InsideClass
|
|
513
|
+
} else if ((next = part.match(RE_KEYWORD_CLASS_PROPERTY_MODIFIER))) {
|
|
514
|
+
token = TokenType.StorageModifier
|
|
515
|
+
state = State.InsideClass
|
|
516
|
+
} else if ((next = part.match(RE_VARIABLE_NAME))) {
|
|
517
|
+
token = TokenType.VariableName
|
|
518
|
+
state = State.InsideClass
|
|
519
|
+
} else if ((next = part.match(RE_COLON))) {
|
|
520
|
+
stack.push(state)
|
|
521
|
+
token = TokenType.Punctuation
|
|
522
|
+
state = State.BeforeType
|
|
523
|
+
} else if ((next = part.match(RE_CURLY_CLOSE))) {
|
|
524
|
+
stack
|
|
525
|
+
token = TokenType.Punctuation
|
|
526
|
+
state = stack.pop() || State.TopLevelContent
|
|
527
|
+
} else {
|
|
528
|
+
part
|
|
529
|
+
throw new Error('no')
|
|
530
|
+
}
|
|
531
|
+
break
|
|
532
|
+
default:
|
|
533
|
+
state
|
|
534
|
+
throw new Error('no')
|
|
535
|
+
}
|
|
536
|
+
index += next[0].length
|
|
537
|
+
tokens.push({
|
|
538
|
+
type: token,
|
|
539
|
+
length: next[0].length,
|
|
540
|
+
})
|
|
541
|
+
}
|
|
542
|
+
if (state === State.AfterType && stack[0] === State.InsideClass) {
|
|
543
|
+
state = State.InsideClass
|
|
544
|
+
stack.pop()
|
|
545
|
+
}
|
|
546
|
+
return {
|
|
547
|
+
state,
|
|
548
|
+
stack,
|
|
549
|
+
tokens,
|
|
550
|
+
}
|
|
551
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/shared-process",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.20",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -17,7 +17,6 @@
|
|
|
17
17
|
"debug": "^4.3.4",
|
|
18
18
|
"execa": "^6.1.0",
|
|
19
19
|
"exit-hook": "^3.0.0",
|
|
20
|
-
"fs-extra": "^10.1.0",
|
|
21
20
|
"got": "^12.1.0",
|
|
22
21
|
"is-object": "^1.0.2",
|
|
23
22
|
"json-parse-even-better-errors": "^2.3.1",
|
|
@@ -32,8 +31,8 @@
|
|
|
32
31
|
"verror": "^1.10.1",
|
|
33
32
|
"ws": "^8.8.0",
|
|
34
33
|
"xdg-basedir": "^5.1.0",
|
|
35
|
-
"@lvce-editor/pty-host": "0.0.
|
|
36
|
-
"@lvce-editor/extension-host": "0.0.
|
|
34
|
+
"@lvce-editor/pty-host": "0.0.20",
|
|
35
|
+
"@lvce-editor/extension-host": "0.0.20"
|
|
37
36
|
},
|
|
38
37
|
"optionalDependencies": {
|
|
39
38
|
"electron-clipboard-ex": "^1.3.3",
|
|
@@ -42,15 +41,12 @@
|
|
|
42
41
|
},
|
|
43
42
|
"devDependencies": {
|
|
44
43
|
"@types/debug": "^4.1.7",
|
|
45
|
-
"@types/fs-extra": "^9.0.13",
|
|
46
|
-
"@types/is-ci": "^3.0.0",
|
|
47
44
|
"@types/is-object": "^1.0.2",
|
|
48
45
|
"@types/tail": "^2.2.1",
|
|
49
46
|
"@types/tar-fs": "^2.0.1",
|
|
50
47
|
"@types/verror": "^1.10.5",
|
|
51
48
|
"@types/ws": "^8.5.3",
|
|
52
|
-
"get-port": "^6.1.2"
|
|
53
|
-
"is-ci": "^3.0.1"
|
|
49
|
+
"get-port": "^6.1.2"
|
|
54
50
|
},
|
|
55
51
|
"xo": {
|
|
56
52
|
"rules": {
|
|
@@ -231,7 +231,7 @@ export const invoke = async (command, ...args) => {
|
|
|
231
231
|
await loadCommand(command)
|
|
232
232
|
if (!(command in commands)) {
|
|
233
233
|
console.warn(`[shared process] Unknown command "${command}"`)
|
|
234
|
-
|
|
234
|
+
throw new Error(`Command ${command} not found`)
|
|
235
235
|
}
|
|
236
236
|
}
|
|
237
237
|
if (typeof commands[command] !== 'function') {
|
|
@@ -8,13 +8,17 @@ import * as ReadJson from '../JsonFile/JsonFile.js'
|
|
|
8
8
|
import * as Path from '../Path/Path.js'
|
|
9
9
|
import * as Platform from '../Platform/Platform.js'
|
|
10
10
|
import * as Queue from '../Queue/Queue.js'
|
|
11
|
+
import path from 'node:path'
|
|
11
12
|
|
|
12
13
|
export const state = {
|
|
13
14
|
async getExtensions() {
|
|
15
|
+
// TODO only read from env once
|
|
16
|
+
const builtinExtensions = await getBuiltinExtensions()
|
|
14
17
|
if (process.env.ONLY_EXTENSION) {
|
|
15
|
-
|
|
18
|
+
const absolutePath = path.resolve(process.env.ONLY_EXTENSION)
|
|
19
|
+
const onlyExtension = await getExtensionManifests([absolutePath])
|
|
20
|
+
return [...builtinExtensions, ...onlyExtension]
|
|
16
21
|
}
|
|
17
|
-
const builtinExtensions = await getBuiltinExtensions()
|
|
18
22
|
const installedExtensions = await getInstalledExtensions()
|
|
19
23
|
return [...builtinExtensions, ...installedExtensions]
|
|
20
24
|
},
|
|
@@ -12,9 +12,8 @@ export const state = {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export const copy = async (source, target) => {
|
|
15
|
-
const { copy } = await import('fs-extra')
|
|
16
15
|
try {
|
|
17
|
-
await
|
|
16
|
+
await fs.cp(source, target, { recursive: true })
|
|
18
17
|
} catch (error) {
|
|
19
18
|
throw new Error.OperationalError({
|
|
20
19
|
cause: error,
|