@@ -43,7 +43,6 @@ 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' ;
47
46
import { IInstantiationService } from '../../../util/vs/platform/instantiation/common/instantiation' ;
48
47
import { Position as VscodePosition } from '../../../vscodeTypes' ;
49
48
import { Delayer , DelaySession } from '../../inlineEdits/common/delayer' ;
@@ -53,6 +52,7 @@ import { IgnoreImportChangesAspect } from '../../inlineEdits/node/importFilterin
53
52
import { createTaggedCurrentFileContentUsingPagedClipping , getUserPrompt , N_LINES_ABOVE , N_LINES_AS_CONTEXT , N_LINES_BELOW , nes41Miniv3SystemPrompt , PromptPieces , PromptTags , simplifiedPrompt , systemPromptTemplate , unifiedModelSystemPrompt , xtab275SystemPrompt } from '../common/promptCrafting' ;
54
53
import { XtabEndpoint } from './xtabEndpoint' ;
55
54
import { linesWithBackticksRemoved , toLines } from './xtabUtils' ;
55
+ import { CurrentDocument } from './xtabCurrentDocument' ;
56
56
57
57
namespace ResponseTags {
58
58
export const NO_CHANGE = {
@@ -86,6 +86,8 @@ export class XtabProvider implements IStatelessNextEditProvider {
86
86
public readonly dependsOnSelection = true ;
87
87
public readonly showNextEditPreference = ShowNextEditPreference . Always ;
88
88
89
+ private static computeTokens = ( s : string ) => Math . floor ( s . length / 4 ) ;
90
+
89
91
private readonly tracer : ITracer ;
90
92
private readonly delayer : Delayer ;
91
93
@@ -226,47 +228,40 @@ export class XtabProvider implements IStatelessNextEditProvider {
226
228
logContext . setEndpointInfo ( typeof endpoint . urlOrRequestMetadata === 'string' ? endpoint . urlOrRequestMetadata : JSON . stringify ( endpoint . urlOrRequestMetadata . type ) , endpoint . model ) ;
227
229
telemetryBuilder . setModelName ( endpoint . model ) ;
228
230
229
- const computeTokens = ( s : string ) => Math . floor ( s . length / 4 ) ;
230
-
231
231
const cursorPosition = new Position ( selection . endLineNumber , selection . endColumn ) ;
232
232
233
- const cursorOffset = activeDocument . documentAfterEdits . getTransformer ( ) . getOffset ( cursorPosition ) ;
234
-
235
- const currentFileContent = activeDocument . documentAfterEdits ;
236
- const currentFileContentLines = currentFileContent . getLines ( ) ;
233
+ const currentDocument = new CurrentDocument ( activeDocument . documentAfterEdits , cursorPosition ) ;
237
234
238
235
const cursorLineIdx = cursorPosition . lineNumber - 1 /* to convert to 0-based */ ;
239
236
240
- const cursorLine = currentFileContentLines [ cursorLineIdx ] ;
237
+ const cursorLine = currentDocument . lines . value [ cursorLineIdx ] ;
241
238
const isCursorAtEndOfLine = cursorPosition . column === cursorLine . trimEnd ( ) . length ;
242
239
if ( isCursorAtEndOfLine ) {
243
240
delaySession . setExtraDebounce ( this . configService . getExperimentBasedConfig ( ConfigKey . Internal . InlineEditsExtraDebounceEndOfLine , this . expService ) ) ;
244
241
}
245
242
telemetryBuilder . setIsCursorAtLineEnd ( isCursorAtEndOfLine ) ;
246
243
247
- const areaAroundEditWindowLinesRange = this . computeAreaAroundEditWindowLinesRange ( currentFileContentLines , cursorLineIdx ) ;
244
+ const areaAroundEditWindowLinesRange = this . computeAreaAroundEditWindowLinesRange ( currentDocument . lines . value , cursorLineIdx ) ;
248
245
249
- const editWindowLinesRange = this . computeEditWindowLinesRange ( currentFileContentLines , cursorLineIdx , request , retryState ) ;
246
+ const editWindowLinesRange = this . computeEditWindowLinesRange ( currentDocument . lines . value , cursorLineIdx , request , retryState ) ;
250
247
251
248
const cursorOriginalLinesOffset = Math . max ( 0 , cursorLineIdx - editWindowLinesRange . start ) ;
252
249
const editWindowLastLineLength = activeDocument . documentAfterEdits . getTransformer ( ) . getLineLength ( editWindowLinesRange . endExclusive ) ;
253
250
const editWindow = activeDocument . documentAfterEdits . getTransformer ( ) . getOffsetRange ( new Range ( editWindowLinesRange . start + 1 , 1 , editWindowLinesRange . endExclusive , editWindowLastLineLength + 1 ) ) ;
254
251
255
- const editWindowLines = currentFileContentLines . slice ( editWindowLinesRange . start , editWindowLinesRange . endExclusive ) ;
252
+ const editWindowLines = currentDocument . lines . value . slice ( editWindowLinesRange . start , editWindowLinesRange . endExclusive ) ;
256
253
257
254
// Expected: editWindow.substring(activeDocument.documentAfterEdits.value) === editWindowLines.join('\n')
258
255
259
256
const doesIncludeCursorTag = editWindowLines . some ( line => line . includes ( PromptTags . CURSOR ) ) ;
260
257
const shouldRemoveCursorTagFromResponse = ! doesIncludeCursorTag ; // we'd like to remove the tag only if the original edit-window didn't include the tag
261
258
262
259
const taggedCurrentFileContentResult = this . constructTaggedFile (
263
- currentFileContent ,
264
- currentFileContentLines ,
265
- cursorOffset ,
260
+ currentDocument ,
266
261
editWindowLinesRange ,
267
262
areaAroundEditWindowLinesRange ,
268
263
promptOptions ,
269
- computeTokens ,
264
+ XtabProvider . computeTokens ,
270
265
{ includeLineNumbers : false }
271
266
) ;
272
267
@@ -304,7 +299,7 @@ export class XtabProvider implements IStatelessNextEditProvider {
304
299
taggedCurrentFileContent ,
305
300
areaAroundCodeToEdit ,
306
301
langCtx ,
307
- computeTokens ,
302
+ XtabProvider . computeTokens ,
308
303
promptOptions
309
304
) ;
310
305
@@ -363,9 +358,7 @@ export class XtabProvider implements IStatelessNextEditProvider {
363
358
}
364
359
365
360
private constructTaggedFile (
366
- currentFileContent : StringText ,
367
- currentFileContentLines : string [ ] ,
368
- cursorOffset : number ,
361
+ currentDocument : CurrentDocument ,
369
362
editWindowLinesRange : OffsetRange ,
370
363
areaAroundEditWindowLinesRange : OffsetRange ,
371
364
promptOptions : ModelConfig ,
@@ -375,8 +368,8 @@ export class XtabProvider implements IStatelessNextEditProvider {
375
368
}
376
369
) {
377
370
const contentWithCursorAsLinesOriginal = ( ( ) => {
378
- const addCursorTagEdit = StringEdit . single ( StringReplacement . insert ( cursorOffset , PromptTags . CURSOR ) ) ;
379
- const contentWithCursor = addCursorTagEdit . applyOnText ( currentFileContent ) ;
371
+ const addCursorTagEdit = StringEdit . single ( StringReplacement . insert ( currentDocument . cursorOffset , PromptTags . CURSOR ) ) ;
372
+ const contentWithCursor = addCursorTagEdit . applyOnText ( currentDocument . content ) ;
380
373
return contentWithCursor . getLines ( ) ;
381
374
} ) ( ) ;
382
375
@@ -398,9 +391,9 @@ export class XtabProvider implements IStatelessNextEditProvider {
398
391
PromptTags . AREA_AROUND . end
399
392
] . join ( '\n' ) ;
400
393
401
- currentFileContentLines = opts . includeLineNumbers
402
- ? addLineNumbers ( currentFileContentLines )
403
- : currentFileContentLines ;
394
+ const currentFileContentLines = opts . includeLineNumbers
395
+ ? addLineNumbers ( currentDocument . lines . value )
396
+ : currentDocument . lines . value ;
404
397
405
398
let areaAroundCodeToEditForCurrentFile : string ;
406
399
if ( promptOptions . currentFile . includeTags ) {
0 commit comments