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 / node / findTestsFilesTool.tsx 311 строк · изменён 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
import * as l10n from '@vscode/l10n' ;
import { BasePromptElementProps , PromptElement , PromptElementProps , PromptSizing } from '@vscode/prompt-tsx' ;
import type * as vscode from 'vscode' ;
import { TextDocumentSnapshot } from '../../../platform/editing/common/textDocumentSnapshot' ;
import { IIgnoreService } from '../../../platform/ignore/common/ignoreService' ;
import { IPromptPathRepresentationService
filePaths
ranges a b c d
toolName
_testFileFinder
@ instantiationService
@ workspaceService
@ promptPathRepresentationService
@ ignoreService
options vscode token vscode
languageId
inputUris
testFiles
anyTestFiles
srcFiles
lookForAnyTestFile
options filePath
uri filePath
uri
uri
uri
inputUris
languageId
languageId
token
srcFileUri token
srcFileUri srcFileUri
srcFileDocument srcFileUri
srcFiles srcFile srcFileUri testFile srcFileDocument
testFileUri token
testFileUri
testFileDocument testFileUri
testFiles srcFile testFile testFileUri testFileDocument
token
testFiles lookForAnyTestFile
testFileUri lookForAnyTestFile token
testFileUri testFileUri
testFileDocument testFileUri
anyTestFiles srcFile lookForAnyTestFile testFile testFileUri testFileDocument
nTestFilesFound testFiles srcFiles anyTestFiles
props
languageId languageId
testFiles
srcFiles
anyTestFiles
result
props options token
result nTestFilesFound
l10n
nTestFilesFound
l10n
l10n
result
options vscode token vscode vscode vscode
options length
uris options filePath filePath
uris uri uri
invocationMessage l10n
uris
uris uri uri
promptContext
seen
filePaths
ranges a b c d
path range vscode
seen path
seen path
filePaths path
ranges range range range range range
ref promptContext
ref
ref
ref
ref ref
promptContext
file promptContext
file file
filePaths
filePaths
ranges
srcFile
testFile
languageId
testFiles
anyTestFiles
srcFiles
props
@ parserService
props
_state sizing
tokenSizing sizing
documentData info info formattingOptions selection
docs documentData tokenSizing
index
info
info
info
projectedDoc
info
props
@ promptPathRepresentationService
props
state sizing
projectedDoc
info
props
@ promptPathRepresentationService
props
state sizing
info
projectedDoc
props
props
state sizing
}
from
'../../../platform/prompts/common/promptPathRepresentationService'
;
import
{ IWorkspaceService }
from
'../../../platform/workspace/common/workspaceService'
;
import
{ isLocation }
from
'../../../util/common/types'
;
import
{ CancellationToken }
from
'../../../util/vs/base/common/cancellation'
;
import
{ Disposable }
from
'../../../util/vs/base/common/lifecycle'
;
import
{
URI
}
from
'../../../util/vs/base/common/uri'
;
import
{ IInstantiationService }
from
'../../../util/vs/platform/instantiation/common/instantiation'
;
import
{ ExtendedLanguageModelToolResult , LanguageModelPromptTsxPart , MarkdownString }
from
'../../../vscodeTypes'
;
import
{ IBuildPromptContext }
from
'../../prompt/common/intents'
;
import
{ isTestFile, TestFileFinder }
from
'../../prompt/node/testFiles'
;
import
{ renderPromptElementJSON }
from
'../../prompts/node/base/promptRenderer'
;
import
{ Tag }
from
'../../prompts/node/base/tag'
;
import
{ IParserService }
from
'../../../platform/parser/node/parserService'
;
import
{ TestDeps }
from
'../../intents/node/testIntent/testDeps'
;
import
{ ProjectedDocument }
from
'../../prompts/node/inline/summarizedDocument/summarizeDocument'
;
import
{ summarizeDocuments, SummarizeDocumentsItem }
from
'../../prompts/node/inline/summarizedDocument/summarizeDocumentHelpers'
;
import
{ CodeBlock }
from
'../../prompts/node/panel/safeElements'
;
import
{ ToolName }
from
'../common/toolNames'
;
import
{ ICopilotTool , ToolRegistry }
from
'../common/toolsRegistry'
;
import
{ formatUriForFileWidget }
from
'../common/toolUtils'
;
import
{ checkCancellation, resolveToolInputPath }
from
'./toolUtils'
;
interface
IFindTestFilesToolsParams
{
readonly
:
string
[
]
;
readonly
?
:
(
[
:
number
,
:
number
,
:
number
,
:
number
]
|
undefined
)
[
]
;
}
class
FindTestFilesTool
extends
Disposable
implements
ICopilotTool< IFindTestFilesToolsParams>
{
public
static
readonly
=
ToolName
.
FindTestFiles
;
private
readonly
:
TestFileFinder
;
constructor
(
IInstantiationService
private
readonly
:
IInstantiationService
,
IWorkspaceService
private
readonly
:
IWorkspaceService
,
IPromptPathRepresentationService
private
readonly
:
IPromptPathRepresentationService
,
IIgnoreService
private
readonly
:
IIgnoreService
,
)
{
super
(
)
;
this
.
_testFileFinder
=
this
.
instantiationService
.
createInstance
(
TestFileFinder
)
;
}
async
invoke
(
:
.
LanguageModelToolInvocationOptions
<
IFindTestFilesToolsParams
>
,
:
CancellationToken
)
:
Promise
<
.
LanguageModelToolResult
>
{
let
:
string
|
undefined
;
const
:
URI
[
]
=
[
]
;
const
:
IRelatedExistingFile
[
]
=
[
]
;
const
:
IRelatedExistingFile
[
]
=
[
]
;
const
:
IRelatedExistingFile
[
]
=
[
]
;
let
:
TextDocumentSnapshot
|
undefined
;
await
Promise
.
all
(
.
input
.
filePaths
.
map
(
async
=>
{
const
=
this
.
promptPathRepresentationService
.
resolveFilePath
(
)
;
if
(
!
)
{
throw
new
Error
(
` Invalid input path ${ filePath} `
)
;
}
if
(
await
this
.
ignoreService
.
isCopilotIgnored
(
)
)
{
return
;
}
const
document
=
await
this
.
workspaceService
.
openTextDocumentAndSnapshot
(
)
;
.
push
(
document
.
uri
)
;
if
(
===
undefined
)
{
=
document
.
languageId
;
}
if
(
.
isCancellationRequested
)
{
return
;
}
if
(
isTestFile
(
document
)
)
{
const
=
await
this
.
_testFileFinder
.
findFileForTestFile
(
document
,
)
;
if
(
&&
!
await
this
.
ignoreService
.
isCopilotIgnored
(
)
)
{
const
=
await
this
.
workspaceService
.
openTextDocumentAndSnapshot
(
)
;
.
push
(
{
:
,
:
document
.
uri
,
document
:
}
)
;
}
}
else
{
const
=
await
this
.
_testFileFinder
.
findTestFileForSourceFile
(
document
,
)
;
if
(
)
{
const
=
await
this
.
workspaceService
.
openTextDocumentAndSnapshot
(
)
;
.
push
(
{
:
document
.
uri
,
:
,
document
:
}
)
;
}
}
}
)
)
;
checkCancellation
(
)
;
if
(
.
length
===
0
&&
)
{
const
=
await
this
.
_testFileFinder
.
findAnyTestFileForSourceFile
(
,
)
;
if
(
&&
!
await
this
.
ignoreService
.
isCopilotIgnored
(
)
)
{
const
=
await
this
.
workspaceService
.
openTextDocumentAndSnapshot
(
)
;
.
push
(
{
:
.
uri
,
:
,
document
:
}
)
;
}
}
const
=
.
length
+
.
length
+
.
length
;
const
:
IFindTestFilesToolOutputProps
=
{
:
!
,
,
,
}
;
const
=
new
ExtendedLanguageModelToolResult
(
[
new
LanguageModelPromptTsxPart
(
await
renderPromptElementJSON
(
this
.
instantiationService
,
FindTestFilesToolOutput
,
,
.
tokenizationOptions
,
)
)
]
)
;
.
toolResultMessage
=
===
0
?
new
MarkdownString
(
.
t
` Checked ${ this . formatURIs ( inputUris) } for test related files, none found `
)
:
===
1
?
new
MarkdownString
(
.
t
` Checked ${ this . formatURIs ( inputUris) } , 1 file found `
)
:
new
MarkdownString
(
.
t
` Checked ${ this . formatURIs ( inputUris) } , ${ nTestFilesFound} files found `
)
;
return
;
}
prepareInvocation
(
:
.
LanguageModelToolInvocationPrepareOptions
<
IFindTestFilesToolsParams
>
,
:
.
CancellationToken
)
:
.
ProviderResult
<
.
PreparedToolInvocation
>
{
if
(
!
.
input
.
filePaths
?.
)
{
throw
new
Error
(
'Invalid input'
)
;
}
const
=
.
input
.
filePaths
.
map
(
=>
resolveToolInputPath
(
,
this
.
promptPathRepresentationService
)
)
;
if
(
.
some
(
=>
===
undefined
)
)
{
throw
new
Error
(
'Invalid input'
)
;
}
return
{
:
new
MarkdownString
(
.
t
` Checking ${ this . formatURIs ( uris) } `
)
,
}
;
}
private
formatURIs
(
:
URI
[
]
)
:
string
{
return
.
map
(
=>
formatUriForFileWidget
(
)
)
.
join
(
', '
)
;
}
async
provideInput
(
:
IBuildPromptContext
)
:
Promise
<
IFindTestFilesToolsParams
|
undefined
>
{
const
=
new
Set< string >
(
)
;
const
:
string
[
]
=
[
]
;
const
:
(
[
:
number
,
:
number
,
:
number
,
:
number
]
|
undefined
)
[
]
=
[
]
;
function
addPath
(
:
string
,
:
.
Range
|
undefined
)
{
if
(
!
.
has
(
)
)
{
.
add
(
)
;
.
push
(
)
;
.
push
(
&&
[
.
start
.
line
,
.
start
.
character
,
.
end
.
line
,
.
end
.
character
]
)
;
}
}
for
(
const
of
.
chatVariables
)
{
if
(
URI
.
isUri
(
.
value
)
)
{
addPath
(
this
.
promptPathRepresentationService
.
getFilePath
(
.
value
)
,
undefined
)
;
}
else
if
(
isLocation
(
.
value
)
)
{
addPath
(
this
.
promptPathRepresentationService
.
getFilePath
(
.
value
.
uri
)
,
.
value
.
range
)
;
}
}
if
(
.
workingSet
)
{
for
(
const
of
.
workingSet
)
{
addPath
(
this
.
promptPathRepresentationService
.
getFilePath
(
.
document
.
uri
)
,
.
range
)
;
}
}
if
(
!
.
length
)
{
}
return
{
,
}
;
}
}
interface
IRelatedExistingFile
{
readonly
:
URI
;
readonly
:
URI
;
readonly
document
:
TextDocumentSnapshot
;
}
ToolRegistry
.
registerTool
(
FindTestFilesTool
)
;
interface
IFindTestFilesToolOutputProps
extends
BasePromptElementProps
{
readonly
:
string
;
readonly
:
IRelatedExistingFile
[
]
;
readonly
:
IRelatedExistingFile
[
]
;
readonly
:
IRelatedExistingFile
[
]
;
}
class
FindTestFilesToolOutput
extends
PromptElement< IFindTestFilesToolOutputProps>
{
constructor
(
:
PromptElementProps
<
IFindTestFilesToolOutputProps
>
,
IParserService
private
readonly
:
IParserService
,
)
{
super
(
)
;
}
async
render
(
:
void
,
:
PromptSizing
)
{
if
(
this
.
props
.
testFiles
.
length
===
0
&&
this
.
props
.
srcFiles
.
length
===
0
&&
this
.
props
.
anyTestFiles
.
length
===
0
)
{
return
< >
No test related files found.
</ >
;
}
const
=
Math
.
min
(
.
tokenBudget
,
32_000
)
;
const
:
SummarizeDocumentsItem
[
]
=
[
...
this
.
props
.
testFiles
,
...
this
.
props
.
anyTestFiles
,
...
this
.
props
.
srcFiles
]
.
map
(
=>
(
{
document
:
.
document
,
:
undefined
,
:
undefined
}
)
)
;
const
=
await
summarizeDocuments
(
this
.
parserService
,
,
)
;
let
=
0
;
return
< >
< TestDeps languageId = { this . props . languageId } />
The following files are useful when writing tests:
< br />
{
this
.
props
.
testFiles
.
map
(
=>
< RelatedTestDescription info = { info} projectedDoc = { docs[ index++ ] } />
)
}
{
this
.
props
.
anyTestFiles
.
map
(
=>
< ExampleTestDescription info = { info} projectedDoc = { docs[ index++ ] } />
)
}
{
this
.
props
.
srcFiles
.
map
(
=>
< RelatedSourceDescription info = { info} projectedDoc = { docs[ index++ ] } />
)
}
</ >;
}
}
interface IRelatedSourceDescriptionProps extends BasePromptElementProps
{
readonly
:
ProjectedDocument
;
readonly
:
IRelatedExistingFile
;
}
class RelatedSourceDescription extends PromptElement<IRelatedSourceDescriptionProps>
{
constructor
(
:
PromptElementProps
<
IRelatedSourceDescriptionProps
>
,
IPromptPathRepresentationService
private
readonly
:
IPromptPathRepresentationService
,
)
{
super
(
)
;
}
render
(
:
void
,
:
PromptSizing
)
{
const
document
=
this
.
props
.
info
.
document
;
return
< Tag name = ' relatedSource' >
The test file
{
this
.
promptPathRepresentationService
.
getFilePath
(
this
.
props
.
info
.
testFile
)
}
contains tests for the following file:
< br />
< CodeBlock code = { this . props . projectedDoc . text } uri = { document . uri } languageId = { document . languageId } includeFilepath = { true } />
<br />
</ Tag >
;
}
}
interface IRelatedTestDescriptionProps extends BasePromptElementProps
{
readonly
:
ProjectedDocument
;
readonly
:
IRelatedExistingFile
;
}
class RelatedTestDescription extends PromptElement<IRelatedTestDescriptionProps>
{
constructor
(
:
PromptElementProps
<
IRelatedTestDescriptionProps
>
,
IPromptPathRepresentationService
private
readonly
:
IPromptPathRepresentationService
,
)
{
super
(
)
;
}
render
(
:
void
,
:
PromptSizing
)
{
const
document
=
this
.
props
.
info
.
document
;
return
< Tag name = ' relatedTest' >
Tests for
{
this
.
promptPathRepresentationService
.
getFilePath
(
this
.
props
.
info
.
srcFile
)
}
can go into the following existing file:
< br />
< CodeBlock code = { this . props . projectedDoc . text } uri = { document . uri } languageId = { document . languageId } includeFilepath = { true } />
<br />
</ Tag >
;
}
}
interface IExampleTestDescriptionProps extends BasePromptElementProps
{
readonly
:
IRelatedExistingFile
;
readonly
:
ProjectedDocument
;
}
class ExampleTestDescription extends PromptElement<IExampleTestDescriptionProps>
{
constructor
(
:
PromptElementProps
<
IExampleTestDescriptionProps
>
,
)
{
super
(
)
;
}
render
(
:
void
,
:
PromptSizing
)
{
return
< Tag name = ' sampleTest' >
This is a sample test file:
< br />
< CodeBlock code = { this . props . projectedDoc . text } uri = { this . props . info . document . uri } languageId = { this . props . info . document . languageId } includeFilepath = { true } />
<br />
</ Tag >
;
}
}