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 / prompts / node / panel / fileVariable.tsx 383 строк · изменён 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
import * as l10n from '@vscode/l10n' ;
import { BasePromptElementProps , ChatResponseReferencePartStatusKind , Document , Image , PromptElement , PromptReference , PromptSizing } from '@vscode/prompt-tsx' ;
import { UserMessage } from '@vscode/prompt-tsx/dist/base/promptElements' ;
import { AbstractDocumentWithLanguageId } from '../../../../platform/editing/common/abstractText' ;
import { NotebookDocumentSnapshot
variableName
variableValue
filePathMode
lineNumberStyle
alwaysIncludeSummary
omitReferences
description
omitContents
props
@ workspaceService
@ ignoreService
@ fileService
@ notebookService
@ alternativeNotebookContent
@ promptEndpoint
@ promptPathRepresentationService
props
override _state sizing
uri
uri
uri doc doc uri
filePath uri
attrs
attrs
attrs filePath
uri
options status description l10n kind
buffer uri
base64string buffer
err
uri
options status description l10n kind
buffer uri
buffer buffer buffer buffer buffer
options status description l10n kind
base64string buffer
err
options status description l10n kind
binary uri openTextDocuments
binary
range
documentSnapshot
fileUri uri
uri
items uri
items
outputCell items
outputCell outputCell
options status description l10n kind
uri uri
notebook cell uri
notebook
fileUri notebook
cell
cellRange cell cell cell
range range cellRange
range cellRange range cellRange
range cellRange
altDocument notebook
range altDocument cell range altDocument cell range
range
documentSnapshot fileUri
fileUri
fileUri
err
options status description l10n err kind
range range documentSnapshot documentSnapshot uri
range
selectionDesc
summaryDesc
variableName
range
filePathMode
omitReferences
description
override _state sizing
range
uri
references range uri range uri
uri range
variableName
range
filePathMode
lineNumberStyle
omitReferences
description
props
@ instantiationService
@ _promptPathRepresentationService
props
override _state sizing
range
uri
lineNumberStyle
summarized
range sizing
costFnOverride fileVariableCostFn
lineNumberStyle
range sizing
costFnOverride fileVariableCostFn
lineNumberStyle
code summarized summarized
promptReferenceOptions summarized
status description l10n kind
references uri promptReferenceOptions
attrs
attrs
summarized
attrs
attrs uri
summarized
lines summarized
lineNumberWidth lines
lines line index
lineNumber
summarized
lineNumber index
offset summarized index
originalPosition summarized summarized offset
lineNumber originalPosition
fileVariableCostFn
doc
nodeMultiplier node
doc
parentCost node nodeMultiplier node
nodeText node
nodeText parentCost
nodeText nodeText parentCost
node currentCost
node
currentCost
node
m nodeMultiplier node
currentCost m
}
from
'../../../../platform/editing/common/notebookDocumentSnapshot'
;
import
{ TextDocumentSnapshot }
from
'../../../../platform/editing/common/textDocumentSnapshot'
;
import
{ modelSupportsPDFDocuments }
from
'../../../../platform/endpoint/common/chatModelCapabilities'
;
import
{ IFileSystemService }
from
'../../../../platform/filesystem/common/fileSystemService'
;
import
{ IIgnoreService }
from
'../../../../platform/ignore/common/ignoreService'
;
import
{ IAlternativeNotebookContentService }
from
'../../../../platform/notebook/common/alternativeContent'
;
import
{ INotebookService }
from
'../../../../platform/notebook/common/notebookService'
;
import
{ IPromptPathRepresentationService }
from
'../../../../platform/prompts/common/promptPathRepresentationService'
;
import
{ IWorkspaceService }
from
'../../../../platform/workspace/common/workspaceService'
;
import
{ getNotebookAndCellFromUri, getNotebookCellOutput }
from
'../../../../util/common/notebooks'
;
import
{ isUri }
from
'../../../../util/common/types'
;
import
{ CachedFunction }
from
'../../../../util/vs/base/common/cache'
;
import
{ Schemas }
from
'../../../../util/vs/base/common/network'
;
import
{ basename }
from
'../../../../util/vs/base/common/resources'
;
import
{ splitLines }
from
'../../../../util/vs/base/common/strings'
;
import
{ IInstantiationService }
from
'../../../../util/vs/platform/instantiation/common/instantiation'
;
import
{ Location , Position , Range , Uri }
from
'../../../../vscodeTypes'
;
import
{ IPromptEndpoint }
from
'../base/promptRenderer'
;
import
{ Tag }
from
'../base/tag'
;
import
{ SummarizedDocumentLineNumberStyle }
from
'../inline/summarizedDocument/implementation'
;
import
{ ICostFnFactory , ProjectedDocument , RemovableNode }
from
'../inline/summarizedDocument/summarizeDocument'
;
import
{ DocumentSummarizer , NotebookDocumentSummarizer }
from
'../inline/summarizedDocument/summarizeDocumentHelpers'
;
import
{ BinaryFileHexdump , hexdumpIfBinary }
from
'./binaryFileHexdump'
;
import
{ CodeBlock }
from
'./safeElements'
;
export
interface
FileVariableProps
extends
BasePromptElementProps
{
:
string
;
:
Uri
|
Location
;
?
:
FilePathMode
;
?
:
SummarizedDocumentLineNumberStyle
|
'legacy'
;
?
:
boolean
;
?
:
boolean
;
?
:
string
;
?
:
boolean
;
}
export
class
FileVariable
extends
PromptElement< FileVariableProps, unknown >
{
constructor
(
:
FileVariableProps
,
IWorkspaceService
private
readonly
:
IWorkspaceService
,
IIgnoreService
private
readonly
:
IIgnoreService
,
IFileSystemService
private
readonly
:
IFileSystemService
,
INotebookService
private
readonly
:
INotebookService
,
IAlternativeNotebookContentService
private
readonly
:
IAlternativeNotebookContentService
,
IPromptEndpoint
private
readonly
:
IPromptEndpoint
,
IPromptPathRepresentationService
private
readonly
:
IPromptPathRepresentationService
,
)
{
super
(
)
;
}
async
render
(
:
unknown
,
:
PromptSizing
)
{
const
=
'uri'
in
this
.
props
.
variableValue
?
this
.
props
.
variableValue
.
uri
:
this
.
props
.
variableValue
;
if
(
await
this
.
ignoreService
.
isCopilotIgnored
(
)
)
{
return
< ignoredFiles value = { [ uri] } />
;
}
if
(
.
scheme
===
'untitled'
&&
!
this
.
workspaceService
.
textDocuments
.
some
(
=>
.
uri
.
toString
(
)
===
.
toString
(
)
)
)
{
return
;
}
if
(
this
.
props
.
omitContents
)
{
const
=
this
.
promptPathRepresentationService
.
getFilePath
(
)
;
const
:
Record
<
string
,
string
>
=
{
}
;
if
(
this
.
props
.
variableName
)
{
.
id
=
this
.
props
.
variableName
;
}
.
filePath
=
;
return
(
< Tag name = ' attachment' attrs = { attrs} />
)
;
}
if
(
/ \. ( png| jpg| jpeg| bmp| gif| webp) $ / i
.
test
(
.
path
)
)
{
const
=
{
:
{
:
.
t
(
"{0} does not support images."
,
this
.
promptEndpoint
.
model
)
,
:
ChatResponseReferencePartStatusKind
.
Omitted
}
}
;
if
(
this
.
props
.
omitReferences
)
{
return
;
}
if
(
!
this
.
promptEndpoint
.
supportsVision
)
{
return
(
< >
< references value = { [ new PromptReference ( this . props . variableName ? { variableName: this . props . variableName , value: uri } : uri, undefined , options) ] } />
</ >
)
;
}
try
{
const
=
await
this
.
fileService
.
readFile
(
)
;
const
=
Buffer
.
from
(
)
.
toString
(
'base64'
)
;
return
(
< UserMessage priority = { 0 } >
< Image src = { base64string} detail = { 'high' } />
< references value = { [ new PromptReference ( this . props . variableName ? { variableName: this . props . variableName , value: uri } : uri, undefined , options) ] } />
</ UserMessage >
)
;
}
catch
(
)
{
return
(
< >
< references value = { [ new PromptReference ( this . props . variableName ? { variableName: this . props . variableName , value: uri } : uri, undefined , options) ] } />
</ >
)
;
}
}
if
(
/ \. pdf$ / i
.
test
(
.
path
)
)
{
if
(
!
this
.
promptEndpoint
.
supportsVision
||
!
modelSupportsPDFDocuments
(
this
.
promptEndpoint
)
)
{
if
(
this
.
props
.
omitReferences
)
{
return
;
}
const
=
{
:
{
:
.
t
(
"{0} does not support PDF documents."
,
this
.
promptEndpoint
.
model
)
,
:
ChatResponseReferencePartStatusKind
.
Omitted
}
}
;
return
(
< >
< references value = { [ new PromptReference ( this . props . variableName ? { variableName: this . props . variableName , value: uri } : uri, undefined , options) ] } />
</ >
)
;
}
try
{
const
=
await
this
.
fileService
.
readFile
(
)
;
if
(
.
length
<
4
||
[
0
]
!==
0x25
||
[
1
]
!==
0x50
||
[
2
]
!==
0x44
||
[
3
]
!==
0x46
)
{
if
(
this
.
props
.
omitReferences
)
{
return
;
}
const
=
{
:
{
:
.
t
(
"File is not a valid PDF."
)
,
:
ChatResponseReferencePartStatusKind
.
Omitted
}
}
;
return
(
< >
< references value = { [ new PromptReference ( this . props . variableName ? { variableName: this . props . variableName , value: uri } : uri, undefined , options) ] } />
</ >
)
;
}
const
=
Buffer
.
from
(
)
.
toString
(
'base64'
)
;
return
(
< UserMessage priority = { 0 } >
< Document data = { base64string} mediaType = ' application/pdf' />
{
!
this
.
props
.
omitReferences
&&
< references value = { [ new PromptReference ( this . props . variableName ? { variableName: this . props . variableName , value: uri } : uri) ] } />
}
</ UserMessage >
)
;
}
catch
(
)
{
if
(
this
.
props
.
omitReferences
)
{
return
;
}
const
=
{
:
{
:
.
t
(
"Failed to read PDF file."
)
,
:
ChatResponseReferencePartStatusKind
.
Omitted
}
}
;
return
(
< >
< references value = { [ new PromptReference ( this . props . variableName ? { variableName: this . props . variableName , value: uri } : uri, undefined , options) ] } />
</ >
)
;
}
}
const
=
await
hexdumpIfBinary
(
this
.
fileService
,
,
{
:
this
.
workspaceService
.
textDocuments
}
)
;
if
(
)
{
return
< BinaryFileHexdump uri = { uri} data = { binary. data } variableName = { this . props . variableName } description = { this . props . description } omitReferences = { this . props . omitReferences } />
;
}
let
=
isUri
(
this
.
props
.
variableValue
)
?
undefined
:
this
.
props
.
variableValue
.
range
;
let
:
TextDocumentSnapshot
|
NotebookDocumentSnapshot
;
let
:
Uri
=
;
if
(
.
scheme
===
Schemas
.
vscodeNotebookCellOutput
)
{
const
=
getNotebookCellOutput
(
,
this
.
workspaceService
.
notebookDocuments
)
;
if
(
!
)
{
return
;
}
const
=
[
2
]
;
if
(
.
items
.
length
>
0
&&
.
items
[
0
]
.
mime
.
startsWith
(
'image/'
)
&&
!
this
.
promptEndpoint
.
supportsVision
)
{
const
=
{
:
{
:
.
t
(
"{0} does not support images."
,
this
.
promptEndpoint
.
model
)
,
:
ChatResponseReferencePartStatusKind
.
Omitted
}
}
;
if
(
this
.
props
.
omitReferences
)
{
return
;
}
return
(
< >
< references value = { [ new PromptReference ( this . props . variableName ? { variableName: this . props . variableName , value: this . props . variableValue } : this . props . variableValue , undefined , options) ] } />
</ >
)
;
}
}
if
(
.
scheme
===
Schemas
.
vscodeNotebookCell
||
.
scheme
===
Schemas
.
vscodeNotebookCellOutput
)
{
const
[
,
]
=
getNotebookAndCellFromUri
(
,
this
.
workspaceService
.
notebookDocuments
)
;
if
(
!
)
{
return
;
}
=
.
uri
;
if
(
)
{
const
=
new
Range
(
.
document
.
lineAt
(
0
)
.
range
.
start
,
.
document
.
lineAt
(
.
document
.
lineCount
-
1
)
.
range
.
end
)
;
=
??
;
if
(
.
start
>
.
end
||
.
end
<
.
start
)
{
=
;
}
const
=
this
.
alternativeNotebookContent
.
create
(
this
.
alternativeNotebookContent
.
getFormat
(
this
.
promptEndpoint
)
)
.
getAlternativeDocument
(
)
;
=
new
Range
(
.
fromCellPosition
(
,
.
start
)
,
.
fromCellPosition
(
,
.
end
)
)
;
}
else
{
=
undefined
;
}
}
try
{
=
this
.
notebookService
.
hasSupportedNotebooks
(
)
?
await
this
.
workspaceService
.
openNotebookDocumentAndSnapshot
(
,
this
.
alternativeNotebookContent
.
getFormat
(
this
.
promptEndpoint
)
)
:
await
this
.
workspaceService
.
openTextDocumentAndSnapshot
(
)
;
}
catch
(
)
{
const
=
{
:
{
:
.
t
(
'This file could not be read: {0}'
,
.
message
)
,
:
ChatResponseReferencePartStatusKind
.
Omitted
}
}
;
if
(
this
.
props
.
omitReferences
)
{
return
;
}
return
(
< >
< references value = { [ new PromptReference ( this . props . variableName ? { variableName: this . props . variableName , value: this . props . variableValue } : this . props . variableValue , undefined , options) ] } />
</ >
)
;
}
if
(
(
&&
(
!
this
.
props
.
alwaysIncludeSummary
||
.
isEqual
(
new
Range
(
new
Position
(
0
,
0
)
,
.
lineAt
(
.
lineCount
-
1
)
.
range
.
end
)
)
)
)
||
/ \. ( svg) $ / i
.
test
(
.
path
)
)
{
return
< CodeSelection variableName = { this . props . variableName } document = { documentSnapshot} range = { range} filePathMode = { this . props . filePathMode } omitReferences = { this . props . omitReferences } description = { this . props . description } />
;
}
if
(
)
{
const
=
this
.
props
.
description
?
this
.
props
.
description
:
` `
;
const
=
` User's active file for additional context `
;
return
(
< >
< CodeSelection variableName = { this . props . variableName } document = { documentSnapshot} range = { range} filePathMode = { this . props . filePathMode } omitReferences = { this . props . omitReferences } description = { selectionDesc} />
< CodeSummary flexGrow = { 1 } variableName = { '' } document = { documentSnapshot} range = { range} filePathMode = { this . props . filePathMode } lineNumberStyle = { this . props . lineNumberStyle } omitReferences = { this . props . omitReferences } description = { summaryDesc} />
</ >
)
;
}
return
< CodeSummary variableName = { this . props . variableName } document = { documentSnapshot} range = { range} filePathMode = { this . props . filePathMode } lineNumberStyle = { this . props . lineNumberStyle } omitReferences = { this . props . omitReferences } description = { this . props . description } />
;
}
}
interface
CodeSelectionProps
extends
BasePromptElementProps
{
:
string
;
document
:
TextDocumentSnapshot
|
NotebookDocumentSnapshot
;
?
:
Range
;
?
:
FilePathMode
;
?
:
boolean
;
?
:
string
;
}
class
CodeSelection
extends
PromptElement< CodeSelectionProps, unknown >
{
async
render
(
:
unknown
,
:
PromptSizing
)
{
const
{
document
,
}
=
this
.
props
;
const
{
}
=
document
;
const
=
this
.
props
.
omitReferences
?
undefined
:
[
new
PromptReference
(
?
new
Location
(
,
)
:
)
]
;
return
(
< Tag name = ' attachment' attrs = { this . props . variableName ? { id: this . props . variableName } : undefined } >
{
this
.
props
.
description
?
this
.
props
.
description
+
':\n'
:
''
}
Excerpt from
{
basename
(
)
}
{
?
` , lines ${ range. start. line + 1 } to ${ range. end. line + 1 } `
:
''
}
:
< CodeBlock includeFilepath = { this . props . filePathMode === FilePathMode . AsComment } languageId = { document . languageId } uri = { uri} references = { references} code = { document . getText ( range) } />
</ Tag >
)
;
}
}
export
enum
FilePathMode
{
AsAttribute
,
AsComment
,
None
}
interface
CodeSummaryProps
extends
BasePromptElementProps
{
:
string
;
document
:
TextDocumentSnapshot
|
NotebookDocumentSnapshot
;
?
:
Range
;
?
:
FilePathMode
;
?
:
SummarizedDocumentLineNumberStyle
|
'legacy'
;
?
:
boolean
;
?
:
string
;
}
class
CodeSummary
extends
PromptElement< CodeSummaryProps, unknown >
{
constructor
(
:
CodeSummaryProps
,
IInstantiationService
private
readonly
:
IInstantiationService
,
IPromptPathRepresentationService
private
readonly
:
IPromptPathRepresentationService
,
)
{
super
(
)
;
}
async
render
(
:
unknown
,
:
PromptSizing
)
{
const
{
document
,
}
=
this
.
props
;
const
{
}
=
document
;
const
=
this
.
props
.
lineNumberStyle
===
'legacy'
?
undefined
:
this
.
props
.
lineNumberStyle
;
const
=
document
instanceof
TextDocumentSnapshot
?
await
this
.
instantiationService
.
createInstance
(
DocumentSummarizer
)
.
summarizeDocument
(
document
,
undefined
,
,
.
tokenBudget
,
{
:
,
,
}
)
:
await
this
.
instantiationService
.
createInstance
(
NotebookDocumentSummarizer
)
.
summarizeDocument
(
document
,
undefined
,
,
.
tokenBudget
,
{
:
,
,
}
)
;
const
=
this
.
props
.
lineNumberStyle
===
'legacy'
?
this
.
includeLineNumbers
(
)
:
.
text
;
const
=
!
.
isOriginal
?
{
:
{
:
.
t
(
'Part of this file was not sent to the model due to context window limitations. Try attaching specific selections from your file instead.'
)
,
:
2
}
}
:
undefined
;
const
=
this
.
props
.
omitReferences
?
undefined
:
[
new
PromptReference
(
,
undefined
,
)
]
;
const
:
Record
<
string
,
string
>
=
{
}
;
if
(
this
.
props
.
variableName
)
{
.
id
=
this
.
props
.
variableName
;
}
if
(
!
.
isOriginal
)
{
.
isSummarized
=
'true'
;
}
if
(
this
.
props
.
filePathMode
===
FilePathMode
.
AsAttribute
)
{
.
filePath
=
this
.
_promptPathRepresentationService
.
getFilePath
(
)
;
}
return
(
< Tag name = ' attachment' attrs = { attrs} >
{
this
.
props
.
description
?
this
.
props
.
description
+
':\n'
:
''
}
< CodeBlock includeFilepath = { this . props . filePathMode === FilePathMode . AsComment } languageId = { document . languageId } uri = { uri} references = { references} code = { code} fence = ' ' />
</ Tag >
)
;
}
private
includeLineNumbers
(
:
ProjectedDocument
)
:
string
{
const
=
splitLines
(
.
text
)
;
const
=
.
length
.
toString
(
)
.
length
;
return
.
map
(
(
,
)
=>
{
let
:
number
;
if
(
.
isOriginal
)
{
=
;
}
else
{
const
=
.
positionOffsetTransformer
.
getOffset
(
new
Position
(
,
0
)
)
;
const
=
.
originalPositionOffsetTransformer
.
getPosition
(
.
projectBack
(
)
)
;
=
.
line
;
}
return
` ${ ( lineNumber + 1 ) . toString ( ) . padStart ( lineNumberWidth) } : ${ line} `
;
}
)
.
join
(
'\n'
)
;
}
}
export
const
:
ICostFnFactory
<
AbstractDocumentWithLanguageId
>
=
{
createCostFn
(
)
{
const
:
CachedFunction
<
RemovableNode
,
number
>
=
new
CachedFunction
(
=>
{
if
(
.
languageId
===
'typescript'
)
{
const
=
.
parent
?
.
get
(
.
parent
)
:
1
;
const
=
.
text
.
trim
(
)
;
if
(
.
startsWith
(
'private '
)
)
{
return
*
1.1
;
}
if
(
.
startsWith
(
'export '
)
||
.
startsWith
(
'public '
)
)
{
return
*
0.9
;
}
}
return
1
;
}
)
;
return
(
,
)
=>
{
if
(
!
)
{
return
;
}
if
(
.
kind
===
'import_statement'
)
{
return
1000
;
}
const
=
.
get
(
)
;
return
*
;
}
;
}
,
}
;