@@ -43,6 +43,7 @@ import { Position } from '../../../util/vs/editor/common/core/position';
43
43
import { Range } from '../../../util/vs/editor/common/core/range' ;
44
44
import { LineRange } from '../../../util/vs/editor/common/core/ranges/lineRange' ;
45
45
import { OffsetRange } from '../../../util/vs/editor/common/core/ranges/offsetRange' ;
46
+ import { StringText } from '../../../util/vs/editor/common/core/text/abstractText' ;
46
47
import { IInstantiationService } from '../../../util/vs/platform/instantiation/common/instantiation' ;
47
48
import { Position as VscodePosition } from '../../../vscodeTypes' ;
48
49
import { Delayer , DelaySession } from '../../inlineEdits/common/delayer' ;
@@ -258,43 +259,22 @@ export class XtabProvider implements IStatelessNextEditProvider {
258
259
const doesIncludeCursorTag = editWindowLines . some ( line => line . includes ( PromptTags . CURSOR ) ) ;
259
260
const shouldRemoveCursorTagFromResponse = ! doesIncludeCursorTag ; // we'd like to remove the tag only if the original edit-window didn't include the tag
260
261
261
- const addCursorTagEdit = StringEdit . single ( StringReplacement . insert ( cursorOffset , PromptTags . CURSOR ) ) ;
262
- const contentWithCursor = addCursorTagEdit . applyOnText ( currentFileContent ) ;
263
- const contentWithCursorLines = contentWithCursor . getLines ( ) ;
264
-
265
- const editWindowWithCursorLines = contentWithCursorLines . slice ( editWindowLinesRange . start , editWindowLinesRange . endExclusive ) ;
266
-
267
- const areaAroundCodeToEdit = [
268
- PromptTags . AREA_AROUND . start ,
269
- ...contentWithCursorLines . slice ( areaAroundEditWindowLinesRange . start , editWindowLinesRange . start ) ,
270
- PromptTags . EDIT_WINDOW . start ,
271
- ...editWindowWithCursorLines ,
272
- PromptTags . EDIT_WINDOW . end ,
273
- ...contentWithCursorLines . slice ( editWindowLinesRange . endExclusive , areaAroundEditWindowLinesRange . endExclusive ) ,
274
- PromptTags . AREA_AROUND . end
275
- ] . join ( '\n' ) ;
276
-
277
- const areaAroundCodeToEditForCurrentFile = promptOptions . currentFile . includeTags
278
- ? areaAroundCodeToEdit
279
- : [
280
- ...contentWithCursorLines . slice ( areaAroundEditWindowLinesRange . start , editWindowLinesRange . start ) ,
281
- ...editWindowLines ,
282
- ...contentWithCursorLines . slice ( editWindowLinesRange . endExclusive , areaAroundEditWindowLinesRange . endExclusive ) ,
283
- ] . join ( '\n' ) ;
284
- const taggedCurrentFileContentResult = createTaggedCurrentFileContentUsingPagedClipping (
262
+ const taggedCurrentFileContentResult = this . constructTaggedFile (
263
+ currentFileContent ,
285
264
currentFileContentLines ,
286
- areaAroundCodeToEditForCurrentFile ,
265
+ cursorOffset ,
266
+ editWindowLinesRange ,
287
267
areaAroundEditWindowLinesRange ,
268
+ promptOptions ,
288
269
computeTokens ,
289
- promptOptions . pagedClipping . pageSize ,
290
- promptOptions . currentFile ,
270
+ { includeLineNumbers : false }
291
271
) ;
292
272
293
273
if ( taggedCurrentFileContentResult . isError ( ) ) {
294
274
return Result . error ( new NoNextEditReason . PromptTooLarge ( 'currentFile' ) ) ;
295
275
}
296
276
297
- const { taggedCurrentFileContent, nLines : nLinesCurrentFile } = taggedCurrentFileContentResult . val ;
277
+ const { taggedCurrentFileR : { taggedCurrentFileContent, nLines : nLinesCurrentFile } , areaAroundCodeToEdit } = taggedCurrentFileContentResult . val ;
298
278
299
279
telemetryBuilder . setNLinesOfCurrentFileInPrompt ( nLinesCurrentFile ) ;
300
280
@@ -382,6 +362,74 @@ export class XtabProvider implements IStatelessNextEditProvider {
382
362
return Result . ok < void > ( undefined ) ;
383
363
}
384
364
365
+ private constructTaggedFile (
366
+ currentFileContent : StringText ,
367
+ currentFileContentLines : string [ ] ,
368
+ cursorOffset : number ,
369
+ editWindowLinesRange : OffsetRange ,
370
+ areaAroundEditWindowLinesRange : OffsetRange ,
371
+ promptOptions : ModelConfig ,
372
+ computeTokens : ( s : string ) => number ,
373
+ opts : {
374
+ includeLineNumbers : boolean ;
375
+ }
376
+ ) {
377
+ const contentWithCursorAsLinesOriginal = ( ( ) => {
378
+ const addCursorTagEdit = StringEdit . single ( StringReplacement . insert ( cursorOffset , PromptTags . CURSOR ) ) ;
379
+ const contentWithCursor = addCursorTagEdit . applyOnText ( currentFileContent ) ;
380
+ return contentWithCursor . getLines ( ) ;
381
+ } ) ( ) ;
382
+
383
+ const addLineNumbers = ( lines : string [ ] ) => lines . map ( ( line , idx ) => `${ idx + 1 } | ${ line } ` ) ;
384
+
385
+ const contentWithCursorAsLines = opts . includeLineNumbers
386
+ ? addLineNumbers ( contentWithCursorAsLinesOriginal )
387
+ : contentWithCursorAsLinesOriginal ;
388
+
389
+ const editWindowWithCursorAsLines = contentWithCursorAsLines . slice ( editWindowLinesRange . start , editWindowLinesRange . endExclusive ) ;
390
+
391
+ const areaAroundCodeToEdit = [
392
+ PromptTags . AREA_AROUND . start ,
393
+ ...contentWithCursorAsLines . slice ( areaAroundEditWindowLinesRange . start , editWindowLinesRange . start ) ,
394
+ PromptTags . EDIT_WINDOW . start ,
395
+ ...editWindowWithCursorAsLines ,
396
+ PromptTags . EDIT_WINDOW . end ,
397
+ ...contentWithCursorAsLines . slice ( editWindowLinesRange . endExclusive , areaAroundEditWindowLinesRange . endExclusive ) ,
398
+ PromptTags . AREA_AROUND . end
399
+ ] . join ( '\n' ) ;
400
+
401
+ currentFileContentLines = opts . includeLineNumbers
402
+ ? addLineNumbers ( currentFileContentLines )
403
+ : currentFileContentLines ;
404
+
405
+ let areaAroundCodeToEditForCurrentFile : string ;
406
+ if ( promptOptions . currentFile . includeTags ) {
407
+ areaAroundCodeToEditForCurrentFile = areaAroundCodeToEdit ;
408
+ } else {
409
+ const editWindowLines = currentFileContentLines . slice ( editWindowLinesRange . start , editWindowLinesRange . endExclusive ) ;
410
+ areaAroundCodeToEditForCurrentFile = [
411
+ ...contentWithCursorAsLines . slice ( areaAroundEditWindowLinesRange . start , editWindowLinesRange . start ) ,
412
+ ...editWindowLines ,
413
+ ...contentWithCursorAsLines . slice ( editWindowLinesRange . endExclusive , areaAroundEditWindowLinesRange . endExclusive ) ,
414
+ ] . join ( '\n' ) ;
415
+ }
416
+
417
+ const taggedCurrentFileContentResult = createTaggedCurrentFileContentUsingPagedClipping (
418
+ currentFileContentLines ,
419
+ areaAroundCodeToEditForCurrentFile ,
420
+ areaAroundEditWindowLinesRange ,
421
+ computeTokens ,
422
+ promptOptions . pagedClipping . pageSize ,
423
+ promptOptions . currentFile ,
424
+ ) ;
425
+
426
+ return taggedCurrentFileContentResult . map ( taggedCurrentFileR => ( {
427
+ taggedCurrentFileR,
428
+ areaAroundCodeToEdit,
429
+ } ) ) ;
430
+ }
431
+
432
+
385
433
private async getLanguageContext (
386
434
request : StatelessNextEditRequest ,
387
435
delaySession : DelaySession ,
0 commit comments