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 / intents / node / testIntent / testFromSrcInvocation.tsx 442 строк · изменён 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
import { PromptElement , PromptElementProps , PromptSizing , SystemMessage , UserMessage } from '@vscode/prompt-tsx' ;
import assert from 'assert' ;
import type * as vscode from 'vscode' ;
import { IResponsePart } from '../../../../platform/chat/common/chatMLFetcher' ;
import { ChatLocation } from '../../../../platform/chat/common/commonTypes' ;
import { IIgnoreService
kind
uri
_testFileToWriteTo
_additionalResponseParts vscode
_testFileFinder
intent
endpoint
documentContext
alreadyConsumedChatVariable vscode
@ instantiationService
@ workspaceService
@ ignoreService
@ _parserService
promptContext
progress vscode vscode vscode
token vscode
testExampleFile token
testExampleFile testExampleFile
kind
uri testExampleFile
testFileUri
kind
uri testFileUri
range
range
testFileUri
testFile testFileUri
testFileAST testFile
lastTest testFileAST testFileAST
lastTest
range testFile testFile
lastLineOfTest testFile lastTest
lineAfterLastLine lastLineOfTest
range lastLineOfTest lastLineOfTest lineAfterLastLine
progress range
promptContext
promptContext promptContext query
renderer
context
endpoint
testExampleFile
testFileToWriteTo
promptContext
alreadyConsumedChatVariable
result renderer progress token
result
context inputStream outputStream vscode token
responseProcessor
responseProcessor context inputStream outputStream token
doc
additionalParts
testFileKind kind
testFileUri uri
testFileKind testFileUri
additionalParts
testFileKind
range
projectedDoc doc
replyInterpreter
testFileUri
projectedDoc
lineFilter streamingWorkingCopyDocument
streamingWorkingCopyDocument
range
lineFilter
_
replyInterpreter context inputStream outputStream token
testFile testFileUri
testFileAST testFile
lastTest testFileAST testFileAST
range
lastTest
range testFile testFile
lastLineOfTest testFile lastTest
lineAfterLastLine lastLineOfTest
range lastLineOfTest lastLineOfTest lineAfterLastLine
summarizedDocument
testFile
range
testFile
splitDoc summarizedDocument
placeHolder
replyInterpreter splitDoc
markdownStream markdownStream placeHolder
markdownStream markdownStream placeHolder
splitDoc
line line placeHolder
replyInterpreter context inputStream outputStream token
additionalParts p outputStream p
token
kind
testExampleFile token
token
testExampleFile
kind
anyTestFile token
token
kind
testExampleFile anyTestFile
testExampleFile testExampleFile
kind testExampleFile
context
endpoint
testExampleFile
testFileToWriteTo
promptContext
alreadyConsumedChatVariable vscode
props
@ parserService
@ workspaceService
props
override state sizing
history query chatVariables
context testExampleFile testFileToWriteTo alreadyConsumedChatVariable
treeSitterAST context
userSelection vscode context
testedSymbolIdentifier
nodeKind
treeSitterAST
node treeSitterAST context context
userSelection context node
testedSymbolIdentifier node
nodeKind node
documentSummarizationSettings
context
nodeKind nodeKind
node currentScore
node currentScore node node currentScore
summarization
context
context
userSelection
sizing
documentSummarizationSettings
languageId context
extraContext context testExampleFile
requestAndUserQuery
workspaceService
chatVariables
userQuery query
testFileToWriteTo testFileToWriteTo
testedSymbolIdentifier
context
srcFilePath context path context
filteredChatVariables alreadyConsumedChatVariable chatVariables chatVariables v v alreadyConsumedChatVariable
languageId languageId
extraContext extraContext
testExampleFile
requestAndUserQuery
context testExampleFile
extraContext
context
usingExistingTestFile testExampleFile testExampleFile
usingExistingTestFile
extraContext
parent path context
init_search path parent
workspaceRootPath context
init_search
workspaceRootPath path parent path workspaceRootPath fsPath
extraContext
extraContext
error
extraContext
extraContext
}
from
'../../../../platform/ignore/common/ignoreService'
;
import
{ IChatEndpoint }
from
'../../../../platform/networking/common/networking'
;
import
{ IParserService , treeSitterOffsetRangeToVSCodeRange as toRange, vscodeToTreeSitterOffsetRange as toTSOffsetRange }
from
'../../../../platform/parser/node/parserService'
;
import
{ IWorkspaceService }
from
'../../../../platform/workspace/common/workspaceService'
;
import
{ CancellationToken }
from
'../../../../util/vs/base/common/cancellation'
;
import
* as path
from
'../../../../util/vs/base/common/path'
;
import
{ assertType }
from
'../../../../util/vs/base/common/types'
;
import
{
URI
}
from
'../../../../util/vs/base/common/uri'
;
import
{ StringEdit }
from
'../../../../util/vs/editor/common/core/edits/stringEdit'
;
import
{ IInstantiationService }
from
'../../../../util/vs/platform/instantiation/common/instantiation'
;
import
{ ChatResponseMovePart , Range , Uri }
from
'../../../../vscodeTypes'
;
import
{ IBuildPromptContext }
from
'../../../prompt/common/intents'
;
import
{ IDocumentContext }
from
'../../../prompt/node/documentContext'
;
import
{ EarlyStopping , IIntentInvocation , IResponseProcessorContext , LeadingMarkdownStreaming }
from
'../../../prompt/node/intents'
;
import
{ PseudoStopStartResponseProcessor }
from
'../../../prompt/node/pseudoStartStopConversationCallback'
;
import
{ InsertionStreamingEdits , TextPieceClassifiers }
from
'../../../prompt/node/streamingEdits'
;
import
{ TestExample , TestExampleFile }
from
'../../../prompt/node/testExample'
;
import
{ isTestFile, suggestUntitledTestFileLocation, TestFileFinder }
from
'../../../prompt/node/testFiles'
;
import
{ CopilotIdentityRules }
from
'../../../prompts/node/base/copilotIdentity'
;
import
{ InstructionMessage }
from
'../../../prompts/node/base/instructionMessage'
;
import
{ PromptRenderer }
from
'../../../prompts/node/base/promptRenderer'
;
import
{ SafetyRules }
from
'../../../prompts/node/base/safetyRules'
;
import
{ Tag }
from
'../../../prompts/node/base/tag'
;
import
{ createPromptingSummarizedDocument, InlineReplyInterpreter }
from
'../../../prompts/node/inline/promptingSummarizedDocument'
;
import
{ ISummarizedDocumentSettings , ProjectedDocument , RemovableNode }
from
'../../../prompts/node/inline/summarizedDocument/summarizeDocument'
;
import
{ summarizeDocument }
from
'../../../prompts/node/inline/summarizedDocument/summarizeDocumentHelpers'
;
import
{ replaceStringInStream, StreamPipe }
from
'../../../prompts/node/inline/utils/streaming'
;
import
{ ChatToolReferences , ChatVariables }
from
'../../../prompts/node/panel/chatVariables'
;
import
{ HistoryWithInstructions }
from
'../../../prompts/node/panel/conversationHistory'
;
import
{ CustomInstructions }
from
'../../../prompts/node/panel/customInstructions'
;
import
{ CodeBlock }
from
'../../../prompts/node/panel/safeElements'
;
import
{ TestDeps }
from
'./testDeps'
;
import
{ TestsIntent }
from
'./testIntent'
;
import
{ formatRequestAndUserQuery, relativeToWorkspace }
from
'./testPromptUtil'
;
type
TestFileToWriteTo
=
{
:
'existing'
|
'new'
;
:
Uri
;
}
;
export
class
TestFromSourceInvocation
implements
IIntentInvocation
{
private
:
TestFileToWriteTo
|
undefined
;
private
:
.
ExtendedChatResponsePart
[
]
|
undefined
;
private
:
TestFileFinder
;
constructor
(
readonly
:
TestsIntent
,
readonly
:
IChatEndpoint
,
readonly
location
:
ChatLocation
,
private
readonly
:
IDocumentContext
,
private
readonly
:
.
ChatPromptReference
|
undefined
,
IInstantiationService
private
readonly
:
IInstantiationService
,
IWorkspaceService
private
readonly
:
IWorkspaceService
,
IIgnoreService
private
readonly
:
IIgnoreService
,
IParserService
private
readonly
:
IParserService
,
)
{
this
.
_testFileFinder
=
this
.
instantiationService
.
createInstance
(
TestFileFinder
)
;
}
async
buildPrompt
(
:
IBuildPromptContext
,
:
.
Progress
<
.
ChatResponseProgressPart
|
.
ChatResponseReferencePart
>
,
:
.
CancellationToken
)
{
assert
(
!
isTestFile
(
this
.
documentContext
.
document
)
,
'TestFromSourceInvocation should not be invoked from a test file'
)
;
const
=
await
this
.
findTestFileForSourceFile
(
)
;
if
(
!==
null
&&
.
kind
===
'candidateTestFile'
)
{
this
.
_testFileToWriteTo
=
{
:
'existing'
,
:
.
testExampleFile
,
}
;
}
else
{
const
=
suggestUntitledTestFileLocation
(
this
.
documentContext
.
document
)
;
this
.
_testFileToWriteTo
=
{
:
'new'
,
:
,
}
;
}
let
:
Range
;
if
(
this
.
_testFileToWriteTo
.
kind
===
'new'
)
{
=
new
Range
(
0
,
0
,
0
,
0
)
;
}
else
{
const
=
this
.
_testFileToWriteTo
.
uri
;
const
=
await
this
.
workspaceService
.
openTextDocument
(
)
;
const
=
this
.
_parserService
.
getTreeSitterAST
(
)
;
const
=
?
await
.
findLastTest
(
)
:
null
;
if
(
===
null
)
{
=
new
Range
(
.
lineCount
,
0
,
.
lineCount
,
0
)
;
}
else
{
const
=
.
positionAt
(
.
endIndex
)
;
const
=
.
line
+
1
;
=
new
Range
(
.
line
,
.
character
,
,
0
)
;
}
}
.
report
(
new
ChatResponseMovePart
(
this
.
_testFileToWriteTo
.
uri
,
)
as
any
)
;
if
(
this
.
location
===
ChatLocation
.
Panel
&&
!
.
query
)
{
=
{
...
,
:
'Write a set of detailed unit test functions for the code above.'
,
}
;
}
const
=
PromptRenderer
.
create
(
this
.
instantiationService
,
this
.
endpoint
,
Prompt
,
{
:
this
.
documentContext
,
:
this
.
endpoint
,
location
:
this
.
location
,
,
:
this
.
_testFileToWriteTo
,
,
:
this
.
alreadyConsumedChatVariable
,
}
)
;
const
=
await
.
render
(
as
any
,
)
;
return
;
}
async
processResponse
(
:
IResponseProcessorContext
,
:
AsyncIterable
<
IResponsePart
>
,
:
.
ChatResponseStream
,
:
CancellationToken
)
:
Promise
<
void
>
{
if
(
this
.
location
===
ChatLocation
.
Panel
)
{
const
=
this
.
instantiationService
.
createInstance
(
PseudoStopStartResponseProcessor
,
[
]
,
undefined
)
;
await
.
processResponse
(
,
,
,
)
;
return
;
}
const
=
this
.
documentContext
.
document
;
const
=
this
.
_additionalResponseParts
;
this
.
_additionalResponseParts
=
undefined
;
const
=
this
.
_testFileToWriteTo
?.
;
const
=
this
.
_testFileToWriteTo
?.
;
this
.
_testFileToWriteTo
=
undefined
;
if
(
===
undefined
||
===
undefined
)
{
assertType
(
,
'Expected to have a textual response without a test file'
)
;
}
else
if
(
===
'new'
)
{
const
=
new
Range
(
0
,
0
,
0
,
0
)
;
const
=
new
ProjectedDocument
(
''
,
StringEdit
.
empty
,
.
languageId
)
;
const
=
new
InlineReplyInterpreter
(
,
,
this
.
documentContext
.
fileIndentInfo
,
LeadingMarkdownStreaming
.
Emit
,
EarlyStopping
.
StopAfterFirstCodeBlock
,
(
,
)
=>
new
InsertionStreamingEdits
(
,
.
start
,
)
,
TextPieceClassifiers
.
createCodeBlockClassifier
(
)
,
=>
true
,
)
;
await
.
processResponse
(
,
,
,
)
;
}
else
{
const
=
await
this
.
workspaceService
.
openTextDocumentAndSnapshot
(
)
;
const
=
this
.
_parserService
.
getTreeSitterAST
(
)
;
const
=
?
await
.
findLastTest
(
)
:
null
;
let
:
Range
;
if
(
===
null
)
{
=
new
Range
(
.
lineCount
,
0
,
.
lineCount
,
0
)
;
}
else
{
const
=
.
positionAt
(
.
endIndex
)
;
const
=
.
line
+
1
;
=
new
Range
(
.
line
,
.
character
,
,
0
)
;
}
const
=
await
createPromptingSummarizedDocument
(
this
.
_parserService
,
,
this
.
documentContext
.
fileIndentInfo
,
,
.
getText
(
)
.
length
)
;
const
=
.
splitAroundOriginalSelectionEnd
(
)
;
const
=
'$PLACEHOLDER$'
;
const
=
.
createReplyInterpreter
(
StreamPipe
.
chain
(
=>
replaceStringInStream
(
,
'`'
+
+
'`'
,
'selection'
)
,
=>
replaceStringInStream
(
,
,
'selection'
)
,
)
,
EarlyStopping
.
StopAfterFirstCodeBlock
,
.
insertStreaming
,
TextPieceClassifiers
.
createCodeBlockClassifier
(
)
,
=>
.
value
.
trim
(
)
!==
)
;
await
.
processResponse
(
,
,
,
)
;
}
?.
forEach
(
=>
.
push
(
)
)
;
}
private
async
findTestFileForSourceFile
(
:
CancellationToken
)
:
Promise
<
TestExampleFile
|
null
>
{
let
:
'anyTestFile'
|
'candidateTestFile'
;
let
=
await
this
.
_testFileFinder
.
findTestFileForSourceFile
(
this
.
documentContext
.
document
,
)
;
if
(
.
isCancellationRequested
)
{
return
null
;
}
if
(
!==
undefined
)
{
=
'candidateTestFile'
;
}
else
{
const
=
await
this
.
_testFileFinder
.
findAnyTestFileForSourceFile
(
this
.
documentContext
.
document
,
)
;
if
(
.
isCancellationRequested
)
{
return
null
;
}
=
'anyTestFile'
;
=
;
}
if
(
===
undefined
||
(
await
this
.
ignoreService
.
isCopilotIgnored
(
)
)
)
{
return
null
;
}
return
{
,
}
;
}
}
type
Props
=
PromptElementProps
<
{
:
IDocumentContext
;
:
IChatEndpoint
;
location
:
ChatLocation
;
:
TestExampleFile
|
null
;
:
TestFileToWriteTo
;
:
IBuildPromptContext
;
:
.
ChatPromptReference
|
undefined
;
}
>
;
class
Prompt
extends
PromptElement< Props>
{
constructor
(
:
Props
,
IParserService
private
readonly
:
IParserService
,
IWorkspaceService
private
readonly
:
IWorkspaceService
)
{
super
(
)
;
}
async
render
(
:
void
,
:
PromptSizing
)
{
const
{
,
,
,
}
=
this
.
props
.
promptContext
;
const
{
,
,
,
location
,
}
=
this
.
props
;
const
=
this
.
parserService
.
getTreeSitterAST
(
.
document
)
;
let
:
.
Range
=
.
selection
;
let
:
string
|
undefined
;
let
:
string
|
undefined
;
if
(
!==
undefined
)
{
const
=
await
.
getNodeToDocument
(
toTSOffsetRange
(
.
selection
,
.
document
)
)
;
=
toRange
(
.
document
,
.
nodeToDocument
)
;
=
.
nodeIdentifier
;
=
.
nodeToDocument
.
type
;
}
const
:
ISummarizedDocumentSettings
|
undefined
=
(
[
'typescript'
,
'typescriptreact'
]
.
includes
(
.
document
.
languageId
)
&&
!==
undefined
&&
[
'class_declaration'
,
'method_definition'
]
.
includes
(
)
)
?
{
costFnOverride
:
(
:
RemovableNode
,
:
number
)
=>
{
return
!
?
:
.
kind
===
'constructor'
||
.
kind
===
'method_definition'
?
0
:
;
}
}
:
undefined
;
const
=
await
summarizeDocument
(
this
.
parserService
,
.
document
,
.
fileIndentInfo
,
,
.
tokenBudget
/
2
,
,
)
;
const
=
.
language
.
languageId
;
const
=
await
this
.
computeLangSpecificExtraGuidelines
(
,
)
;
const
=
formatRequestAndUserQuery
(
{
:
this
.
workspaceService
,
,
:
,
:
.
uri
,
,
,
}
)
;
const
=
relativeToWorkspace
(
this
.
workspaceService
,
.
document
.
uri
.
path
)
??
.
basename
(
.
document
.
uri
.
path
)
;
const
=
===
undefined
?
:
.
filter
(
=>
.
reference
!==
)
;
return
(
< >
< SystemMessage priority = { 1000 } >
You are an AI programming assistant.
< br />
< CopilotIdentityRules />
<br />
< SafetyRules />
</ SystemMessage >
< HistoryWithInstructions history = { history} passPriority historyPriority = { 700 } >
< InstructionMessage priority = { 1000 } >
{
location
===
ChatLocation
.
Editor
?
< >
The user has a
{
}
file opened in a code editor.
< br />
The user includes some code snippets from the file.
< br />
Answer with a single
{
}
code block.
</ >
:
location
===
ChatLocation
.
Panel
?
< >
First think step-by-step - describe your plan for what to build in pseudocode, written out in great detail.
< br />
Then output the code in a single code block.
< br />
Minimize any other prose.
< br />
Use Markdown formatting in your answers.
< br />
Make sure to include the programming language name at the start of the Markdown code blocks.
< br />
Avoid wrapping the whole response in triple backticks.
< br />
The user works in an IDE called Visual Studio Code which has a concept for editors with open files, integrated unit test support, an output pane that shows the output of running the code as well as an integrated terminal.
< br />
The active document is the source code the user is looking at right now.
< br />
You can only give one reply for each conversation turn.
</ >
:
undefined
}
{
.
length
>
0
&&
< >
<br />
{
}
</ >
}
</ InstructionMessage >
</ HistoryWithInstructions >
< UserMessage >
< TestDeps languageId = { languageId} priority = { 750 } />
< CustomInstructions chatVariables = { filteredChatVariables} languageId = { context. language . languageId } includeTestGenerationInstructions = { true } priority = { 725 } />
< ChatToolReferences priority = { 750 } promptContext = { this . props . promptContext } flexGrow = { 1 } />
< ChatVariables priority = { 750 } chatVariables = { filteredChatVariables} />
{
!==
null
&&
< TestExample priority = { 750 } { ... testExampleFile} />
}
< Tag name = ' currentFile' priority = { 900 } >
Here is the current file at `{srcFilePath}`:
< br />
< br />
< CodeBlock uri = { context. document . uri } languageId = { context. document . languageId } code = { summarization. text } />
<br />
< br />
{
}
</ Tag >
</ UserMessage >
</ >
)
;
}
private
async
computeLangSpecificExtraGuidelines
(
:
IDocumentContext
,
:
TestExampleFile
|
null
)
:
Promise
<
string
>
{
const
=
[
]
;
if
(
.
document
.
languageId
===
'python'
)
{
const
=
!==
null
&&
.
kind
===
'candidateTestFile'
;
if
(
!
)
{
.
push
(
'Make sure your answer imports the function to test as this is a total new file.'
)
;
const
:
string
=
.
dirname
(
.
document
.
uri
.
fsPath
)
;
const
:
string
=
.
join
(
,
'__init__.py'
)
;
const
:
URI
|
undefined
=
this
.
workspaceService
.
getWorkspaceFolder
(
.
document
.
uri
)
;
try
{
await
this
.
workspaceService
.
openTextDocument
(
Uri
.
file
(
)
)
;
if
(
!==
undefined
&&
.
resolve
(
)
===
.
resolve
(
?.
??
''
)
)
{
.
push
(
'The file is in the root of the workspace, which has an __init__.py but use an absolute import to import the function to test.'
)
;
}
else
{
.
push
(
'The parent directory of the given file has an __init__.py file making it a regular package. Use a relative import to import the function to test.'
)
;
}
}
catch
(
)
{
.
push
(
'The parent directory of the given file has no __init__.py file making it a namespace package. Use an absolute import to import the function to test.'
)
;
}
}
}
return
.
join
(
'\n'
)
;
}
}