ide на основе vs code · VibeGit
ide на основе vs code Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
krutaya-ide-na-osnove-vs-code / extensions / copilot / src / extension / tools / test / node / applyPatch / parser.spec.ts 635 строк · изменён 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
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
import * as fs from 'fs/promises' ;
import * as os from 'os' ;
import * as path from 'path' ;
import { expect, it, suite } from 'vitest' ;
import { StringTextDocumentWithLanguageId } from '../../../../../platform/editing/common/abstractText' ;
import { findLast } from '../../../../../util/vs/base/common/arraysFind' ;
import { URI } from '../../../../../util/vs/base/common/uri' ;
import { patch_to_commit replace_explicit_tabs text_to_patch
input
input
input
input
actions
chunks
delLines
insLines
origIndex
delLines
insLines
origIndex
type
input
input
input
input
input
input
actions
chunks
delLines
insLines
origIndex
delLines
insLines
origIndex
type
input
input
input
input
actions
chunks
delLines
insLines
origIndex
delLines
insLines
origIndex
type
input
input
actions
chunks
delLines
insLines
origIndex
type
input
input
input
input
input
input
input fs
patchFmt fs
patch patchFmt
docs
input
parsed patch docs
commit parsed docs
Object commit changes newContent
input fs
patch fs
docs
input
parsed patch docs
commit parsed docs
Object commit changes newContent
input fs
patchFmt fs
patchFmt patchFmt
expectedOutput fs
docs
input
parsed patchFmt docs
commit parsed docs
actualOutput Object commit changes newContent
actualOutput expectedOutput
input fs
patchFmt fs
patchFmt patchFmt
expectedOutput fs
docs
input
parsed patchFmt docs
commit parsed docs
actualOutput Object commit changes newContent
actualOutput expectedOutput
input fs
patchFmt fs
patchFmt patchFmt
expectedOutput fs
docs
input
parsed patchFmt docs
commit parsed docs
actualOutput Object commit changes newContent
actualOutput expectedOutput
corpusPath path __dirname
patches fs corpusPath f f
patchFile patches
patchContent fs path corpusPath patchFile
patch original expected fpath docs patchContent
inputDocs Record StringTextDocumentWithLanguageId
original fpath
inputDocs fpath original
uri text Object docs
inputDocs uri path text
parsed patch inputDocs
expected
commit parsed inputDocs
commit changes fpath newContent expected
e
patch
originalsPath path os patchFile
fs originalsPath Object inputDocs uri doc
e
it
filesSampled
maxEditsPerFile
contextLines
min max Math Math max min min
src path __dirname
allFiles
file fs cwd src
allFiles path src file
fs corpusPath recursive
caseNo
i i filesSampled i
file allFiles allFiles length
content fs file
lines content
lines length
i
fpath path src file
patch
linesToModify
i maxEditsPerFile linesToModify length i
r lines length
linesToModify r
linesToModify r
linesToModify a b a b
modified
wasEmittingContext
ln ln lines length ln
nextToModify linesToModify l l ln
prevModified linesToModify l l ln
emitContext
nextToModify nextToModify ln contextLines
prevModified ln prevModified contextLines
emitContext wasEmittingContext
ln
patch
currentIndent lines ln
contextLine currentIndent lines i i currentIndent ln
contextLine
patch
patch
wasEmittingContext emitContext
prevModified ln
insertText
modified insertText lines ln
patch lines ln
patch
newText
patch
patch
modified newText
modified lines ln
emitContext
patch
patch
fs
path __dirname
patch patch original content expected modified fpath
,
,
}
from
'../../../node/applyPatch/parser'
;
suite
(
'applyPatch parser'
,
(
)
=>
{
it
(
'replace_explicit_tabs'
,
(
)
=>
{
expect
(
replace_explicit_tabs
(
''
)
)
.
toBe
(
''
)
;
expect
(
replace_explicit_tabs
(
'foo'
)
)
.
toBe
(
'foo'
)
;
expect
(
replace_explicit_tabs
(
'\\tfoo'
)
)
.
toBe
(
'\tfoo'
)
;
expect
(
replace_explicit_tabs
(
' \\tfoo'
)
)
.
toBe
(
' \tfoo'
)
;
expect
(
replace_explicit_tabs
(
'\\t\\tfoo'
)
)
.
toBe
(
'\t\tfoo'
)
;
expect
(
replace_explicit_tabs
(
'\\tfoo\\tbar'
)
)
.
toBe
(
'\tfoo\\tbar'
)
;
expect
(
replace_explicit_tabs
(
' \\t\\tfoo'
)
)
.
toBe
(
' \t\tfoo'
)
;
expect
(
replace_explicit_tabs
(
'#\\tfoo'
)
)
.
toBe
(
'#\tfoo'
)
;
expect
(
replace_explicit_tabs
(
'////\\tfoo'
)
)
.
toBe
(
'////\tfoo'
)
;
expect
(
replace_explicit_tabs
(
' #////\\tfoo'
)
)
.
toBe
(
' #////\tfoo'
)
;
expect
(
replace_explicit_tabs
(
'\\tfoo\n\\tbar'
)
)
.
toBe
(
'\tfoo\n\tbar'
)
;
expect
(
replace_explicit_tabs
(
' \\tfoo\n \\tbar'
)
)
.
toBe
(
' \tfoo\n \tbar'
)
;
expect
(
replace_explicit_tabs
(
'\\t\\tfoo\n #\\tbar'
)
)
.
toBe
(
'\t\tfoo\n #\tbar'
)
;
expect
(
replace_explicit_tabs
(
'\\t\\tfoo\n\\tbar\n#\\tbaz'
)
)
.
toBe
(
'\t\tfoo\n\tbar\n#\tbaz'
)
;
}
)
;
it
(
'fixes an issue'
,
(
)
=>
{
const
=
` *** Begin Patch\n*** Update File: /path/to/file.ts\n@@section1\n-[old code1]\n+[new code1}\n@@section2\n-[old code2]\n+[new code2}\n*** End Patch `
;
expect
(
text_to_patch
(
,
{
'/path/to/file.ts'
:
new
StringTextDocumentWithLanguageId
(
'section1\n[old code1]\nsection2\n[old code2]'
,
'text/plain'
)
}
)
)
.
toMatchInlineSnapshot
(
`
[
{
"actions": {
"/path/to/file.ts": {
"chunks": [
{
"delLines": [
"[old code1]",
],
"insLines": [
"[new code1}",
],
"origIndex": 1,
},
{
"delLines": [
"[old code2]",
],
"insLines": [
"[new code2}",
],
"origIndex": 3,
},
],
"movePath": undefined,
"type": "update",
},
},
},
0,
]
`
)
;
}
)
;
it
(
'tolerates out-of-order patch sections'
,
(
)
=>
{
const
=
` *** Begin Patch\n*** Update File: a.txt\n@@\n-world\n+world hello\n@@\n-hello\n+hello world\n*** End Patch `
;
expect
(
text_to_patch
(
,
{
'a.txt'
:
new
StringTextDocumentWithLanguageId
(
'hello\nworld'
,
'text/plain'
)
}
)
)
.
toMatchObject
(
[
{
:
{
'a.txt'
:
{
:
[
{
:
[
'world'
]
,
:
[
'world hello'
]
,
:
1
,
}
,
{
:
[
'hello'
]
,
:
[
'hello world'
]
,
:
0
,
}
,
]
,
:
'update'
,
}
}
}
,
0
]
)
;
}
)
;
it
(
'does not tolerate edit distance below threshold'
,
(
)
=>
{
const
=
[
'*** Begin Patch'
,
'*** Update File: a.txt'
,
'@@'
,
'-world!'
,
'+everyone'
,
'*** End Patch'
]
.
join
(
'\n'
)
;
expect
(
(
)
=>
text_to_patch
(
,
{
'a.txt'
:
new
StringTextDocumentWithLanguageId
(
'hello\nworld'
,
'text/plain'
)
}
)
)
.
toThrowErrorMatchingInlineSnapshot
(
`
[Error: Invalid context at character 0:
world!]
`
)
;
}
)
;
it
(
'tolerates edit distance above threshold'
,
(
)
=>
{
const
=
[
'*** Begin Patch'
,
'*** Update File: a.txt'
,
'@@'
,
'-world!'
,
'-lots'
,
'-more'
,
'-context'
,
'+everyone'
,
'*** End Patch'
]
.
join
(
'\n'
)
;
expect
(
text_to_patch
(
,
{
'a.txt'
:
new
StringTextDocumentWithLanguageId
(
'hello\nworld\nlots\nmore\ncontext\nhere\n'
,
'text/plain'
)
}
)
)
.
toMatchInlineSnapshot
(
`
[
{
"actions": {
"a.txt": {
"chunks": [
{
"delLines": [
"world!",
"lots",
"more",
"context",
],
"insLines": [
"everyone",
],
"origIndex": 1,
},
],
"movePath": undefined,
"type": "update",
},
},
},
26,
]
`
)
;
}
)
;
it
(
'tolerates missing patch end'
,
(
)
=>
{
const
=
` *** Begin Patch\n*** Update File: a.txt\n@@\n-world\n+world hello\n@@\n-hello\n+hello world `
;
expect
(
text_to_patch
(
,
{
'a.txt'
:
new
StringTextDocumentWithLanguageId
(
'hello\nworld'
,
'text/plain'
)
}
)
)
.
toMatchObject
(
[
{
:
{
'a.txt'
:
{
:
[
{
:
[
'world'
]
,
:
[
'world hello'
]
,
:
1
,
}
,
{
:
[
'hello'
]
,
:
[
'hello world'
]
,
:
0
,
}
,
]
,
:
'update'
,
}
}
}
,
0
]
)
;
}
)
;
it
(
'tolerates missing hunk line addition'
,
(
)
=>
{
const
=
[
'*** Begin Patch'
,
'*** Update File: a.txt'
,
'@@'
,
'-world'
,
'+'
,
'def greet():'
,
'+ print("Hello, world!")'
,
'*** End Patch'
]
.
join
(
'\n'
)
;
expect
(
text_to_patch
(
,
{
'a.txt'
:
new
StringTextDocumentWithLanguageId
(
'hello\nworld'
,
'text/plain'
)
}
)
)
.
toMatchInlineSnapshot
(
`
[
{
"actions": {
"a.txt": {
"chunks": [
{
"delLines": [
"world",
],
"insLines": [
"",
"def greet():",
" print("Hello, world!")",
],
"origIndex": 1,
},
],
"movePath": undefined,
"type": "update",
},
},
},
64,
]
`
)
;
}
)
;
it
(
'tolerate to extra whitespace in delimited sections'
,
(
)
=>
{
const
=
` *** Begin Patch\n*** Update File: a.txt\n@@\n-world\n+world hello\n\n@@\n-hello\n+hello world\n*** End Patch `
;
expect
(
text_to_patch
(
,
{
'a.txt'
:
new
StringTextDocumentWithLanguageId
(
'hello\nworld'
,
'text/plain'
)
}
)
)
.
toMatchObject
(
[
{
:
{
'a.txt'
:
{
:
[
{
:
[
'world'
]
,
:
[
'world hello'
]
,
:
1
,
}
,
{
:
[
'hello'
]
,
:
[
'hello world'
]
,
:
0
,
}
,
]
,
:
'update'
,
}
}
}
,
0
]
)
;
}
)
;
it
(
'matches explicit \\t tab chars'
,
(
)
=>
{
const
=
` *** Begin Patch\n*** Update File: a.txt\n@@\n-\\t\\tworld\n+\\t\\tworld hello\n*** End Patch `
;
expect
(
text_to_patch
(
,
{
'a.txt'
:
new
StringTextDocumentWithLanguageId
(
'\t\thello\n\t\tworld'
,
'text/plain'
)
}
)
)
.
toMatchObject
(
[
{
:
{
'a.txt'
:
{
:
[
{
:
[
'\t\tworld'
]
,
:
[
'\t\tworld hello'
]
,
:
1
,
}
]
,
:
'update'
,
}
}
}
,
6
]
)
;
}
)
;
it
(
'preserves tab chars in tex files'
,
(
)
=>
{
const
=
[
'*** Begin Patch'
,
'*** Update File: a.tex'
,
'@@'
,
'hello'
,
'-\tworld'
,
'+\t\\textbf{world}'
,
'*** End Patch'
]
.
join
(
'\n'
)
;
expect
(
text_to_patch
(
,
{
'a.tex'
:
new
StringTextDocumentWithLanguageId
(
'prefix\nhello\n\tworld\nwoo\nsuffix'
,
'text/plain'
)
}
)
)
.
toMatchInlineSnapshot
(
`
[
{
"actions": {
"a.tex": {
"chunks": [
{
"delLines": [
" world",
],
"insLines": [
" \\textbf{world}",
],
"origIndex": 2,
},
],
"movePath": undefined,
"type": "update",
},
},
},
0,
]
`
)
;
}
)
;
it
(
'matches explicit \\n and \\t tab chars'
,
(
)
=>
{
const
=
[
'*** Begin Patch'
,
'*** Update File: a.txt'
,
'@@'
,
'-hello\\n\\tworld\\nwoo'
,
'+hello\\n\\tcode!\\nwoo'
,
'*** End Patch'
]
.
join
(
'\n'
)
;
expect
(
text_to_patch
(
,
{
'a.txt'
:
new
StringTextDocumentWithLanguageId
(
'prefix\nhello\n\tworld\nwoo\nsuffix'
,
'text/plain'
)
}
)
)
.
toMatchInlineSnapshot
(
`
[
{
"actions": {
"a.txt": {
"chunks": [
{
"delLines": [
"hello
world
woo",
],
"insLines": [
"hello
code!
woo",
],
"origIndex": 1,
},
],
"movePath": undefined,
"type": "update",
},
},
},
134,
]
`
)
;
}
)
;
it
(
'always normalizes explicit \\t tab chars in replacement'
,
(
)
=>
{
const
=
` *** Begin Patch\n*** Update File: a.txt\n@@\n-hello\n+\\t\\tworld\n*** End Patch `
;
expect
(
text_to_patch
(
,
{
'a.txt'
:
new
StringTextDocumentWithLanguageId
(
'hello'
,
'text/plain'
)
}
)
)
.
toMatchInlineSnapshot
(
`
[
{
"actions": {
"a.txt": {
"chunks": [
{
"delLines": [
"hello",
],
"insLines": [
" world",
],
"origIndex": 0,
},
],
"movePath": undefined,
"type": "update",
},
},
},
0,
]
`
)
;
}
)
;
it
(
'issue#262549'
,
async
(
)
=>
{
const
=
await
.
readFile
(
` ${ __dirname} /corpus/262549-input.txt `
,
'utf-8'
)
;
const
=
await
.
readFile
(
` ${ __dirname} /corpus/262549-call.txt `
,
'utf-8'
)
;
const
=
JSON
.
parse
(
'"'
+
.
replaceAll
(
'\n'
,
'\\n'
)
.
replaceAll
(
'\t'
,
'\\t'
)
+
'"'
)
;
const
=
{
'/Users/omitted/projects/flagship/edge-ai/scripts/Fix-VisuallySimilarUnicode.ps1'
:
new
StringTextDocumentWithLanguageId
(
,
'text/plain'
)
}
;
const
[
]
=
text_to_patch
(
,
)
;
const
=
patch_to_commit
(
,
)
;
await
expect
(
.
values
(
.
)
.
at
(
0
)
?.
)
.
toMatchFileSnapshot
(
` ${ __dirname} /corpus/262549-output.txt `
)
;
}
)
;
it
(
'reindents unindented code'
,
async
(
)
=>
{
const
=
await
.
readFile
(
` ${ __dirname} /corpus/reindent-input.txt `
,
'utf-8'
)
;
const
=
await
.
readFile
(
` ${ __dirname} /corpus/reindent-call.txt `
,
'utf-8'
)
;
const
=
{
'/Users/connor/Downloads/hello.yml'
:
new
StringTextDocumentWithLanguageId
(
,
'text/plain'
)
}
;
const
[
]
=
text_to_patch
(
,
)
;
const
=
patch_to_commit
(
,
)
;
expect
(
.
values
(
.
)
.
at
(
0
)
?.
)
.
toMatchInlineSnapshot
(
`
"- hello
- world
- list:
- item1
- item2
- item3
- item1a
- item2a
- item3a
- item1b
- item20b
- nested3
- nested2
- item3b
- item1c
- item2c
- item3c
- item1d
- item2d
- item3d
"
`
)
;
}
)
;
it
(
'issue#267547'
,
async
(
)
=>
{
const
=
await
.
readFile
(
` ${ __dirname} /corpus/267547-input.txt `
,
'utf-8'
)
;
let
=
await
.
readFile
(
` ${ __dirname} /corpus/267547-call.txt `
,
'utf-8'
)
;
=
.
replaceAll
(
'\r\n'
,
'\n'
)
;
const
=
await
.
readFile
(
` ${ __dirname} /corpus/267547-output.txt `
,
'utf-8'
)
;
const
=
{
'267547.txt'
:
new
StringTextDocumentWithLanguageId
(
.
replaceAll
(
'\r\n'
,
'\n'
)
,
'text/plain'
)
}
;
const
[
]
=
text_to_patch
(
,
)
;
const
=
patch_to_commit
(
,
)
;
const
=
.
values
(
.
)
.
at
(
0
)
?.
;
expect
(
?.
replaceAll
(
'\r\n'
,
'\n'
)
)
.
toBe
(
.
replaceAll
(
'\r\n'
,
'\n'
)
)
;
}
)
;
it
(
'indent when multiple sections are updated'
,
async
(
)
=>
{
const
=
await
.
readFile
(
` ${ __dirname} /corpus/multipleSections-input.txt `
,
'utf-8'
)
;
let
=
await
.
readFile
(
` ${ __dirname} /corpus/multipleSections-call.txt `
,
'utf-8'
)
;
=
.
replaceAll
(
'\r\n'
,
'\n'
)
;
const
=
await
.
readFile
(
` ${ __dirname} /corpus/multipleSections-output.txt `
,
'utf-8'
)
;
const
=
{
'multipleSections.txt'
:
new
StringTextDocumentWithLanguageId
(
.
replaceAll
(
'\r\n'
,
'\n'
)
,
'text/plain'
)
}
;
const
[
]
=
text_to_patch
(
,
)
;
const
=
patch_to_commit
(
,
)
;
const
=
.
values
(
.
)
.
at
(
0
)
?.
;
expect
(
?.
replaceAll
(
'\r\n'
,
'\n'
)
)
.
toBe
(
.
replaceAll
(
'\r\n'
,
'\n'
)
)
;
}
)
;
it
(
'multiple indented lines update'
,
async
(
)
=>
{
const
=
await
.
readFile
(
` ${ __dirname} /corpus/multipleIndentedLines-input.txt `
,
'utf-8'
)
;
let
=
await
.
readFile
(
` ${ __dirname} /corpus/multipleIndentedLines-call.txt `
,
'utf-8'
)
;
=
.
replaceAll
(
'\r\n'
,
'\n'
)
;
const
=
await
.
readFile
(
` ${ __dirname} /corpus/multipleIndentedLines-output.txt `
,
'utf-8'
)
;
const
=
{
'multipleIndentedLines.txt'
:
new
StringTextDocumentWithLanguageId
(
.
replaceAll
(
'\r\n'
,
'\n'
)
,
'text/plain'
)
}
;
const
[
]
=
text_to_patch
(
,
)
;
const
=
patch_to_commit
(
,
)
;
const
=
.
values
(
.
)
.
at
(
0
)
?.
;
expect
(
?.
replaceAll
(
'\r\n'
,
'\n'
)
)
.
toBe
(
.
replaceAll
(
'\r\n'
,
'\n'
)
)
;
}
)
;
suite
(
'corpus'
,
(
)
=>
{
const
=
.
join
(
,
'corpus'
)
;
it
(
'applies corpus'
,
async
(
)
=>
{
const
=
(
await
.
readdir
(
)
)
.
filter
(
=>
.
endsWith
(
'.patch'
)
)
.
sort
(
)
;
for
(
const
of
)
{
const
=
await
.
readFile
(
.
join
(
,
)
,
'utf8'
)
;
const
{
,
,
,
,
}
=
JSON
.
parse
(
)
;
const
:
<
string
,
>
=
{
}
;
if
(
&&
)
{
[
]
=
new
StringTextDocumentWithLanguageId
(
,
'text/plain'
)
;
}
else
{
for
(
const
[
,
]
of
.
entries
(
)
)
{
[
URI
.
parse
(
)
.
]
=
new
StringTextDocumentWithLanguageId
(
as
string
,
'text/plain'
)
;
}
}
try
{
const
[
]
=
text_to_patch
(
,
)
;
if
(
!==
undefined
)
{
const
=
patch_to_commit
(
,
)
;
expect
(
.
[
]
.
)
.
toEqual
(
)
;
}
}
catch
(
)
{
console
.
error
(
` Failed to apply patch from ${ patchFile} ( ${ e} ):\n `
,
)
;
const
=
.
join
(
.
tmpdir
(
)
,
)
;
await
.
writeFile
(
,
.
entries
(
)
.
map
(
(
[
,
]
)
=>
` // ${ uri} \n ${ doc. getText ( ) } `
)
.
join
(
'\n\n'
)
)
;
console
.
error
(
` \nOriginals written to ${ originalsPath} `
)
;
throw
;
}
}
}
)
;
.
skip
(
'generate randomized corpus'
,
async
(
)
=>
{
const
=
50
;
const
=
3
;
const
=
3
;
const
random
=
(
:
number
,
:
number
)
=>
.
floor
(
.
random
(
)
*
(
-
+
1
)
)
+
;
const
=
.
join
(
,
'..'
,
'..'
,
'..'
,
'..'
,
'..'
,
'..'
,
'..'
,
'vscode'
,
'src'
)
;
const
=
[
]
;
for
await
(
const
of
.
glob
(
'**/*.ts'
,
{
:
}
)
)
{
.
push
(
.
join
(
,
)
)
;
}
await
.
mkdir
(
,
{
:
true
}
)
;
let
=
0
;
for
(
let
=
0
;
<
;
++
)
{
const
=
[
random
(
0
,
.
-
1
)
]
;
const
=
await
.
readFile
(
,
'utf8'
)
;
const
=
.
split
(
'\n'
)
;
if
(
.
<
10
)
{
--
;
continue
;
}
const
=
'/'
+
.
relative
(
,
)
.
replaceAll
(
'\\'
,
'/'
)
;
const
=
[
'*** Begin Patch'
,
` *** Update File: ${ fpath} `
,
'@@'
,
]
;
const
:
number
[
]
=
[
]
;
for
(
let
=
random
(
1
,
)
;
.
<
;
)
{
const
=
random
(
0
,
.
-
1
)
;
if
(
!
.
includes
(
)
)
{
.
push
(
)
;
}
}
.
sort
(
(
,
)
=>
-
)
;
const
:
string
[
]
=
[
]
;
let
=
false
;
for
(
let
=
0
;
<
.
;
++
)
{
const
=
.
find
(
=>
>
)
;
const
=
findLast
(
,
=>
<=
)
;
const
=
(
!==
undefined
&&
-
<
)
||
(
!==
undefined
&&
-
<
)
;
if
(
&&
!
)
{
if
(
>
0
)
{
.
push
(
''
)
;
}
const
=
[
]
.
match
(
/ ^ \s * /
)
?.
[
0
]
;
const
=
&&
findLast
(
,
=>
!
.
startsWith
(
)
,
-
1
)
;
if
(
)
{
.
push
(
` @@ ${ contextLine. trim ( ) } `
)
;
}
else
{
.
push
(
'@@'
)
;
}
}
=
;
if
(
===
)
{
switch
(
random
(
0
,
2
)
)
{
case
0
:
{
const
=
` // Inserted line ${ ln} `
;
.
push
(
,
[
]
)
;
.
push
(
` + ${ insertText} `
,
[
]
)
;
break
;
}
case
1
:
{
.
push
(
` - ${ lines[ ln] } `
)
;
break
;
}
case
2
:
{
const
=
` // Replaced line ${ ln} `
;
.
push
(
` - ${ lines[ ln] } `
)
;
.
push
(
` + ${ newText} `
)
;
.
push
(
)
;
}
}
}
else
{
.
push
(
[
]
)
;
if
(
)
{
.
push
(
` ${ lines[ ln] } `
)
;
}
}
}
.
push
(
'*** End Patch'
)
;
await
.
writeFile
(
.
join
(
,
'corpus'
,
` ${ caseNo++ } .patch `
)
,
JSON
.
stringify
(
{
:
.
join
(
'\n'
)
,
:
,
:
.
join
(
'\n'
)
,
}
,
null
,
2
)
)
;
}
}
)
;
}
)
;
}
)
;