ide на основе vs code · VibeGit
ide на основе vs code Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
krutaya-ide-na-osnove-vs-code / extensions / copilot / test / simulation / renameSuggestionsProvider.stest.ts 522 строк · изменён 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
import * as assert from 'assert' ;
import { outdent } from 'outdent' ;
import type * as vscode from 'vscode' ;
import { guessNamingConvention, NamingConvention } from '../../src/extension/renameSuggestions/common/namingConvention' ;
import { RenameSuggestionsProvider } from '../../src/extension/renameSuggestions/node/renameSuggestionsProvider' ;
import { TestingServiceCollection } from '../../src/platform/test/node/services' ;
import { IRelativeFile } from '../../src/platform/test/node/simulationWorkspace' ;
import deannotateSrc
CancellationToken
IInstantiationService
NewSymbolNameTriggerKind Range
ISimulationTestRuntime ssuite stest
setupSimulationWorkspace teardownSimulationWorkspace
startIndex
endIndex
offsetRange OffsetRange document vscode TextDocument vscode Range
startPos document offsetRange startIndex
endPos document offsetRange endIndex
range startPos endPos
range
title location
override
newSymbolNames vscode NewSymbolName searchStrings
searchStrings searchStrings searchStrings searchStrings
searchStrings searchStrings s s
newSymbolNames
newSymbolNameLowercase newSymbolName
assert
searchStrings searchString newSymbolNameLowercase searchString
newSymbolNames vscode NewSymbolName
assert newSymbolNames length
newSymbolNames vscode NewSymbolName searchStrings
searchStringsLowercased searchStrings
newSymbolNames newSymbolName searchStringsLowercased length
IRelativeFile
isCurrent
testingServiceCollection TestingServiceCollection files IRenameScenarioFile
currentFileIx files length files f f isCurrent
currentFileIx
currentFile files currentFileIx
files currentFileIx
deannotatedSrc annotatedRange currentFile fileContents
currentFile
currentFile
fileContents deannotatedSrc
files currentFile
workspace testingServiceCollection files
accessor testingServiceCollection
document workspace currentFile fileName document
renameRange annotatedRange document
testRuntime accessor ISimulationTestRuntime
workspacePath workspace document uri
testRuntime workspacePath document
provider accessor IInstantiationService AlwaysEnabledNewSymbolNamesProvider
symbols provider document renameRange NewSymbolNameTriggerKind Invoke CancellationToken None
symbols
accessor workspace
testingServiceCollection
fileContents outdent
file IRenameScenarioFile
kind
fileName
languageId
fileContents
isCurrent
symbols testingServiceCollection file
assert symbols
symbols
assert symbols Math symbols length symbols s s newSymbolName
testingServiceCollection
fileContents outdent
file IRenameScenarioFile
kind
fileName
languageId
fileContents
isCurrent
symbols testingServiceCollection file
assert symbols
symbols
assert symbols s s newSymbolName
symbols
testingServiceCollection
fileContents outdent
file IRenameScenarioFile
kind
fileName
languageId
fileContents
isCurrent
symbols testingServiceCollection file
assert symbols
symbols
symbols
testingServiceCollection
fileContents outdent
file IRenameScenarioFile
kind
fileName
languageId
fileContents
isCurrent
symbols testingServiceCollection file
assert symbols
symbols
assert symbols newSymbolName NamingConvention ScreamingSnakeCase
testingServiceCollection
fileContents outdent
file IRenameScenarioFile
kind
fileName
languageId
fileContents
isCurrent
symbols testingServiceCollection file
assert symbols
symbols
assert symbols NamingConvention Uppercase NamingConvention ScreamingSnakeCase newSymbolName
testingServiceCollection
fileContents outdent
file IRenameScenarioFile
kind
fileName
languageId
fileContents
isCurrent
symbols testingServiceCollection file
assert symbols symbols length
symbols
testingServiceCollection
currentFile IRenameScenarioFile
kind
fileName
languageId
fileContents outdent
isCurrent
fileWithFnDef IRelativeFile
kind
fileName
languageId
fileContents outdent
symbols testingServiceCollection currentFile fileWithFnDef
assert symbols symbols length
symbols
testingServiceCollection
fileContents outdent
file IRenameScenarioFile
kind
fileName
languageId
fileContents
isCurrent
symbols testingServiceCollection file
assert symbols symbols length
assert symbols s s newSymbolName
testingServiceCollection
fileContents outdent
file IRenameScenarioFile
kind
fileName
languageId
fileContents
isCurrent
symbols testingServiceCollection file
assert symbols symbols length
assert symbols s s newSymbolName
testingServiceCollection
fileContents outdent
file IRenameScenarioFile
kind
fileName
languageId
fileContents
isCurrent
symbols testingServiceCollection file
assert symbols symbols length
assert symbols s s newSymbolName
testingServiceCollection
fileContents outdent
file IRenameScenarioFile
kind
fileName
languageId
fileContents
isCurrent
symbols testingServiceCollection file
assert symbols symbols length
assert symbols s s newSymbolName
testingServiceCollection
fileContents outdent
file IRenameScenarioFile
kind
fileName
languageId
fileContents
isCurrent
symbols testingServiceCollection file
assert symbols symbols length
assert symbols s s newSymbolName
testingServiceCollection
fileContents outdent
file IRenameScenarioFile
kind
fileName
languageId
fileContents
isCurrent
symbols testingServiceCollection file
assert symbols symbols length
assert symbols s s newSymbolName
testingServiceCollection
fileContents outdent
file IRenameScenarioFile
kind
fileName
languageId
fileContents
isCurrent
symbols testingServiceCollection file
assert symbols symbols length
assert symbols s s newSymbolName
testingServiceCollection
fileContents outdent
file IRenameScenarioFile
kind
fileName
languageId
fileContents
isCurrent
symbols testingServiceCollection file
assert symbols symbols length
assert symbols s s newSymbolName
testingServiceCollection
fileContents outdent
file IRenameScenarioFile
kind
fileName
languageId
fileContents
isCurrent
symbols testingServiceCollection file
assert symbols symbols length
assert symbols s s newSymbolName
{
}
from
'../../src/util/common/test/annotatedSrc'
;
import
{
}
from
'../../src/util/vs/base/common/cancellation'
;
import
{
}
from
'../../src/util/vs/platform/instantiation/common/instantiation'
;
import
{
,
}
from
'../../src/vscodeTypes'
;
import
{
,
,
}
from
'../base/stest'
;
import
{
,
}
from
'./inlineChatSimulator'
;
import
{
INLINE_INITIAL_DOC_TAG
}
from
'./shared/sharedTypes'
;
type
OffsetRange
=
{
:
number
;
:
number
;
}
;
function
offsetRangeToPositionRange
(
:
,
:
.
)
:
.
{
const
=
.
positionAt
(
.
)
;
const
=
.
positionAt
(
.
)
;
const
=
new
Range
(
,
)
;
return
;
}
ssuite
(
{
:
'Rename suggestions'
,
:
'external'
}
,
(
)
=>
{
class
AlwaysEnabledNewSymbolNamesProvider
extends
RenameSuggestionsProvider
{
isEnabled
(
)
{
return
true
;
}
}
function
assertIncludesLowercased
(
:
.
[
]
,
:
string
|
string
[
]
)
{
=
Array
.
isArray
(
)
?
:
[
]
;
=
.
map
(
=>
.
toLowerCase
(
)
)
;
for
(
const
symbol
of
)
{
const
=
symbol
.
.
toLowerCase
(
)
;
.
ok
(
.
some
(
=>
.
includes
(
)
)
,
` expected to include ${ searchStrings. map ( s => ` ' ${ s} ' ` ) . join ( ' or ' ) } but received ' ${ newSymbolNameLowercase} ' `
)
;
}
}
function
assertLength
(
:
.
[
]
)
{
.
ok
(
.
>
1
,
` expected at least ${ 1 } newSymbolNames but received ${ newSymbolNames. length} \n ${ JSON . stringify ( newSymbolNames. map ( v => v. newSymbolName) , null , '\t' ) } `
)
;
}
function
countMatches
(
:
.
[
]
,
:
string
)
{
const
=
.
toLowerCase
(
)
;
return
.
filter
(
symbol
=>
symbol
.
.
toLowerCase
(
)
.
includes
(
)
)
.
;
}
type
IRenameScenarioFile
=
(
&
{
?
:
boolean
;
}
)
;
async
function
provideNewSymbolNames
(
:
,
:
[
]
)
{
const
=
.
===
1
?
0
:
.
findIndex
(
=>
.
)
;
if
(
<
0
)
{
throw
new
Error
(
` No current file found from files:\n ${ JSON . stringify ( files, null , '\t' ) } `
)
;
}
let
=
[
]
;
.
splice
(
,
1
)
;
const
{
,
}
=
deannotateSrc
(
.
)
;
=
{
...
,
:
,
}
;
.
push
(
)
;
const
=
setupSimulationWorkspace
(
,
{
}
)
;
const
=
.
createTestingAccessor
(
)
;
try
{
const
=
.
getDocument
(
.
)
.
;
const
=
offsetRangeToPositionRange
(
,
)
;
const
=
.
get
(
)
;
const
=
.
getFilePath
(
.
)
;
await
.
writeFile
(
+
'.txt'
,
.
getText
(
)
,
INLINE_INITIAL_DOC_TAG
)
;
const
=
.
get
(
)
.
createInstance
(
)
;
const
=
await
.
provideNewSymbolNames
(
,
,
.
,
.
)
;
return
;
}
finally
{
await
teardownSimulationWorkspace
(
,
)
;
}
}
stest
(
'rename a function at its definition'
,
async
(
)
=>
{
const
=
`
export function <<fibonacci>>(n: number): number {
if (n <= 1) {
return 1;
}
return fibonacci(n - 1) + fibonacci(n - 2);
}
`
;
const
:
=
{
:
'relativeFile'
,
:
'fibonacci.ts'
,
:
'typescript'
,
,
:
true
,
}
;
const
=
await
provideNewSymbolNames
(
,
[
]
)
;
.
ok
(
,
` Expected symbols to be non-null `
)
;
assertLength
(
)
;
.
ok
(
countMatches
(
,
'fib'
)
>=
.
floor
(
.
*
0.8
)
,
'Expected 80% of symbols to include fib: '
+
JSON
.
stringify
(
.
map
(
=>
.
)
)
)
;
}
)
;
stest
(
'rename follows naming convention _ - rename a function (with underscore) at its definition'
,
async
(
)
=>
{
const
=
`
export function <<_fib>>(n: number): number {
if (n <= 1) {
return 1;
}
return _fib(n - 1) + _fib(n - 2);
}
`
;
const
:
=
{
:
'relativeFile'
,
:
'fibonacci.ts'
,
:
'typescript'
,
,
:
true
,
}
;
const
=
await
provideNewSymbolNames
(
,
[
]
)
;
.
ok
(
,
` Expected symbols to be non-null `
)
;
assertLength
(
)
;
.
ok
(
.
some
(
=>
.
.
startsWith
(
'_'
)
)
,
'Expected to include symbols with underscore'
)
;
assertIncludesLowercased
(
,
[
'fib'
,
'sequence'
]
)
;
}
)
;
stest
(
'rename a variable reference within a function'
,
async
(
)
=>
{
const
=
(
`
function fromQueryMatches(matches: Parser.QueryMatch[]): InSourceTreeSitterQuery[] {
const captures = matches.flatMap(({ captures }) => captures)
.sort((a, b) => a.node.startIndex - b.node.startIndex || b.node.endIndex - a.node.endIndex);
const qs: InSourceTreeSitterQuery[] = [];
for (let i = 0; i < captures.length;) {
const capture = captures[i];
if (capture.name === 'call_expression' && captures[i + 2].name === 'target_language' && captures[i + 3].name === 'query_src_with_quotes') {
<<qs>>.push(new InSourceTreeSitterQuery(captures[i + 2].node, captures[i + 3].node));
i += 4;
} else {
i++;
}
}
return qs;
}
`
)
;
const
:
=
{
:
'relativeFile'
,
:
'queryDiagnosticsProvider.ts'
,
:
'typescript'
,
,
:
true
,
}
;
const
=
await
provideNewSymbolNames
(
,
[
]
)
;
.
ok
(
,
` Expected symbols to be non-null `
)
;
assertLength
(
)
;
assertIncludesLowercased
(
,
[
'quer'
]
)
;
}
)
;
stest
(
'rename a SCREAMING_SNAKE_CASE enum member'
,
async
(
)
=>
{
const
=
(
`
enum LoadStatus {
NOT_LOADED,
LOADING_FROM_CACHE,
<<LOADING_FROM_SRVER>>,
LOADED,
}
`
)
;
const
:
=
{
:
'relativeFile'
,
:
'queryDiagnosticsProvider.ts'
,
:
'typescript'
,
,
:
true
,
}
;
const
=
await
provideNewSymbolNames
(
,
[
]
)
;
.
ok
(
,
` Expected symbols to be non-null `
)
;
assertLength
(
)
;
.
ok
(
.
every
(
symbol
=>
guessNamingConvention
(
symbol
.
)
===
.
)
,
'Expected all symbols to be SCREAMING_SNAKE_CASE'
)
;
}
)
;
stest
(
'respect context: infer name based on existing code - enum member'
,
async
(
)
=>
{
const
=
(
`
enum Direction {
UP,
DOWN,
RIGHT,
<<TODO>>,
}
`
)
;
const
:
=
{
:
'relativeFile'
,
:
'direction.ts'
,
:
'typescript'
,
,
:
true
,
}
;
const
=
await
provideNewSymbolNames
(
,
[
]
)
;
.
ok
(
,
` Expected symbols to be non-null `
)
;
assertLength
(
)
;
.
ok
(
.
every
(
symbol
=>
[
.
,
.
]
.
includes
(
guessNamingConvention
(
symbol
.
)
)
)
,
'Expected all symbols to be SCREAMING_SNAKE_CASE or UPPERCASE'
)
;
}
)
;
stest
(
'rename a function call - definition in same file'
,
async
(
)
=>
{
const
=
(
`
export function f(n: number): number {
if (n <= 1) {
return 1;
}
return f(n - 1) + f(n - 2);
}
const result = <<f>>(10);
`
)
;
const
:
=
{
:
'relativeFile'
,
:
'script.ts'
,
:
'typescript'
,
,
:
true
,
}
;
const
=
await
provideNewSymbolNames
(
,
[
]
)
;
.
ok
(
&&
.
>
1
,
'Expected to provide > 1 symbols'
)
;
assertIncludesLowercased
(
,
[
'fib'
,
'sequence'
]
)
;
}
)
;
stest
(
'rename a function call - definition in different file'
,
async
(
)
=>
{
const
:
=
{
:
'relativeFile'
,
:
'script.ts'
,
:
'typescript'
,
:
`
import { f } from './impl';
const result = <<f>>(10);
`
,
:
true
,
}
;
const
:
=
{
:
'relativeFile'
,
:
'impl.ts'
,
:
'typescript'
,
:
`
export function f(n: number): number {
if (n <= 1) {
return 1;
}
return f(n - 1) + f(n - 2);
}
`
,
}
;
const
=
await
provideNewSymbolNames
(
,
[
,
]
)
;
.
ok
(
&&
.
>
1
,
'Expected to provide > 1 symbols'
)
;
assertIncludesLowercased
(
,
[
'fib'
,
'sequence'
]
)
;
}
)
;
stest
(
'rename type definition'
,
async
(
)
=>
{
const
=
(
`
type <<t>> = {
firstName: string;
lastName: string;
}
`
)
;
const
:
=
{
:
'relativeFile'
,
:
'script.ts'
,
:
'typescript'
,
,
:
true
,
}
;
const
=
await
provideNewSymbolNames
(
,
[
]
)
;
.
ok
(
&&
.
>
1
,
'Expected to provide > 1 symbols'
)
;
.
ok
(
.
some
(
=>
.
.
toLowerCase
(
)
.
includes
(
'person'
)
)
,
'Inludes person'
)
;
}
)
;
stest
(
'rename type definition when it is used in the same file'
,
async
(
)
=>
{
const
=
(
`
type <<t>> = {
firstName: string;
lastName: string;
}
function greet(p: t): string {
return 'Hello ' + p.firstName + ' ' + p.lastName;
}
`
)
;
const
:
=
{
:
'relativeFile'
,
:
'script.ts'
,
:
'typescript'
,
,
:
true
,
}
;
const
=
await
provideNewSymbolNames
(
,
[
]
)
;
.
ok
(
&&
.
>
1
,
'Expected to provide > 1 symbols'
)
;
.
ok
(
.
some
(
=>
.
.
toLowerCase
(
)
.
includes
(
'person'
)
)
,
'Inludes person'
)
;
}
)
;
stest
(
'rename type reference - same file'
,
async
(
)
=>
{
const
=
(
`
type t = {
firstName: string;
lastName: string;
}
function greet(p: <<t>>): string {
return 'Hello ' + p.firstName + ' ' + p.lastName;
}
`
)
;
const
:
=
{
:
'relativeFile'
,
:
'script.ts'
,
:
'typescript'
,
,
:
true
,
}
;
const
=
await
provideNewSymbolNames
(
,
[
]
)
;
.
ok
(
&&
.
>
1
,
'Expected to provide > 1 symbols'
)
;
.
ok
(
.
some
(
=>
.
.
toLowerCase
(
)
.
includes
(
'person'
)
)
,
'Includes person'
)
;
}
)
;
stest
(
'rename type reference - same file with 2 possible defs'
,
async
(
)
=>
{
const
=
(
`
type t = {
firstName: string;
lastName: string;
}
const t = {
bar: 1
}
function greet(p: <<t>>): string {
return 'Hello ' + p.firstName + ' ' + p.lastName;
}
`
)
;
const
:
=
{
:
'relativeFile'
,
:
'script.ts'
,
:
'typescript'
,
,
:
true
,
}
;
const
=
await
provideNewSymbolNames
(
,
[
]
)
;
.
ok
(
&&
.
>
1
,
'Expected to provide > 1 symbols'
)
;
.
ok
(
.
some
(
=>
.
.
toLowerCase
(
)
.
includes
(
'person'
)
)
,
'Includes person'
)
;
}
)
;
stest
(
'rename class - same file'
,
async
(
)
=>
{
const
=
`
class <<P>> {
firstName: string;
lastName: string;
}
`
;
const
:
=
{
:
'relativeFile'
,
:
'script.ts'
,
:
'typescript'
,
,
:
true
,
}
;
const
=
await
provideNewSymbolNames
(
,
[
]
)
;
.
ok
(
&&
.
>
1
,
'Expected to provide > 1 symbols'
)
;
.
ok
(
.
some
(
=>
.
.
toLowerCase
(
)
.
includes
(
'person'
)
)
,
'Inludes person'
)
;
}
)
;
stest
(
'rename class reference - same file'
,
async
(
)
=>
{
const
=
`
class P {
firstName: string;
lastName: string;
}
function greet(p: <<P>>): string {
return 'Hello ' + p.firstName + ' ' + p.lastName;
}
`
;
const
:
=
{
:
'relativeFile'
,
:
'script.ts'
,
:
'typescript'
,
,
:
true
,
}
;
const
=
await
provideNewSymbolNames
(
,
[
]
)
;
.
ok
(
&&
.
>
1
,
'Expected to provide > 1 symbols'
)
;
.
ok
(
.
some
(
=>
.
.
toLowerCase
(
)
.
includes
(
'person'
)
)
,
'Inludes person'
)
;
}
)
;
stest
(
'rename method with field-awareness'
,
async
(
)
=>
{
const
=
`
class Processor {
private stdoutBuffer: string = '';
<<clearBuffer>>() {
// TODO: implement
}
}
`
;
const
:
=
{
:
'relativeFile'
,
:
'script.ts'
,
:
'typescript'
,
,
:
true
,
}
;
const
=
await
provideNewSymbolNames
(
,
[
]
)
;
.
ok
(
&&
.
>
1
,
'Expected to provide > 1 symbols'
)
;
.
ok
(
.
some
(
=>
.
.
toLowerCase
(
)
.
includes
(
'stdout'
)
)
,
'Knows about `stdoutBuffer`'
)
;
}
)
;
stest
(
'non-tree-sitter language'
,
async
(
)
=>
{
const
=
`
let rec <<f>> n = if n <= 1 then 1 else f (n - 1) + f (n - 2)
`
;
const
:
=
{
:
'relativeFile'
,
:
'impl.ml'
,
:
'ocaml'
,
,
:
true
,
}
;
const
=
await
provideNewSymbolNames
(
,
[
]
)
;
.
ok
(
&&
.
>
1
,
'Expected to provide > 1 symbols'
)
;
.
ok
(
.
some
(
=>
.
.
toLowerCase
(
)
.
includes
(
'fib'
)
)
,
'Includes fib'
)
;
}
)
;
stest
(
'rename class name - CSS'
,
async
(
)
=>
{
const
=
`
.box {
background-color: #fff;
}
<<.button>> {
color: #fff;
background-color: #000;
}
`
;
const
:
=
{
:
'relativeFile'
,
:
'style.css'
,
:
'css'
,
,
:
true
,
}
;
const
=
await
provideNewSymbolNames
(
,
[
]
)
;
.
ok
(
&&
.
>
1
,
'Expected to provide > 1 symbols'
)
;
.
ok
(
.
every
(
=>
.
.
match
(
/ ^ \. ( [ a- z A- Z ] + ) /
)
)
,
'All symbols are class names'
)
;
}
)
;
}
)
;