ide на основе vs code · VibeGit
ide на основе vs code Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
krutaya-ide-na-osnove-vs-code / extensions / copilot / test / inline / multiFileEdit.stest.ts 482 строк · изменён 14 нояб., 04:52
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
import * as assert from 'assert' ;
import { CHAT_MODEL } from '../../src/platform/configuration/common/configurationService' ;
import { TestingServiceCollection } from '../../src/platform/test/node/services' ;
import { escapeRegExpCharacters } from '../../src/util/vs/base/common/strings' ;
import { URI } from '../../src/util/vs/base/common/uri' ;
import { Configuration, ssuite, stest } from '../base/stest' ;
import { assertContainsAllSnippets, assertCriteriaMetAsync, assertFileContent, assertJSON assertNoElidedCodeComments getFileContent getWorkspaceDiagnostics
EditTestStrategyPanel simulatePanelCodeMapper
assertInlineEdit assertInlineEditShape assertNoErrorOutcome assertQualifiedFile assertWorkspaceEdit fromFixture toFile
EditTestStrategy IScenario
strategy EditTestStrategyPanel
testingServiceCollection TestingServiceCollection
scenario IScenario
testingServiceCollection scenario strategy
strategy EditTestStrategyPanel variant model configurations Configuration
EditTestStrategy Edits
EditTestStrategy Edits
strategy variant model configurations
title location configurations
description language model testingServiceCollection
strategy testingServiceCollection
files
queries
file
selection
visibleRanges
query
outcome workspace accessor
outcome
assert outcome files length
utilsTs outcome files
assert utilsTs
telemetryFile outcome files
assert telemetryFile
assert accessor workspace d d kind length
outcome
description model testingServiceCollection
strategy testingServiceCollection
files
queries
file
selection
visibleRanges
query
outcome workspace accessor
assert
description language model testingServiceCollection
strategy testingServiceCollection
files
queries
file
selection
visibleRanges
query
outcome workspace accessor
outcome
assert accessor workspace length
assert outcome files length
file outcome files
content file
assert content
assert content
content
description language model testingServiceCollection
strategy testingServiceCollection
files
queries
file
selection
visibleRanges
query
outcome workspace accessor
outcome
assert accessor workspace d d kind length
assert outcome files length
file outcome files
content file
assert content
assert content
content
description language model testingServiceCollection
strategy testingServiceCollection
files
queries
file
selection
visibleRanges
query
outcome workspace accessor
outcome
assert accessor workspace d d kind length
assert outcome files length
file outcome files
content file
assert content
content
description language testingServiceCollection
strategy testingServiceCollection
files
queries
file
selection
visibleRanges
query
outcome workspace accessor
outcome
edit outcome
line
originalLength
modifiedLength
edit changedModifiedLines
assert
edit changedModifiedLines
outcome fileContents
description language model testingServiceCollection
strategy testingServiceCollection
files
queries
query
outcome workspace accessor
outcome
assert accessor workspace d d kind length
assert outcome files length
packageJson outcome files
extensionTs outcome files
packageJsonObj packageJson
assert packageJsonObj devDependencies
assert packageJsonObj dependencies
commands packageJsonObj contributes commands
assert commands
assert commands length
newCommand commands c command c command
assert newCommand
assert extensionTs
assert extensionTs
outcome
query
outcome workspace accessor
outcome
assert accessor workspace d d kind length
assert outcome files length
packageJson outcome files
extensionTs outcome files
packageJsonObj packageJson
assert packageJsonObj dependencies
assert packageJsonObj dependencies
commands packageJsonObj contributes commands
assert commands
assert commands length
newCommand commands c command c command
assert newCommand
assert extensionTs
outcome
stest description model testingServiceCollection
strategy testingServiceCollection
files
fileName fileContents
fileName fileContents
queries
query
outcome workspace accessor
outcome
d accessor workspace d d kind
assert d length
outcome
description language model testingServiceCollection
strategy testingServiceCollection
files
queries
query
outcome workspace accessor
outcome
assert accessor workspace d d kind length
assert outcome files length
fileSystemProviderTs outcome files
extensionTs outcome files
assert extensionTs
newIndex fileSystemProviderTs
assert newIndex
endOfMemFSIndex fileSystemProviderTs
assert endOfMemFSIndex
assert newIndex endOfMemFSIndex
assert fileSystemProviderTs
assert extensionTs
outcome
query
outcome workspace accessor
outcome
assert accessor workspace d d kind length
fileSystemProviderTs outcome files
extensionTs outcome files
utilsTs outcome files
assert fileSystemProviderTs
newIndex utilsTs
assert newIndex
assert utilsTs
assert extensionTs
assert extensionTs
outcome
query
outcome workspace accessor
outcome
assert accessor workspace d d kind length
utilsTs outcome files
assert utilsTs
assert utilsTs
outcome
description language model testingServiceCollection
strategy testingServiceCollection
files
queries
file
selection
query
outcome workspace accessor
outcome
assert outcome fileContents
outcome fileContents
description model testingServiceCollection
strategy testingServiceCollection
files
queries
file
selection
query
outcome workspace accessor
outcome
assert accessor workspace d d kind length
outcome fileContents
outcome fileContents
description model testingServiceCollection
strategy testingServiceCollection
files
queries
file
selection
query
outcome workspace accessor
outcome
accessor outcome chatResponseMarkdown
file
selection
query
outcome workspace accessor
outcome
accessor outcome chatResponseMarkdown
description model testingServiceCollection
strategy testingServiceCollection
files
queries
file
selection
query
outcome workspace accessor
outcome
outcome files
outcome
accessor outcome files
description model testingServiceCollection
strategy testingServiceCollection
files
queries
file
selection
query
outcome workspace accessor
outcome
outcome
outcome fileContents
description model testingServiceCollection
strategy testingServiceCollection
files
uri fileContents
queries
query
outcome workspace accessor
outcome
assert outcome files length
file outcome files
file
assert file uri
assert file fileContents
,
,
,
}
from
'../simulation/outcomeValidators'
;
import
{
,
}
from
'../simulation/panelCodeMapperSimulator'
;
import
{
,
,
,
,
,
,
}
from
'../simulation/stestUtil'
;
import
{
,
}
from
'../simulation/types'
;
function
executeEditTest
(
:
,
:
,
:
)
:
Promise
<
void
>
{
return
simulatePanelCodeMapper
(
,
,
)
;
}
function
forEditsAndAgent
(
callback
:
(
:
,
:
string
|
undefined
,
:
string
|
undefined
,
:
<
any
>
[
]
|
undefined
)
=>
void
)
:
void
{
callback
(
.
,
''
,
undefined
,
undefined
)
;
callback
(
.
,
'-claude'
,
CHAT_MODEL
.
CLAUDE_SONNET
,
undefined
)
;
}
forEditsAndAgent
(
(
,
,
,
)
=>
{
ssuite
(
{
:
` multifile-edit ${ variant} `
,
:
'panel'
,
}
,
(
)
=>
{
stest
(
{
:
'issue #8098: extract function to unseen file'
,
:
'typescript'
,
}
,
(
)
=>
{
return
executeEditTest
(
,
,
{
:
[
fromFixture
(
'multiFileEdit/issue-8098/debugUtils.ts'
)
,
fromFixture
(
'multiFileEdit/issue-8098/debugTelemetry.ts'
)
,
]
,
:
[
{
:
'debugUtils.ts'
,
:
[
34
,
0
,
34
,
0
]
,
:
[
[
3
,
0
,
44
,
0
]
]
,
:
'Extract filterExceptionsFromTelemetry to debugTelemetry #file:debugUtils.ts'
,
validate
:
async
(
,
,
)
=>
{
assertWorkspaceEdit
(
)
;
.
ok
(
.
.
===
2
,
'Expected two files to be edited'
)
;
const
=
assertFileContent
(
.
,
'debugUtils.ts'
)
;
.
ok
(
!
.
includes
(
'function filterExceptionsFromTelemetry'
)
,
'Expected filterExceptionsFromTelemetry to be extracted'
)
;
const
=
assertFileContent
(
.
,
'debugTelemetry.ts'
)
;
.
ok
(
.
includes
(
'filterExceptionsFromTelemetry'
)
,
'Expected filterExceptionsFromTelemetry to be extracted'
)
;
.
strictEqual
(
(
await
getWorkspaceDiagnostics
(
,
,
'tsc'
)
)
.
filter
(
=>
.
===
'syntactic'
)
.
,
0
)
;
assertNoElidedCodeComments
(
)
;
}
}
]
}
)
;
}
)
;
stest
(
{
:
'issue #8131: properly using dotenv in this file'
,
}
,
(
)
=>
{
return
executeEditTest
(
,
,
{
:
[
fromFixture
(
'multiFileEdit/issue-8131/extension.ts'
)
,
]
,
:
[
{
:
'extension.ts'
,
:
[
29
,
20
,
29
,
20
]
,
:
[
[
18
,
0
,
46
,
0
]
]
,
:
'#file:extension.ts Am I properly using dotenv in this file. The process.env.OPENAI_API_KEY keeps being undefined'
,
validate
:
async
(
,
,
)
=>
{
.
fail
(
'not implemented'
)
;
}
}
]
}
)
;
}
)
;
stest
(
{
:
'import new helper function'
,
:
'typescript'
,
}
,
(
)
=>
{
return
executeEditTest
(
,
,
{
:
[
fromFixture
(
'multiFileEdit/fibonacci/version1.ts'
)
,
fromFixture
(
'multiFileEdit/fibonacci/version2.ts'
)
,
fromFixture
(
'multiFileEdit/fibonacci/foo.ts'
)
,
fromFixture
(
'multiFileEdit/fibonacci/bar.ts'
)
,
]
,
:
[
{
:
'foo.ts'
,
:
[
0
,
0
,
4
,
0
]
,
:
[
[
9
,
0
,
4
,
0
]
]
,
:
'Update #file:foo.ts and #file:bar.ts to use the fibonacci function from #file:version2.ts instead of #file:version1.ts'
,
validate
:
async
(
,
,
)
=>
{
assertWorkspaceEdit
(
)
;
.
strictEqual
(
(
await
getWorkspaceDiagnostics
(
,
,
'tsc'
)
)
.
,
0
)
;
.
strictEqual
(
.
.
,
2
,
'Expected two files to be edited'
)
;
for
(
const
of
.
)
{
const
=
getFileContent
(
)
;
.
ok
(
.
includes
(
'./version2'
)
,
'Expected file to include updated import'
)
;
.
ok
(
!
.
includes
(
'./version1'
)
,
'Expected file to not include original import'
)
;
assertNoElidedCodeComments
(
)
;
}
}
}
]
}
)
;
}
)
;
stest
(
{
:
'change library used by two files'
,
:
'typescript'
,
}
,
(
)
=>
{
return
executeEditTest
(
,
,
{
:
[
fromFixture
(
'multiFileEdit/filepaths/1.ts'
)
,
fromFixture
(
'multiFileEdit/filepaths/2.ts'
)
,
]
,
:
[
{
:
'1.ts'
,
:
[
0
,
0
,
26
,
0
]
,
:
[
[
0
,
0
,
26
,
0
]
]
,
:
'Update #file:1.ts and #file:2.ts to replace usage of "path" with vscode apis'
,
validate
:
async
(
,
,
)
=>
{
assertWorkspaceEdit
(
)
;
.
strictEqual
(
(
await
getWorkspaceDiagnostics
(
,
,
'tsc'
)
)
.
filter
(
=>
.
===
'syntactic'
)
.
,
0
)
;
.
strictEqual
(
.
.
,
2
,
'Expected two files to be edited'
)
;
for
(
const
of
.
)
{
const
=
getFileContent
(
)
;
.
ok
(
!
.
includes
(
'path.join'
)
,
'Expected file to not include path usage'
)
;
.
ok
(
!
.
includes
(
'path.relative'
)
,
'Expected file to not include path usage'
)
;
assertNoElidedCodeComments
(
)
;
}
}
}
]
}
)
;
}
)
;
stest
(
{
:
'add validation logic to three files'
,
:
'typescript'
,
}
,
(
)
=>
{
return
executeEditTest
(
,
,
{
:
[
fromFixture
(
'multiFileEdit/filepaths/1.ts'
)
,
fromFixture
(
'multiFileEdit/filepaths/2.ts'
)
,
fromFixture
(
'multiFileEdit/filepaths/3.ts'
)
,
]
,
:
[
{
:
'1.ts'
,
:
[
0
,
0
,
26
,
0
]
,
:
[
[
0
,
0
,
26
,
0
]
]
,
:
'Throw an error if we see a "http" uri #file:1.ts #file:2.ts #file:3.ts'
,
validate
:
async
(
,
,
)
=>
{
assertWorkspaceEdit
(
)
;
.
strictEqual
(
(
await
getWorkspaceDiagnostics
(
,
,
'tsc'
)
)
.
filter
(
=>
.
===
'syntactic'
)
.
,
0
)
;
.
strictEqual
(
.
.
,
3
,
'Expected three files to be edited'
)
;
for
(
const
of
.
)
{
const
=
getFileContent
(
)
;
.
ok
(
.
includes
(
'throw new Error'
)
,
'Expected file to not include original import'
)
;
assertNoElidedCodeComments
(
)
;
}
}
}
]
}
)
;
}
)
;
stest
(
{
:
'does not delete code (big file) #15475'
,
:
'typescript'
}
,
(
)
=>
{
return
executeEditTest
(
,
,
{
:
[
fromFixture
(
'codeMapper/notebookEditorWidget.ts'
)
]
,
:
[
{
:
'notebookEditorWidget.ts'
,
:
[
497
,
0
,
501
,
0
]
,
:
[
[
480
,
0
,
520
,
0
]
]
,
:
'add return types for getSelections'
,
validate
:
async
(
,
,
)
=>
{
assertInlineEdit
(
)
;
const
=
assertInlineEditShape
(
,
{
:
497
,
:
2957
,
:
2957
,
}
)
;
assertContainsAllSnippets
(
.
.
join
(
'\n'
)
,
[
'getSelections(): ICellRange[] {'
]
,
'Edit not applied'
)
;
.
deepStrictEqual
(
.
.
join
(
'\n'
)
,
` getSelections(): ICellRange[] { `
,
'Unrelated edits applied'
)
;
assertNoElidedCodeComments
(
.
)
;
}
}
]
}
)
;
}
)
;
stest
(
{
:
'add a command and dependency to a VS Code extension'
,
:
'typescript'
,
}
,
(
)
=>
{
return
executeEditTest
(
,
,
{
:
[
fromFixture
(
'multiFileEdit/asciiart/package.json'
)
,
fromFixture
(
'multiFileEdit/asciiart/src/extension.ts'
)
,
]
,
:
[
{
:
[
` In #file:extension.ts add a new command 'Hello ASCII World' which shows an information dialog that displays 'hello world' as ASCII art. `
,
` You can use the 'ascii-art' node module to generate the string. `
,
` Please also update #file:package.json with the new command and the new dependency. `
]
.
join
(
' '
)
,
validate
:
async
(
,
,
)
=>
{
assertWorkspaceEdit
(
)
;
.
strictEqual
(
(
await
getWorkspaceDiagnostics
(
,
,
'tsc'
)
)
.
filter
(
=>
.
===
'syntactic'
)
.
,
0
)
;
.
strictEqual
(
.
.
,
2
,
'Expected two files to be edited'
)
;
const
=
assertFileContent
(
.
,
'package.json'
)
;
const
=
assertFileContent
(
.
,
'extension.ts'
)
;
const
=
assertJSON
(
)
;
.
ok
(
!
.
?.
[
'ascii-art'
]
,
'ascii-art dependency was added to devDependencies'
)
;
.
ok
(
.
?.
[
'ascii-art'
]
,
'Expected package.json to include ascii-art dependency'
)
;
const
=
.
.
;
.
ok
(
Array
.
isArray
(
)
,
'Expected package.json to include a commands array'
)
;
.
ok
(
.
===
2
,
'Expected package.json to include a new command'
)
;
const
=
.
find
(
(
:
{
:
string
}
)
=>
.
!==
'test-multifile-1.helloWorld'
)
;
.
ok
(
,
'Expected package.json to include a command other than helloWorld'
)
;
.
ok
(
.
match
(
/ \b import\b [ ^ ;\n ] + from [ '"] ascii-art[ '"] /
)
,
'Expected an import for ascii-art'
)
;
.
ok
(
.
match
(
new
RegExp
(
` \\bregisterCommand\\b[^;\n]['"] ${ escapeRegExpCharacters ( newCommand. command) } ['"] `
)
)
,
'expected that the new command is registered'
)
;
assertNoElidedCodeComments
(
)
;
}
}
,
{
:
[
` Better use figlet for creating the ascii art. Please remove the dependency on 'ascii-art'. `
,
]
.
join
(
' '
)
,
validate
:
async
(
,
,
)
=>
{
assertWorkspaceEdit
(
)
;
.
strictEqual
(
(
await
getWorkspaceDiagnostics
(
,
,
'tsc'
)
)
.
filter
(
=>
.
===
'syntactic'
)
.
,
0
)
;
.
strictEqual
(
.
.
,
2
,
'Expected two files to be edited'
)
;
const
=
assertFileContent
(
.
,
'package.json'
)
;
const
=
assertFileContent
(
.
,
'extension.ts'
)
;
const
=
assertJSON
(
)
;
.
ok
(
.
[
'figlet'
]
,
'Expected package.json to include figlet dependency'
)
;
.
ok
(
!
.
[
'ascii-art'
]
,
'Expected package.json no longer to contain the ascii-art dependency'
)
;
const
=
.
.
;
.
ok
(
Array
.
isArray
(
)
,
'Expected package.json to include a commands array'
)
;
.
ok
(
.
===
2
,
'Expected package.json to still include 2 command'
)
;
const
=
.
find
(
(
:
{
:
string
}
)
=>
.
!==
'test-multifile-1.helloWorld'
)
;
.
ok
(
,
'Expected package.json to include a command other than helloWorld'
)
;
.
ok
(
.
match
(
/ \b import\b [ ^ ;\n ] + from [ '"] figlet[ '"] /
)
,
'Expected an import for figlet'
)
;
assertNoElidedCodeComments
(
)
;
}
}
]
}
)
;
}
)
;
.
skip
(
{
:
'Issue #8336'
,
}
,
(
)
=>
{
return
executeEditTest
(
,
,
{
:
[
toFile
(
{
:
'roadmap-parser.ts'
,
:
` export interface ParseOptions {\n startLine?: string,\n endLine?: string\n};\n\nexport interface FilterOptions {\n markers?: string[],\n extractMatchingMarkers?: boolean\n};\n\nexport function filter(markdown: string, options?: ParseOptions & FilterOptions): string {\n return parse(markdown, options).filter(options).join();\n}\n\n\nexport class Marker {\n constructor(public label: string, public offset: number) { }\n\n public get length() {\n return this.label.length + 1;\n }\n}\n\nexport class Line {\n\n public static nonHeaderLevel(computedLevel: number): number {\n return computedLevel + 1000;\n }\n\n public static headerLevel(computedLevel: number) : number {\n return computedLevel;\n }\n\n\n public children: Line[] = [];\n public parent: Line | null = null;\n public isHeader: boolean = false;\n public level: number = Line.nonHeaderLevel(0);\n public markers: Marker[] = [];\n\n constructor(public markdown: string) {\n let count = -1;\n let iterator = {\n next: () => count === this.markdown.length ? undefined : this.markdown.charAt(++count),\n index: () => count\n }\n this.parse(iterator);\n };\n\n parse(i: { next: () => string | undefined, index: () => number }) {\n let c = i.next();\n\n // eat headers\n let hashes = 0;\n while ('#' === c) {\n hashes++;\n c = i.next();\n }\n if (hashes > 0) {\n this.isHeader = true;\n this.level = Line.headerLevel(hashes);\n return;\n }\n\n // eat spaces\n let spaces = 0;\n while (' ' === c) {\n spaces++;\n c = i.next();\n }\n\n if ('-' === c) {\n // isBullet === true, remember indentation\n this.level = Line.nonHeaderLevel(Math.floor(spaces / 3));\n c = i.next();\n }\n\n // skip spaces\n while (' ' === c) {\n c = i.next();\n }\n\n // skip check mark\n if ('[' === c) {\n c = i.next();\n while (']' === c || ' ' === c || 'x' === c || 'X' === c ) {\n c = i.next();\n }\n }\n\n // eat markers\n markers: while (':' === c) {\n const offset = i.index();\n const label = [];\n c = i.next();\n while (':' !== c) {\n label.push(c);\n c = i.next();\n if (c === undefined) {\n break markers;\n }\n }\n this.markers.push(new Marker(label.join(''), offset));\n c = i.next();\n while (' ' === c) {\n c = i.next();\n }\n }\n\n }\n\n add(line: Line): Line {\n this.children.push(line);\n return this;\n }\n\n matchesMarkers(markers: string[]): boolean {\n if (this.hasMarkers(markers)) {\n return true;\n }\n return this.children.some(c => c.matchesMarkers(markers));\n }\n\n hasMarkers(markers: string[]): boolean {\n return this.markers.filter(marker => markers.includes(marker.label)).length === markers.length;\n }\n\n sanitizedMarkdown(options: FilterOptions) {\n if (options.extractMatchingMarkers) {\n const markers = this.markers.sort((m1, m2) => m1.offset - m2.offset);\n let sanitized = '';\n let offset = 0;\n markers.forEach(m => {\n if (options.markers?.includes(m.label)) {\n let behindMarker = m.offset + m.length + 1;\n let c = this.markdown.charAt(behindMarker);\n while (c === ' ') {\n c = this.markdown.charAt(++behindMarker);\n }\n sanitized += this.markdown.substring(offset, behindMarker);\n offset = behindMarker;\n }\n });\n sanitized += this.markdown.substring(offset);\n return sanitized;\n }\n const markers = this.markers.sort((m1, m2) => m1.offset - m2.offset);\n let sanitized = '';\n let offset = 0;\n markers.forEach(m => {\n if (options.markers?.includes(m.label)) {\n let behindMarker = m.offset + m.length + 1;\n let c = this.markdown.charAt(behindMarker);\n while (c === ' ') {\n c = this.markdown.charAt(++behindMarker);\n }\n sanitized += this.markdown.substring(offset, m.offset);\n offset = behindMarker;\n }\n });\n sanitized += this.markdown.substring(offset);\n return sanitized;\n }\n return this.markdown;\n }\n\n isEmpty() : boolean {\n return this.markdown.length === 0;\n }\n}\n\nexport class LineTree {\n\n public lines: Line[] = []\n private lastAddition: Line | null = null;\n\n public add(line: Line) {\n if (this.lastAddition) {\n if (line.level > this.lastAddition.level) {\n line.parent = this.lastAddition;\n line.parent.add(line);\n } else if (line.level === this.lastAddition.level) {\n line.parent = this.lastAddition.parent;\n if (line.parent) {\n line.parent.add(line);\n } else {\n this.lines.push(line);\n }\n } else {\n let last: Line | null = this.lastAddition;\n while (last && line.level <= last.level) {\n last = last.parent;\n }\n if (last) {\n line.parent = last;\n line.parent.add(line);\n } else {\n this.lines.push(line);\n }\n }\n } else {\n this.lines.push(line);\n }\n this.lastAddition = line;\n }\n\n public filter(options?: FilterOptions): LineTree {\n if (options && options.markers) {\n const filteredTree = new LineTree();\n const filter = (lines: Line[]) => {\n lines.forEach(l => {\n if (l.matchesMarkers(options.markers!)) {\n filteredTree.add(l);\n }\n filter(l.children);\n });\n };\n filter(this.lines);\n return filteredTree;\n }\n return this;\n }\n\n public join(): string {\n const contents: string[] = [];\n const join = (lines: Line[]) => {\n lines.forEach(l => {\n contents.push(l.markdown);\n join(l.children);\n });\n };\n join(this.lines);\n return contents.join('\\n');\n }\n}\n\nexport function parse(markdown: string, options?: ParseOptions): LineTree {\n const tree = new LineTree();\n\n const input = markdown.split('\\n');\n let acceptLine = options?.startLine ? false : true;\n input.forEach(m => {\n if (options && options.startLine && options.endLine) {\n if (!acceptLine) {\n if (options.startLine === m.trim()) {\n acceptLine = true;\n }\n } else {\n if (options.endLine === m.trim()) {\n acceptLine = false;\n }\n }\n }\n if (acceptLine) {\n tree.add(new Line(m));\n }\n });\n\n return tree;\n} `
}
)
,
toFile
(
{
:
'roadmap.ts'
,
:
'import commandLineArgs from \'command-line-args\';\nimport { resolve, dirname } from \'path\'\nimport { readFileSync, writeFileSync, mkdirSync } from \'fs\';\nimport { filter } from \'./roadmap-parser\';\n\nconst optionDefinitions = [\n { name: \'scope\', type: String },\n { name: \'year\', type: String },\n { name: \'source\', type: String },\n { name: \'template\', type: String },\n { name: \'startLine\', type: String, defaultValue: \'<!-- BEGIN -->\' },\n { name: \'endLine\', type: String, defaultValue: \'<!-- END -->\' },\n { name: \'output\', type: String }\n];\n\ninterface Options {\n scope: string | undefined,\n year: string | undefined,\n source: string | undefined,\n template: string | undefined,\n startLine: string,\n endLine: string,\n output: string | undefined\n}\n\nconst options = commandLineArgs(optionDefinitions, { partial: true }) as Options\nif (!(options.source || options.year) || !options.source) {\n console.log(\n`\nroadmap {--scope <public|internal>} {--year <2021>} --source <perpetual roadmap> {--template <template roadmap to generate>} {--output <file name of the generated roadmap>}\n\nYou may also use \'--startLine <line content>\' and \'--endLine <line content>\' to specify\n- the section(s) of the source roadmap to extract and process\n- the section in the template that should be replaced.\n\nThe defaults are \'<!-- BEGIN -->\' for \'--startLine\' and \'<!-- END -->\' for \'--endLine\'.\n`\n );\n} else {\n\n const cwd = process.cwd();\n const source = resolve(cwd, options.source!);\n try {\n\n const markers: string[] = [];\n if (options.year) {\n markers.push(options.year);\n }\n if (options.scope) {\n markers.push(options.scope)\n }\n\n const rawInput = readFileSync(source);\n const filteredInput = filter(rawInput.toString(), { startLine: options.startLine, endLine: options.endLine, markers, extractMatchingMarkers: true });\n\n if (!options.template) {\n console.log(filteredInput);\n } else {\n\n const template = readFileSync(resolve(cwd, options.template!));\n const processedOutput = replace(template.toString(), filteredInput, options);\n\n if (!options.output) {\n console.log(processedOutput)\n } else {\n\n const outputFile = resolve(cwd, options.output!);\n mkdirSync(dirname(outputFile), { recursive: true });\n writeFileSync(outputFile, processedOutput);\n }\n }\n\n } catch (e) {\n console.error(e.message);\n }\n}\n\nfunction replace(source: string, replacement: string, options: Options): string {\n const replacementRangeStart = source.indexOf(options.startLine) + options.startLine.length;\n const replacementRangeEnd = source.indexOf(options.endLine);\n return `${source.substring(0, replacementRangeStart)}\\n${replacement}\\n${source.substring(replacementRangeEnd)}`;\n}\n'
}
)
,
]
,
:
[
{
:
'change the code so that rather than markers to remove it works with markers to survive #file:roadmap.ts #file:roadmap-parser.ts '
,
validate
:
async
(
,
,
)
=>
{
assertWorkspaceEdit
(
)
;
const
=
(
await
getWorkspaceDiagnostics
(
,
,
'tsc'
)
)
.
filter
(
=>
.
===
'syntactic'
)
;
.
strictEqual
(
.
,
0
)
;
assertNoElidedCodeComments
(
)
;
}
}
]
}
)
;
}
)
;
stest
(
{
:
'fs provider: move function from one file to another'
,
:
'typescript'
,
}
,
(
)
=>
{
return
executeEditTest
(
,
,
{
:
[
fromFixture
(
'multiFileEdit/fsprovider/package.json'
)
,
fromFixture
(
'multiFileEdit/fsprovider/src/extension.ts'
)
,
fromFixture
(
'multiFileEdit/fsprovider/src/fileSystemProvider.ts'
)
,
]
,
:
[
{
:
[
` In #file:extension.ts move the function 'randomData' to the end of #file:fileSystemProvider.ts . Make sure to update the imports in #file:extension.ts and to export the function at the new location `
,
]
.
join
(
' '
)
,
validate
:
async
(
,
,
)
=>
{
assertWorkspaceEdit
(
)
;
.
strictEqual
(
(
await
getWorkspaceDiagnostics
(
,
,
'tsc'
)
)
.
filter
(
=>
.
===
'syntactic'
)
.
,
0
)
;
.
strictEqual
(
.
.
,
2
,
'Expected two files to be edited'
)
;
const
=
assertFileContent
(
.
,
'fileSystemProvider.ts'
)
;
const
=
assertFileContent
(
.
,
'extension.ts'
)
;
.
ok
(
!
.
includes
(
'function randomData(lineCnt: number, lineLen = 155): Buffer'
)
,
'randomData still found in extension.ts'
)
;
const
=
.
indexOf
(
'function randomData(lineCnt: number, lineLen = 155): Buffer'
)
;
.
ok
(
!==
-
1
,
'randomData not found in fileSystemProvider.ts'
)
;
const
=
.
indexOf
(
'// end of MemFS'
)
;
.
ok
(
!==
-
1
,
` can no longer find the '// end of MemFS' comment in fileSystemProvider.ts `
)
;
.
ok
(
>
,
'randomData was not placed at the end of fileSystemProvider.ts'
)
;
.
ok
(
.
indexOf
(
'export function randomData'
)
!==
-
1
,
'randomData not exported in fileSystemProvider.ts'
)
;
.
ok
(
.
match
(
/ \b import {[ ^ }] + randomData[ ^ }] + } from '. \/ fileSystemProvider'/
)
,
'Expected an import for randomData in extension.ts'
)
;
assertNoElidedCodeComments
(
)
;
}
}
,
{
:
[
` Better move 'randomData in its own file: /Users/someone/Projects/proj01/utils.ts'. Don't forget to remove again randomData from #file:fileSystemProvider.ts `
,
]
.
join
(
' '
)
,
validate
:
async
(
,
,
)
=>
{
assertWorkspaceEdit
(
)
;
.
strictEqual
(
(
await
getWorkspaceDiagnostics
(
,
,
'tsc'
)
)
.
filter
(
=>
.
===
'syntactic'
)
.
,
0
)
;
const
=
assertFileContent
(
.
,
'fileSystemProvider.ts'
)
;
const
=
assertFileContent
(
.
,
'extension.ts'
)
;
const
=
assertFileContent
(
.
,
'utils.ts'
)
;
.
ok
(
!
.
includes
(
'function randomData(lineCnt: number, lineLen = 155): Buffer'
)
,
'randomData still found in fileSystemProviderTs.ts'
)
;
const
=
.
indexOf
(
'function randomData(lineCnt: number, lineLen = 155): Buffer'
)
;
.
ok
(
!==
-
1
,
'randomData not found in utilsTs.ts'
)
;
.
ok
(
.
indexOf
(
'export function randomData'
)
!==
-
1
,
'randomData not exported in fileSystemProvider.ts'
)
;
.
ok
(
.
match
(
/ \b import { MemFS } from '. \/ fileSystemProvider'/
)
,
'Expected only MemFs import from fileSystemProvider'
)
;
.
ok
(
.
match
(
/ \b import {[ ^ }] + randomData[ ^ }] + } from '. \/ utils'/
)
,
'Expected an import for randomData from utils'
)
;
assertNoElidedCodeComments
(
)
;
}
}
,
{
:
[
` Please add a copyright statement to the new file #file:utils.ts. You can use the same statement as for #file:fileSystemProvider.ts `
,
]
.
join
(
' '
)
,
validate
:
async
(
,
,
)
=>
{
assertWorkspaceEdit
(
)
;
.
strictEqual
(
(
await
getWorkspaceDiagnostics
(
,
,
'tsc'
)
)
.
filter
(
=>
.
===
'syntactic'
)
.
,
0
)
;
const
=
assertFileContent
(
.
,
'utils.ts'
)
;
.
ok
(
.
includes
(
'Copyright (c) Microsoft Corporation. All rights reserved.'
)
,
'copyright (c) Microsoft not found'
)
;
.
ok
(
.
includes
(
'Licensed under the MIT License. See License.txt in the project root for license information'
)
,
'Licensed under the MIT License not found'
)
;
assertNoElidedCodeComments
(
)
;
}
}
]
}
)
;
}
)
;
stest
(
{
:
'Issue #9647'
,
:
'typescript'
,
}
,
(
)
=>
{
return
executeEditTest
(
,
,
{
:
[
fromFixture
(
'multiFileEdit/issue-9647/.env'
)
,
]
,
:
[
{
:
'.env'
,
:
[
0
,
0
,
0
,
0
]
,
:
'Add OPENAI to .env'
,
validate
:
async
(
,
,
)
=>
{
assertInlineEdit
(
)
;
.
ok
(
.
.
includes
(
'OPENAI='
)
,
'Expected OPENAI to be added to .env'
)
;
assertNoElidedCodeComments
(
.
)
;
}
}
]
}
)
;
}
)
;
stest
(
{
:
'unicode string sequences'
,
}
,
(
)
=>
{
return
executeEditTest
(
,
,
{
:
[
fromFixture
(
'multiFile/unicode-string-sequences/example.js'
)
]
,
:
[
{
:
'example.js'
,
:
[
8
,
0
,
8
,
0
]
,
:
'Avoid recursion in fib '
,
validate
:
async
(
,
,
)
=>
{
assertInlineEdit
(
)
;
.
strictEqual
(
(
await
getWorkspaceDiagnostics
(
,
,
'tsc'
)
)
.
filter
(
=>
.
===
'syntactic'
)
.
,
0
)
;
assertContainsAllSnippets
(
.
,
[
'\\u002D'
,
'\\x2D'
]
)
;
assertNoElidedCodeComments
(
.
)
;
}
}
]
}
)
;
}
)
;
stest
(
{
:
'multiple questions'
,
}
,
(
)
=>
{
return
executeEditTest
(
,
,
{
:
[
fromFixture
(
'multiFile/multiple-questions/package.json'
)
]
,
:
[
{
:
'package.json'
,
:
[
13
,
77
,
13
,
77
]
,
:
'what is the latest version of typescript?'
,
validate
:
async
(
,
,
)
=>
{
assertNoErrorOutcome
(
)
;
await
assertCriteriaMetAsync
(
,
.
,
'Does the response answer the question what the latest version of typescript is?'
)
;
}
}
,
{
:
'package.json'
,
:
[
13
,
77
,
13
,
77
]
,
:
'What is the latest version of mocha?'
,
validate
:
async
(
,
,
)
=>
{
assertNoErrorOutcome
(
)
;
await
assertCriteriaMetAsync
(
,
.
,
'Does the response answer the question what the latest version of mocha is?'
)
;
}
}
]
}
)
;
}
)
;
stest
(
{
:
'create a README from two other files'
,
}
,
(
)
=>
{
return
executeEditTest
(
,
,
{
:
[
fromFixture
(
'multiFileEdit/readme-generation/.devcontainer/devcontainer.json'
)
,
fromFixture
(
'multiFileEdit/readme-generation/.devcontainer/post-install.sh'
)
]
,
:
[
{
:
'devcontainer.json'
,
:
[
0
,
0
,
0
,
0
]
,
:
'add a readme based on these files'
,
validate
:
async
(
,
,
)
=>
{
assertWorkspaceEdit
(
)
;
assertFileContent
(
.
,
'README.md'
)
;
assertNoElidedCodeComments
(
)
;
await
assertCriteriaMetAsync
(
,
getFileContent
(
.
[
0
]
)
,
'Does the content look like a Readme file, properly formatted, with multiple lines?'
)
;
}
}
]
}
)
;
}
)
;
stest
(
{
:
'multiple edits on the same file'
,
}
,
(
)
=>
{
return
executeEditTest
(
,
,
{
:
[
fromFixture
(
'multiFileEdit/two-edits/generate-command-ts.js'
)
,
]
,
:
[
{
:
'generate-command-ts.js'
,
:
[
0
,
0
,
0
,
0
]
,
:
[
` Replace all occurrences of 'generator.fs.copy' with a call to a top level function 'copy' that takes 'generator', 'extensionConfig', 'from' and 'to' as parameters. `
,
` Then do the same for 'generator.fs.copyTpl'. Do not emit the full solution in one go. Emit a code block for every change. `
,
]
.
join
(
''
)
,
validate
:
async
(
,
,
)
=>
{
assertInlineEdit
(
)
;
assertNoElidedCodeComments
(
)
;
assertContainsAllSnippets
(
.
,
[
'function copy(generator, extensionConfig, from, to) {'
,
'function copyTpl(generator, extensionConfig, from, to) {'
,
` copy(generator, extensionConfig, generator.templatePath(bundlerPath, 'vscode'), generator.destinationPath('.vscode')); `
,
` copyTpl(generator, extensionConfig, 'vsc-extension-quickstart.md', 'vsc-extension-quickstart.md'); `
]
)
;
}
}
]
}
)
;
}
)
;
stest
(
{
:
'work with untitled files'
,
}
,
(
)
=>
{
return
executeEditTest
(
,
,
{
:
[
toFile
(
{
:
URI
.
parse
(
'untitled:Untitled-1'
)
,
:
'Hello\n'
}
)
,
]
,
:
[
{
:
[
` In #file:Untitled-1 add a new line with the following content: 'World' `
,
]
.
join
(
' '
)
,
validate
:
async
(
,
,
)
=>
{
assertWorkspaceEdit
(
)
;
.
strictEqual
(
.
.
,
1
,
'Expected one file to be edited'
)
;
const
=
.
[
0
]
;
assertQualifiedFile
(
)
;
.
strictEqual
(
.
.
toString
(
)
,
'untitled:Untitled-1'
,
'Expected the URI to be unchanged'
)
;
.
strictEqual
(
.
,
'Hello\nWorld\n'
,
'Expected the file contents to be Hello\\nWorld'
)
;
}
}
,
]
}
)
;
}
)
;
}
)
;
}
)
;