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 / inline / inlineChatNotebookFixPrompt.tsx 401 строк · изменён 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
import { BasePromptElementProps , PromptElement , PromptSizing , SystemMessage , UserMessage } 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 { ILanguageDiagnosticsService , rangeSpanningDiagnostics } from '../../../../platform/languages/common/languageDiagnosticsService'
isIgnored
priorities
props
@ _ignoreService
@ _instantiationService
@ _languageDiagnosticsService
@ _parserService
@ _tabsAndEditorsService
@ _workspaceService
@ _promptEndpoint
props
override sizing
documentContext context
isIgnored context
isIgnored
priorities promptPriorities
state sizing
documentContext
documentContext
state
query history chatVariables
selection documentContext
diagnostics documentContext documentContext query
range diagnostics diagnostics documentContext
treeSitterAST documentContext
rangeOfInterest treeSitterAST treeSitterAST range range
fixContext documentContext range rangeOfInterest
inputDocCharLimit sizing
projectedDocument
isSummarized
documentContext inputDocCharLimit
structure documentContext documentContext
projectedDocument inputDocCharLimit documentContext documentContext structure tryPreserveTypeChecking
isSummarized
projectedDocument documentContext documentContext
adjustedSelection projectedDocument selection
selectedLinesContent documentContext selection selection
contextInfo documentContext fixContext fixContext
replyInterpreter projectedDocument documentContext adjustedSelection
exampleUri
priorities state
documentContext
uri exampleUri
find
replace
uri exampleUri
find
replace
aboveCells
belowCells
projectedDocument
language
diagnostics vscode
selection vscode
adjustedSelection
isSummarized
selectedLinesContent
state sizing
jupyterNotebook
projectedDocument aboveCells belowCells
aboveCellsInfo aboveCells
belowCellsInfo belowCells
lang
jupyterNotebook
override
cellIndex projectedDocument diagnostics language selection adjustedSelection isSummarized selectedLinesContent
notebookType
isMarkdown language
notebookType isMarkdown
props
props
override
projectedDocument diagnostics language selection adjustedSelection isSummarized selectedLinesContent
isMarkdown language
projectedDocument
isMarkdown
projectedDocument
projectedDocument
selection
adjustedSelection adjustedSelection
adjustedSelection adjustedSelection adjustedSelection adjustedSelection
selectedLinesContent diagnostics d d selection
documentContext
aboveCells
belowCells
state sizing
aboveCells aboveCellsInfo belowCells belowCellsInfo
lang
aboveCellsInfo belowCellsInfo
aboveCellsInfo belowCellsInfo
;
import
{ IParserService }
from
'../../../../platform/parser/node/parserService'
;
import
{ ITabsAndEditorsService }
from
'../../../../platform/tabs/common/tabsAndEditorsService'
;
import
{ IWorkspaceService }
from
'../../../../platform/workspace/common/workspaceService'
;
import
{ ILanguage }
from
'../../../../util/common/languages'
;
import
{ isJupyterNotebookUri, isNotebookCellOrNotebookChatInput }
from
'../../../../util/common/notebooks'
;
import
{ illegalArgument }
from
'../../../../util/vs/base/common/errors'
;
import
{ Schemas }
from
'../../../../util/vs/base/common/network'
;
import
{ StringEdit }
from
'../../../../util/vs/editor/common/core/edits/stringEdit'
;
import
{ IInstantiationService }
from
'../../../../util/vs/platform/instantiation/common/instantiation'
;
import
{ Range , Uri }
from
'../../../../vscodeTypes'
;
import
{ findDiagnosticForSelectionAndPrompt, findFixRangeOfInterest, generateFixContext }
from
'../../../context/node/resolvers/fixSelection'
;
import
{ generateNotebookCellContext }
from
'../../../context/node/resolvers/inlineChatSelection'
;
import
{ InlineFixProps }
from
'../../../context/node/resolvers/inlineFixIntentInvocation'
;
import
{ getStructure }
from
'../../../context/node/resolvers/selectionContextHelpers'
;
import
{ CodeContextRegion }
from
'../../../inlineChat/node/codeContextRegion'
;
import
{ IDocumentContext }
from
'../../../prompt/node/documentContext'
;
import
{ ReplyInterpreterMetaData }
from
'../../../prompt/node/intents'
;
import
{ CompositeElement }
from
'../base/common'
;
import
{ InstructionMessage }
from
'../base/instructionMessage'
;
import
{ IPromptEndpoint }
from
'../base/promptRenderer'
;
import
{ LegacySafetyRules }
from
'../base/safetyRules'
;
import
{ Tag }
from
'../base/tag'
;
import
{ PatchEditExamplePatch , PatchEditInputCodeBlock , PatchEditRules }
from
'../codeMapper/patchEditGeneration'
;
import
{ JupyterNotebookRules }
from
'../notebook/commonPrompts'
;
import
{ ChatToolReferences , ChatVariables , UserQuery }
from
'../panel/chatVariables'
;
import
{ HistoryWithInstructions }
from
'../panel/conversationHistory'
;
import
{ CustomInstructions }
from
'../panel/customInstructions'
;
import
{ CodeBlock }
from
'../panel/safeElements'
;
import
{ PatchEditFixReplyInterpreter }
from
'./inlineChatFix3Prompt'
;
import
{ NotebookPromptPriority , promptPriorities }
from
'./inlineChatNotebookCommon'
;
import
{ InlineChatCellSelectionProps , InlineChatCustomNotebookCellsContextRenderer , InlineChatCustomNotebookInfoRenderer , InlineChatNotebookSelectionCommonProps , InlineChatNotebookVariables , NotebookCellList }
from
'./inlineChatNotebookCommonPromptElements'
;
import
{ ProjectedDocument }
from
'./summarizedDocument/summarizeDocument'
;
import
{ summarizeDocumentSync }
from
'./summarizedDocument/summarizeDocumentHelpers'
;
const
FIX_SELECTION_LENGTH_THRESHOLD
=
15
;
interface
InlineChatNotebookFixPromptState
{
:
boolean
;
:
NotebookPromptPriority
;
}
export
class
InlineFixNotebookPrompt
extends
PromptElement< InlineFixProps, InlineChatNotebookFixPromptState>
{
constructor
(
:
InlineFixProps
,
IIgnoreService
private
readonly
:
IIgnoreService
,
IInstantiationService
private
readonly
:
IInstantiationService
,
ILanguageDiagnosticsService
private
readonly
:
ILanguageDiagnosticsService
,
IParserService
private
readonly
:
IParserService
,
ITabsAndEditorsService
private
readonly
:
ITabsAndEditorsService
,
IWorkspaceService
private
readonly
:
IWorkspaceService
,
IPromptEndpoint
private
readonly
:
IPromptEndpoint
)
{
super
(
)
;
}
async
prepare
(
:
PromptSizing
)
:
Promise
<
InlineChatNotebookFixPromptState
>
{
const
{
:
}
=
this
.
props
;
const
=
await
this
.
_ignoreService
.
isCopilotIgnored
(
.
document
.
uri
)
;
return
{
,
:
}
;
}
async
render
(
:
InlineChatNotebookFixPromptState
,
:
PromptSizing
)
{
const
=
this
.
props
.
documentContext
;
if
(
!
isNotebookCellOrNotebookChatInput
(
.
document
.
uri
)
)
{
throw
illegalArgument
(
'InlineFixNotebookPrompt should not be used with a non-notebook!'
)
;
}
if
(
.
isIgnored
)
{
return
< ignoredFiles value = { [ documentContext. document . uri ] } />
;
}
const
{
,
,
}
=
this
.
props
.
promptContext
;
const
=
.
selection
;
const
=
findDiagnosticForSelectionAndPrompt
(
this
.
_languageDiagnosticsService
,
.
document
.
uri
,
.
selection
,
)
;
const
=
.
length
>
0
?
rangeSpanningDiagnostics
(
)
:
.
selection
;
const
=
this
.
_parserService
.
getTreeSitterAST
(
.
document
)
;
const
=
?
await
findFixRangeOfInterest
(
,
,
FIX_SELECTION_LENGTH_THRESHOLD
)
:
;
const
=
generateFixContext
(
this
.
_promptEndpoint
,
,
,
)
;
const
=
(
.
endpoint
.
modelMaxPromptTokens
/
3
)
*
4
;
let
:
ProjectedDocument
;
let
=
false
;
if
(
.
document
.
getText
(
)
.
length
>
)
{
const
=
await
getStructure
(
this
.
_parserService
,
.
document
,
.
fileIndentInfo
)
;
=
summarizeDocumentSync
(
,
.
document
,
.
wholeRange
,
,
{
:
true
}
)
;
=
true
;
}
else
{
=
new
ProjectedDocument
(
.
document
.
getText
(
)
,
StringEdit
.
empty
,
.
document
.
languageId
)
;
}
const
=
.
projectRange
(
)
;
const
=
.
document
.
getText
(
new
Range
(
.
start
.
line
,
0
,
.
end
.
line
+
1
,
0
)
)
.
trimEnd
(
)
;
const
=
generateNotebookCellContext
(
this
.
_tabsAndEditorsService
,
this
.
_workspaceService
,
,
.
contextInfo
,
.
tracker
)
;
const
=
this
.
_instantiationService
.
createInstance
(
PatchEditFixReplyInterpreter
,
,
.
document
.
uri
,
)
;
const
=
Uri
.
file
(
'/someFolder/myFile.ts'
)
;
const
=
.
priorities
;
return
(
< >
< meta value = { new ReplyInterpreterMetaData ( replyInterpreter) } />
< SystemMessage priority = { priorities. core } >
You are an AI programming assistant.
< br />
When asked for your name, you must respond with "GitHub Copilot".
< br />
You are a world class expert in programming, and especially good at
{
.
language
.
languageId
}
.
< br />
Source code is always contained in ``` blocks.<br />
</SystemMessage>
<HistoryWithInstructions inline={true} passPriority historyPriority={priorities.history ?? 700} history={history}>
<InstructionMessage priority={priorities.core}>
The user needs help to write some new code.<br />
<JupyterNotebookRules />
When dealing with Jupyter Notebook, do not generate CELL INDEX in the code blocks in your answer, it is only used to help you understand the context.<br />
If you suggest to run a terminal command, use a code block that starts with ```bash.
< br />
When fixing "ModuleNotFoundError" or "Import could not be resolved" errors, always use magic command "%pip install" to add the missing packages. The imports MUST be inserted at the top of the code block and it should not replace existing code.
< br />
You should not import the same module twice.
< br />
< PatchEditRules />
< LegacySafetyRules />
< Tag name = ' example' priority = { 100 } >
< Tag name = ' user' >
I have the following code open in the editor.
< br />
< PatchEditInputCodeBlock
uri = { exampleUri}
languageId = ' csharp'
code = { [ '// This is my class' , 'class C { }' , '' , 'new C().Field = 9;' ] }
/>
</ Tag >
< Tag name = ' assistant' >
The problem is that the class 'C' does not have a field or property named 'Field'. To fix this, you need to add a 'Field' property to the 'C' class.
< br />
< br />
<PatchEditExamplePatch
changes=
{
[
{
:
,
:
[
'// This is my class'
,
'class C { }'
]
,
:
[
'// This is my class'
,
'class C {'
,
'public int Field { get; set; }'
,
'}'
]
}
,
{
:
,
:
[
'new C().Field = 9;'
]
,
:
[
'// set the field to 9'
,
'new C().Field = 9;'
]
}
]
}
/>
</ Tag >
</ Tag >
</ InstructionMessage >
</ HistoryWithInstructions >
< UserMessage priority = { priorities. context } >
< CustomInstructions languageId = { documentContext. language . languageId } chatVariables = { chatVariables} />
</ UserMessage >
< ChatToolReferences priority = { priorities. context } promptContext = { this . props . promptContext } flexGrow = { 1 } embeddedInsideUserMessage = { false } />
< ChatVariables priority = { priorities. context } chatVariables = { chatVariables} embeddedInsideUserMessage = { false } />
< InlineChatFixNotebookSelectionRenderer
priority = { priorities. core }
documentContext = { documentContext}
aboveCells = { contextInfo. aboveCells }
belowCells = { contextInfo. belowCells }
document = { documentContext. document }
projectedDocument = { projectedDocument}
language = { documentContext. language }
diagnostics = { diagnostics}
selection = { documentContext. selection }
adjustedSelection = { adjustedSelection}
isSummarized = { isSummarized}
selectedLinesContent = { selectedLinesContent}
/>
< InlineChatNotebookVariables notebookURI = { this . props . documentContext . document . uri } priority = { priorities. runtimeCore } priorities = { priorities} query = { query} />
< UserMessage priority = { priorities. core } >
{
}
{
}
Please find a fix for my code so that the result is without any errors.
< br />
< UserQuery chatVariables = { chatVariables} query = { query} />
<br />
</ UserMessage >
</ >
);
}
}
interface InlineChatNotebookSelectionRendererProps extends InlineChatNotebookSelectionCommonProps
{
?
:
CodeContextRegion
[
]
;
?
:
CodeContextRegion
[
]
;
readonly
document
:
TextDocumentSnapshot
;
readonly
:
ProjectedDocument
;
readonly
:
ILanguage
;
readonly
:
.
Diagnostic
[
]
;
readonly
:
.
Selection
;
readonly
:
Range
;
readonly
:
boolean
;
readonly
:
string
;
}
class InlineChatFixNotebookSelectionRenderer extends PromptElement<InlineChatNotebookSelectionRendererProps>
{
render
(
:
void
,
:
PromptSizing
)
{
if
(
this
.
props
.
documentContext
.
document
.
uri
.
scheme
!==
Schemas
.
vscodeNotebookCell
)
{
throw
illegalArgument
(
'InlineChatNotebookSelectionRenderer should be used only with a notebook!'
)
;
}
const
=
isJupyterNotebookUri
(
this
.
props
.
documentContext
.
document
.
uri
)
;
const
{
,
,
}
=
this
.
props
;
const
=
||
[
]
;
const
=
||
[
]
;
const
=
this
.
props
.
documentContext
.
language
;
return
(
< >
{
?
< >
< InlineChatFixNotebookCellsContextRenderer documentContext = { this . props . documentContext } aboveCells = { aboveCellsInfo} belowCells = { belowCellsInfo} />
</ >
:
< >
< InlineChatCustomNotebookInfoRenderer documentContext = { this . props . documentContext } />
< InlineChatCustomNotebookCellsContextRenderer documentContext = { this . props . documentContext } aboveCells = { aboveCellsInfo} belowCells = { belowCellsInfo} />
</ >
}
< NotebookCellSelection cellIndex = { aboveCellsInfo. length } document = { this . props . document } projectedDocument = { projectedDocument} language = { lang} diagnostics = { this . props . diagnostics } selection = { this . props . selection } adjustedSelection = { this . props . adjustedSelection } isSummarized = { this . props . isSummarized } selectedLinesContent = { this . props . selectedLinesContent } />
</ >
)
;
}
}
class NotebookCellSelection extends PromptElement<InlineChatCellSelectionProps>
{
render
(
)
{
const
{
,
document
,
,
,
,
,
,
,
}
=
this
.
props
;
const
=
isNotebookCellOrNotebookChatInput
(
document
.
uri
)
?
'Jupyter'
:
'custom'
;
const
=
.
languageId
===
'markdown'
;
return
< >
< UserMessage >
Now I create a new cell in this
{
}
Notebook document at index
{
this
.
props
.
cellIndex
}
.
< br />
{
&&
< >
This is a markdown cell. Markdown cell is used to describe and document your workflow.
< br />
</ >
}
< NotebookCellRenderer cellIndex = { cellIndex} document = { document } projectedDocument = { projectedDocument} diagnostics = { diagnostics} language = { language} selection = { selection} adjustedSelection = { adjustedSelection} isSummarized = { isSummarized} selectedLinesContent = { selectedLinesContent} />
</ UserMessage >
</ >
;
}
}
class NotebookCellRenderer extends PromptElement<InlineChatCellSelectionProps>
{
constructor
(
:
InlineChatCellSelectionProps
)
{
super
(
)
;
}
render
(
)
{
const
{
document
,
,
,
,
,
,
,
}
=
this
.
props
;
const
=
.
languageId
===
'markdown'
;
return
< >
< CompositeElement >
{
.
text
.
length
>
0
?
< >
{
?
< >
I have the following markdown content in this cell, starting from line 1 to line
{
.
lineCount
}
.
< br />
</ >
:
< >
I have the following code in this cell, starting from line 1 to line
{
.
lineCount
}
.
< br />
</ >
}
< PatchEditInputCodeBlock uri = { document . uri } languageId = { language. languageId } code = { projectedDocument. text } shouldTrim = { false } isSummarized = { isSummarized} />
<br />
</ >
:
< >
I am in an empty file:
< PatchEditInputCodeBlock uri = { document . uri } languageId = { language. languageId } code = { projectedDocument. text } shouldTrim = { false } isSummarized = { isSummarized} />
<br />
</ >
}
</ CompositeElement >
< CompositeElement >
{
.
isEmpty
?
< >
I have the selection at line
{
.
start
.
line
+
1
}
, column
{
.
start
.
character
+
1
}
< br />
</ >
:
< >
I have currently selected from line
{
.
start
.
line
+
1
}
, column
{
.
start
.
character
+
1
}
to line
{
.
end
.
line
+
1
}
column
{
.
end
.
character
+
1
}
.
< br />
</ >
}
</ CompositeElement >
< CompositeElement >
{
.
length
&&
!
.
some
(
=>
.
range
.
contains
(
)
)
&&
< >
The content of the lines at the selection is
< CodeBlock uri = { document . uri } languageId = { language. languageId } code = { selectedLinesContent} shouldTrim = { false } />
<br />
</ >
}
</ CompositeElement >
</ >
;
}
}
interface InlineChatFixNotebookCellsContextRendererProps extends BasePromptElementProps
{
:
IDocumentContext
;
:
CodeContextRegion
[
]
;
:
CodeContextRegion
[
]
;
}
/**
* Notebook cell context renderer. Used by Fix intents.
* It's using following example for llm response:
* ---FILEPATH Untitled-1<br />
---FIND<br />
---REPLACE<br />
```python<br />
df.plot(x='Name', y='Age', kind='bar')<br />
```<br />
---COMPLETE<br />
* However, we don't use this in Generate and Edit intents yet.
*/
class InlineChatFixNotebookCellsContextRenderer extends PromptElement<InlineChatFixNotebookCellsContextRendererProps>
{
render
(
:
void
,
:
PromptSizing
)
{
if
(
!
isNotebookCellOrNotebookChatInput
(
this
.
props
.
documentContext
.
document
.
uri
)
)
{
throw
illegalArgument
(
'InlineChatNotebookSelectionRenderer should be used only with a notebook!'
)
;
}
const
{
:
,
:
}
=
this
.
props
;
const
=
this
.
props
.
documentContext
.
language
;
return
(
< >
{
(
.
length
>
0
||
.
length
>
0
)
&&
< UserMessage >
I am working on a Jupyter notebook.
< br />
This Jupyter Notebook already contains multiple cells.
< br />
The content of cells are listed below, each cell starts with CELL INDEX and a code block started with ```{lang.languageId}<br />
Each cell is a block of code that can be executed independently.<br />
Since it is Jupyter Notebook, if a module is already imported in a cell, it can be used in other cells as well.<br />
For the same reason, if a variable is defined in a cell, it can be used in other cells as well.<br />
We should not repeat the same import or variable definition in multiple cells, unless we want to overwrite the previous definition.<br />
Do not generate CELL INDEX in your answer, it is only used to help you understand the context.<br />
<br />
<>Below you will find a set of examples of what you should respond with. Please follow the exmaples on how to avoid repeating code.<br />
## Examples starts here<br />
Here are the cells in this Jupyter Notebook:<br />
`CELL INDEX: 0<br />
```python<br />
import pandas as pd<br />
<br />
# create a dataframe with sample data<br />
df = pd.DataFrame({'Name': ['Alice', 'Bob', 'Charlie'], 'Age': [25, 30, 35], 'Gender': ['F', 'M', 'M']})<br />
print(df)<br />
```
< br />
---------------------------------
< br />
USER:
< br />
Now I create a new cell in this Jupyter Notebook document at index 1.
< br />
I have the following code open in this cell, starting from line 1 to line 1.
< br />
```python<br />
```
< br />
---------------------------------
< br />
USER:
< br />
plot the data frame<br />
< br />
---------------------------------
< br />
Assistant Answer<br />
---------------------------------
< br />
To plot the dataframe, we can use the `plot()` method of pandas dataframe.
< br />
< br />
---FILEPATH Untitled-1<br />
---FIND<br />
---REPLACE<br />
```python<br />
df.plot(x='Name', y='Age', kind='bar')<br />
```
< br />
---COMPLETE<br />
## Example ends here<br />
</ >
{
.
length
>
0
&&
< NotebookCellList cells = { aboveCellsInfo} title = { 'Here are the cells in this Jupyter Notebook:\n' } />
}
{
.
length
>
0
&&
< NotebookCellList cells = { belowCellsInfo} cellIndexDelta = { aboveCellsInfo. length + 1 } title = { 'Here are the cells below the current cell that I am editing in this Jupyter Notebook:\n' } />
}
</ UserMessage >
}
</ >
)
;
}
}