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 / testing / node / setupTestsFileManager.tsx 346 строк · изменён 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
import * as l10n from '@vscode/l10n' ;
import { BasePromptElementProps , PromptElement , PromptPiece , PromptSizing , SystemMessage , UserMessage } from '@vscode/prompt-tsx' ;
import type * as vscode from 'vscode' ;
import { ChatFetchResponseType , ChatLocation } from '../../../platform/chat/common/commonTypes' ;
import { TextDocumentSnapshot } from
_serviceBrand
requests
@ instantiationService
requestId options
mut options
requestId mut
mut
requestId
req requestId
req
l10n
req
fileDescriptions
fileContents
applied
opts
@ fileSystemService
@ endpointProvider
@ instantiationService
@ workspaceService
@ promptPathRepresentationService
file
file file
res file
index file
index index
res index
res
progress vscode message token
l10n
file
token
progress message l10n file
contents file
file contents
progress message l10n
e
e
file
prev file
prev
prev
promise file
file promise
promise
file
descriptions
file
originalText
endpoint
promptRenderer endpoint
file
allInstructions descriptions response
fileTree
query
instructionsForThisFile descriptions perFile f f file description
prompt promptRenderer
fetchResult endpoint
prompt
fetchResult
file
l10n fetchResult fetchResult
originalText
reply fetchResult originalText
originalText reply
fetchResult
endpoint
promptRenderer endpoint
fileTreeStr
query
prompt promptRenderer
fetchResult endpoint
prompt
fetchResult
out file description
file description fetchResult
out file description
perFile out response fetchResult
query
fileTreeStr
override
file
query
fileTree
allInstructions
instructionsForThisFile
override
file query fileTree allInstructions instructionsForThisFile
changes
uri
find
replace
query instructionsForThisFile
instructionsForThisFile
allInstructions fileTree
props
@ parserService
props
override state sizing
codeExcerpt
sizing
'../../../platform/editing/common/textDocumentSnapshot'
;
import
{ IEndpointProvider }
from
'../../../platform/endpoint/common/endpointProvider'
;
import
{ IFileSystemService }
from
'../../../platform/filesystem/common/fileSystemService'
;
import
{ IParserService }
from
'../../../platform/parser/node/parserService'
;
import
{ IPromptPathRepresentationService }
from
'../../../platform/prompts/common/promptPathRepresentationService'
;
import
{ IWorkspaceMutation , IWorkspaceMutationManager , IWorkspaceMutationOptions }
from
'../../../platform/testing/common/workspaceMutationManager'
;
import
{ IWorkspaceService }
from
'../../../platform/workspace/common/workspaceService'
;
import
{ CancellationToken }
from
'../../../util/vs/base/common/cancellation'
;
import
{ Iterable }
from
'../../../util/vs/base/common/iterator'
;
import
{
URI
}
from
'../../../util/vs/base/common/uri'
;
import
{ IInstantiationService }
from
'../../../util/vs/platform/instantiation/common/instantiation'
;
import
{ Range }
from
'../../../vscodeTypes'
;
import
{ applyEdits }
from
'../../prompt/node/intents'
;
import
{ CopilotIdentityRules }
from
'../../prompts/node/base/copilotIdentity'
;
import
{ PromptRenderer }
from
'../../prompts/node/base/promptRenderer'
;
import
{ ResponseTranslationRules }
from
'../../prompts/node/base/responseTranslationRules'
;
import
{ SafetyRules }
from
'../../prompts/node/base/safetyRules'
;
import
{ PatchEditExamplePatch , PatchEditRules , getPatchEditReplyProcessor }
from
'../../prompts/node/codeMapper/patchEditGeneration'
;
import
{ summarizeDocument }
from
'../../prompts/node/inline/summarizedDocument/summarizeDocumentHelpers'
;
import
{ CodeBlock }
from
'../../prompts/node/panel/safeElements'
;
const
KEEP_LAST_N
=
5
;
export
class
WorkspaceMutationManager
implements
IWorkspaceMutationManager
{
declare
readonly
:
undefined
;
private
readonly
=
new
Map< string , IWorkspaceMutation>
(
)
;
constructor
(
IInstantiationService
private
readonly
:
IInstantiationService
,
)
{
}
create
(
:
string
,
:
IWorkspaceMutationOptions
)
:
IWorkspaceMutation
{
const
=
this
.
instantiationService
.
createInstance
(
WorkspaceMutation
,
)
;
this
.
requests
.
set
(
,
)
;
if
(
this
.
requests
.
size
>
KEEP_LAST_N
)
{
this
.
requests
.
delete
(
Iterable
.
first
(
this
.
requests
.
keys
(
)
)
!
)
;
}
return
;
}
get
(
:
string
)
:
IWorkspaceMutation
{
const
=
this
.
requests
.
get
(
)
;
if
(
!
)
{
throw
new
Error
(
.
t
(
` No request found, or it has expired. Please re-submit your query. `
)
)
;
}
return
;
}
}
class
WorkspaceMutation
implements
IWorkspaceMutation
{
private
readonly
=
this
.
getFileDescriptions
(
)
;
private
readonly
=
new
Map< string , Promise < string >>
(
)
;
private
=
false
;
constructor
(
public
readonly
:
IWorkspaceMutationOptions
,
IFileSystemService
private
readonly
:
IFileSystemService
,
IEndpointProvider
private
readonly
:
IEndpointProvider
,
IInstantiationService
private
readonly
:
IInstantiationService
,
IWorkspaceService
private
readonly
:
IWorkspaceService
,
IPromptPathRepresentationService
private
readonly
:
IPromptPathRepresentationService
)
{
this
.
fileDescriptions
=
this
.
getFileDescriptions
(
)
;
}
public
get
(
:
string
)
{
=
.
replaceAll
(
'\\'
,
'/'
)
.
replace
(
/ ^ \/ /
,
''
)
;
const
=
this
.
getInner
(
)
;
const
=
this
.
opts
.
files
.
indexOf
(
)
;
if
(
!==
-
1
&&
<
this
.
opts
.
files
.
length
-
1
)
{
.
then
(
(
)
=>
this
.
getInner
(
this
.
opts
.
files
[
+
1
]
)
)
;
}
return
;
}
public
async
apply
(
:
undefined
|
.
Progress
<
{
:
string
}
>
,
:
CancellationToken
)
:
Promise
<
void
>
{
if
(
this
.
applied
)
{
throw
new
Error
(
.
t
(
'Edits have already been applied'
)
)
;
}
try
{
this
.
applied
=
true
;
for
(
const
of
this
.
opts
.
files
)
{
if
(
.
isCancellationRequested
)
{
return
;
}
?.
report
(
{
:
.
t
(
'Generating {0}'
,
)
}
)
;
const
=
await
this
.
getInner
(
)
;
await
this
.
fileSystemService
.
writeFile
(
URI
.
joinPath
(
this
.
opts
.
baseURI
,
)
,
new
TextEncoder
(
)
.
encode
(
)
)
;
}
?.
report
(
{
:
.
t
(
'Edits applied successfully'
)
}
)
;
}
catch
(
)
{
this
.
applied
=
false
;
throw
;
}
}
private
async
getInner
(
:
string
)
{
const
=
this
.
fileContents
.
get
(
)
;
if
(
)
{
return
;
}
const
=
this
.
generateContent
(
)
;
this
.
fileContents
.
set
(
,
)
;
return
;
}
private
async
generateContent
(
:
string
)
{
const
=
await
this
.
fileDescriptions
;
let
document
:
TextDocumentSnapshot
|
undefined
;
try
{
document
=
await
this
.
workspaceService
.
openTextDocumentAndSnapshot
(
URI
.
joinPath
(
this
.
opts
.
baseURI
,
)
)
;
}
catch
{
}
const
=
document
?.
getText
(
)
;
const
=
await
this
.
endpointProvider
.
getChatEndpoint
(
'copilot-utility-small'
)
;
const
=
PromptRenderer
.
create
(
this
.
instantiationService
,
,
WorkspaceMutationFilePrompt
,
{
,
document
,
:
?.
,
:
this
.
opts
.
fileTree
,
:
this
.
opts
.
query
,
:
?.
.
find
(
=>
.
file
===
)
?.
,
}
)
;
const
=
await
.
render
(
)
;
const
=
await
.
makeChatRequest
(
'workspaceMutationFileGenerator'
,
.
messages
,
undefined
,
CancellationToken
.
None
,
ChatLocation
.
Other
)
;
if
(
.
type
!==
ChatFetchResponseType
.
Success
)
{
this
.
fileContents
.
delete
(
)
;
throw
new
Error
(
.
t
(
'Encountered an error while generating the file: ({0}) {1}'
,
.
type
,
.
reason
)
)
;
}
if
(
&&
document
)
{
const
=
getPatchEditReplyProcessor
(
this
.
promptPathRepresentationService
)
.
process
(
.
value
,
,
document
.
uri
)
;
return
applyEdits
(
,
.
edits
)
;
}
return
.
value
;
}
private
async
getFileDescriptions
(
)
{
const
=
await
this
.
endpointProvider
.
getChatEndpoint
(
'copilot-utility-small'
)
;
const
=
PromptRenderer
.
create
(
this
.
instantiationService
,
,
WorkspaceMutationInstructionsPrompt
,
{
:
this
.
opts
.
fileTree
,
:
this
.
opts
.
query
,
}
)
;
const
=
await
.
render
(
)
;
const
=
await
.
makeChatRequest
(
'workspaceMutationSummarizer'
,
.
messages
,
undefined
,
CancellationToken
.
None
,
ChatLocation
.
Other
,
)
;
if
(
.
type
!==
ChatFetchResponseType
.
Success
)
{
return
undefined
;
}
const
:
{
:
string
;
:
string
}
[
]
=
[
]
;
for
(
const
[
,
,
]
of
.
value
.
matchAll
(
/ ^ `? ( . *? ) `? :\s * ( . + ) $ / gm
)
)
{
.
push
(
{
,
}
)
;
}
return
{
:
,
:
.
value
}
;
}
}
interface
WorkspaceMutationInstructionsPromptArgs
extends
BasePromptElementProps
{
:
string
;
:
string
;
}
class
WorkspaceMutationInstructionsPrompt
extends
PromptElement< WorkspaceMutationInstructionsPromptArgs>
{
render
(
)
:
PromptPiece
<
any
,
any
>
|
undefined
{
return
(
< >
< SystemMessage priority = { 1000 } >
You are a VS Code assistant. Your job is to generate the project specification when given the user description and file tree structure of the project that a user wants to create.
< br />
< CopilotIdentityRules />
< SafetyRules />
< ResponseTranslationRules />
< br />
Additional Rules<br />
You will be given a user query and a tree of files they wish to edit or create in order to accomplish a task.
Think step by step and respond with a text description that lists and summarizes what needs to be done in each file to accomplish the user's task.
< br />
Below you will find a set of examples of what you should respond with. Please follow these examples as closely as possible.
< br />
< br />
## Valid question<br />
User: I want to: add the sequelize ORM to my project and add a user model<br />
This is the project tree structure:
< br />
```markdown <br />
my-express-app<br />
├── src<br />
│ └── models<br />
│ └── user.ts<br />
├── package.json<br />
└── README.md<br />
```
< br />
## Valid response<br />
`src/models/user.ts`: This file defines and exports the User model for use in the application.
< br />
`src/routes/index.ts`: This file exports a function `setRoutes` which sets up the routes for the application. It uses the `IndexController` to handle the root route.
< br />
`package.json`: We need to edit the package.json to ensure Sequelize is defined as a dependency<br />
`README.md`: We should add documentation to the readme file to make consumers aware of the new setup steps.
< br />
</ SystemMessage >
< UserMessage priority = { 900 } >
I want to:
{
this
.
props
.
query
}
< br />
This is the project tree structure:
< br />
```markdown' <br />
{this.props.fileTreeStr}<br />
```
< br />
</ UserMessage >
</ >
)
;
}
}
interface
WorkspaceFileMutationPromptArgs
extends
BasePromptElementProps
{
:
string
;
:
string
;
:
string
;
:
string
|
undefined
;
?
:
string
;
document
?
:
TextDocumentSnapshot
;
}
class
WorkspaceMutationFilePrompt
extends
PromptElement< WorkspaceFileMutationPromptArgs>
{
render
(
)
:
PromptPiece
<
any
,
any
>
|
undefined
{
const
{
,
,
,
,
,
document
}
=
this
.
props
;
return
(
< >
< SystemMessage priority = { 1000 } >
You are a VS Code assistant. Your job is to generate the project specification when given the user description and file tree structure of the project that a user wants to create.
< br />
< CopilotIdentityRules />
< SafetyRules />
< ResponseTranslationRules />
< br />
Additional Rules<br />
The user will describe the task they're trying to accomplish, and ask you to generate or edit a file in persuit of that task.
< br />
{
document
?
< PatchEditRules />
:
< >
Print the entire contents of the file you propose.
< br />
If asked to generate a test file, create a file with a self-contained 'hello world' test case without dependency on any other files or imports aside from the testing framwork.
< br />
</ >
}
Do not include comments in json files.
< br />
Do not use code blocks or backticks.
< br />
Do not include any other explanation.
< br />
< br />
{
document
?
<
PatchEditExamplePatch
=
{
[
{
:
URI
.
file
(
'/package.json'
)
,
:
[
'"dependencies": {'
,
' "typescript": "^4.5.4",'
]
,
:
[
'"dependencies": {'
,
' "mocha": "latest"'
,
' "typescript": "^4.5.4",'
]
,
}
]
}
/
>
:
< >
# Example<br />
## Question:
< br />
I want to: set up mocha in my workspace<br />
Please print the contents of the file `src/index.test.ts`
< br />
## Response:
{
`
const assert = require('assert');
test('hello world!', () => {
assert.strictEqual(1 + 1, 2);
});
`
}
</ >
}
</ SystemMessage >
< UserMessage priority = { 900 } >
I want to:
{
}
< br />
Please print the contents of the file `{file}`
< br />
{
?
< >
Description of this file:
{
}
</ >
:
< >
Here are the files in my workspace, including this one:
{
}
`</>}<br />
This is the project tree structure:<br />
```filetree<br />
{
}
< br />
```
< br />
< br />
{
document
&&
< WorkspaceMutationFileContents flexGrow = { 1 } document = { document } />
}
</ UserMessage >
</ >
)
;
}
}
interface WorkspaceMutationFileContentsProps extends BasePromptElementProps
{
document
:
TextDocumentSnapshot
;
}
class WorkspaceMutationFileContents extends PromptElement<WorkspaceMutationFileContentsProps>
{
constructor
(
:
WorkspaceMutationFileContentsProps
,
IParserService
private
readonly
:
IParserService
,
)
{
super
(
)
;
}
async
render
(
:
void
,
:
PromptSizing
)
:
Promise
<
PromptPiece
>
{
const
{
document
}
=
this
.
props
;
const
=
await
summarizeDocument
(
this
.
parserService
,
document
,
undefined
,
new
Range
(
0
,
0
,
0
,
0
)
,
.
tokenBudget
*
(
2
/
3
)
)
;
return
< CodeBlock uri = { document . uri } languageId = { document . languageId } code = { codeExcerpt. text } />
;
}
}