@@ -13,20 +13,17 @@ import { URI } from '../../../../../base/common/uri.js';
13
13
import { getCodeEditor , ICodeEditor } from '../../../../../editor/browser/editorBrowser.js' ;
14
14
import { ICodeEditorService } from '../../../../../editor/browser/services/codeEditorService.js' ;
15
15
import { Location } from '../../../../../editor/common/languages.js' ;
16
- import { IModelService } from '../../../../../editor/common/services/model.js' ;
17
16
import { IConfigurationService } from '../../../../../platform/configuration/common/configuration.js' ;
18
- import { ILogService } from '../../../../../platform/log/common/log.js' ;
19
17
import { IWorkbenchContribution } from '../../../../common/contributions.js' ;
20
18
import { EditorsOrder } from '../../../../common/editor.js' ;
21
19
import { IEditorService } from '../../../../services/editor/common/editorService.js' ;
22
20
import { getNotebookEditorFromEditorPane , INotebookEditor } from '../../../notebook/browser/notebookBrowser.js' ;
23
21
import { IChatEditingService } from '../../common/chatEditingService.js' ;
24
- import { IChatRequestImplicitVariableEntry , IChatRequestVariableEntry , toPromptFileVariableEntry } from '../../common/chatVariableEntries.js' ;
22
+ import { IChatRequestImplicitVariableEntry , IChatRequestVariableEntry } from '../../common/chatVariableEntries.js' ;
25
23
import { IChatService } from '../../common/chatService.js' ;
26
24
import { ChatAgentLocation } from '../../common/constants.js' ;
27
25
import { ILanguageModelIgnoredFilesService } from '../../common/ignoredFiles.js' ;
28
- import { PROMPT_LANGUAGE_ID } from '../../common/promptSyntax/promptTypes.js' ;
29
- import { IPromptsService , TSharedPrompt } from '../../common/promptSyntax/service/promptsService.js' ;
26
+ import { getPromptsTypeForLanguageId } from '../../common/promptSyntax/promptTypes.js' ;
30
27
import { IChatWidget , IChatWidgetService } from '../chat.js' ;
31
28
32
29
export class ChatImplicitContextContribution extends Disposable implements IWorkbenchContribution {
@@ -155,6 +152,7 @@ export class ChatImplicitContextContribution extends Disposable implements IWork
155
152
let languageId : string | undefined ;
156
153
if ( model ) {
157
154
newValue = model . uri ;
155
+ languageId = model . getLanguageId ( ) ;
158
156
}
159
157
160
158
const notebookEditor = this . findActiveNotebookEditor ( ) ;
@@ -174,37 +172,27 @@ export class ChatImplicitContextContribution extends Disposable implements IWork
174
172
return ;
175
173
}
176
174
175
+ const isPromptFile = languageId && getPromptsTypeForLanguageId ( languageId ) !== undefined ;
176
+
177
177
const widgets = updateWidget ? [ updateWidget ] : [ ...this . chatWidgetService . getWidgetsByLocations ( ChatAgentLocation . Panel ) , ...this . chatWidgetService . getWidgetsByLocations ( ChatAgentLocation . Editor ) ] ;
178
178
for ( const widget of widgets ) {
179
179
if ( ! widget . input . implicitContext ) {
180
180
continue ;
181
181
}
182
182
const setting = this . _implicitContextEnablement [ widget . location ] ;
183
183
const isFirstInteraction = widget . viewModel ?. getItems ( ) . length === 0 ;
184
- if ( setting === 'first' && ! isFirstInteraction ) {
185
- widget . input . implicitContext . setValue ( undefined , false , undefined ) ;
186
- } else if ( setting === 'always' || setting === 'first' && isFirstInteraction ) {
184
+ if ( ( setting === 'always' || setting === 'first' && isFirstInteraction ) && ! isPromptFile ) { // disable implicit context for prompt files
187
185
widget . input . implicitContext . setValue ( newValue , isSelection , languageId ) ;
188
- } else if ( setting === 'never' ) {
186
+ } else {
189
187
widget . input . implicitContext . setValue ( undefined , false , undefined ) ;
190
188
}
191
189
}
192
190
}
193
191
}
194
192
195
193
export class ChatImplicitContext extends Disposable implements IChatRequestImplicitVariableEntry {
196
- /**
197
- * If the implicit context references a prompt file, this field
198
- * holds a reference to an associated prompt parser instance.
199
- */
200
- private prompt : TSharedPrompt | undefined ;
201
194
202
195
get id ( ) {
203
- if ( this . prompt !== undefined ) {
204
- const variable = toPromptFileVariableEntry ( this . prompt . uri , true ) ;
205
- return variable . id ;
206
- }
207
-
208
196
if ( URI . isUri ( this . value ) ) {
209
197
return 'vscode.implicit.file' ;
210
198
} else if ( this . value ) {
@@ -219,12 +207,6 @@ export class ChatImplicitContext extends Disposable implements IChatRequestImpli
219
207
}
220
208
221
209
get name ( ) : string {
222
- if ( this . prompt !== undefined ) {
223
- const variable = toPromptFileVariableEntry ( this . prompt . uri , true ) ;
224
-
225
- return variable . name ;
226
- }
227
-
228
210
if ( URI . isUri ( this . value ) ) {
229
211
return `file:${ basename ( this . value ) } ` ;
230
212
} else if ( this . value ) {
@@ -237,12 +219,6 @@ export class ChatImplicitContext extends Disposable implements IChatRequestImpli
237
219
readonly kind = 'implicit' ;
238
220
239
221
get modelDescription ( ) : string {
240
- if ( this . prompt !== undefined ) {
241
- const variable = toPromptFileVariableEntry ( this . prompt . uri , true ) ;
242
-
243
- return variable . modelDescription ;
244
- }
245
-
246
222
if ( URI . isUri ( this . value ) ) {
247
223
return `User's active file` ;
248
224
} else if ( this . _isSelection ) {
@@ -277,90 +253,20 @@ export class ChatImplicitContext extends Disposable implements IChatRequestImpli
277
253
this . _onDidChangeValue . fire ( ) ;
278
254
}
279
255
280
- constructor (
281
- @IPromptsService private readonly promptsService : IPromptsService ,
282
- @IModelService private readonly modelService : IModelService ,
283
- @ILogService private readonly logService : ILogService ,
284
- ) {
285
- super ( ) ;
286
- }
287
-
288
256
setValue ( value : Location | URI | undefined , isSelection : boolean , languageId ?: string ) : void {
289
257
this . _value = value ;
290
258
this . _isSelection = isSelection ;
291
-
292
- // remove and dispose existent prompt parser instance
293
- this . removePrompt ( ) ;
294
- // if language ID is a 'prompt' language, create a prompt parser instance
295
- if ( value && ( languageId === PROMPT_LANGUAGE_ID ) ) {
296
- this . addPrompt ( value ) ;
297
- }
298
259
this . _onDidChangeValue . fire ( ) ;
299
260
}
300
261
301
262
public async toBaseEntries ( ) : Promise < readonly IChatRequestVariableEntry [ ] > {
302
- // chat variable for non-prompt file attachment
303
- if ( this . prompt === undefined ) {
304
- return [ {
305
- kind : 'file' ,
306
- id : this . id ,
307
- name : this . name ,
308
- value : this . value ,
309
- modelDescription : this . modelDescription ,
310
- } ] ;
311
-
312
- }
313
-
314
- // prompt can have any number of nested references, hence
315
- // collect all of valid ones and return the entire list
316
- await this . prompt . allSettled ( ) ;
317
- return [
318
- // add all valid child references in the prompt
319
- ...this . prompt . allValidReferences . map ( ( link ) => {
320
- return toPromptFileVariableEntry ( link . uri , false ) ;
321
- } ) ,
322
- // and then the root prompt reference itself
323
- toPromptFileVariableEntry ( this . prompt . uri , true )
324
- ] ;
325
- }
326
-
327
- /**
328
- * Whether the implicit context references a prompt file.
329
- */
330
- public get isPromptFile ( ) {
331
- return ( this . prompt !== undefined ) ;
263
+ return [ {
264
+ kind : 'file' ,
265
+ id : this . id ,
266
+ name : this . name ,
267
+ value : this . value ,
268
+ modelDescription : this . modelDescription ,
269
+ } ] ;
332
270
}
333
271
334
- /**
335
- * Add prompt parser instance for the provided value.
336
- */
337
- private addPrompt (
338
- value : URI | Location ,
339
- ) : void {
340
- const uri = URI . isUri ( value )
341
- ? value
342
- : value . uri ;
343
-
344
- const model = this . modelService . getModel ( uri ) ;
345
- const modelExists = ( model !== null ) ;
346
- if ( ( modelExists === false ) || model . isDisposed ( ) ) {
347
- return this . logService . warn (
348
- `cannot create prompt parser instance for ${ uri . path } (model exists: ${ modelExists } )` ,
349
- ) ;
350
- }
351
-
352
- this . prompt = this . promptsService . getSyntaxParserFor ( model ) ;
353
- }
354
-
355
- /**
356
- * Remove and dispose prompt parser instance.
357
- */
358
- private removePrompt ( ) : void {
359
- delete this . prompt ;
360
- }
361
-
362
- public override dispose ( ) : void {
363
- this . removePrompt ( ) ;
364
- super . dispose ( ) ;
365
- }
366
272
}
0 commit comments