@@ -47,7 +47,6 @@ import { ActionType, Commit, DiffError, FileChange, InvalidContextError, Invalid
47
47
import { EditFileResult , IEditedFile } from './editFileToolResult' ;
48
48
import { sendEditNotebookTelemetry } from './editNotebookTool' ;
49
49
import { assertFileOkForTool , resolveToolInputPath } from './toolUtils' ;
50
- import { guessIndentation , normalizeIndentation } from '../../prompt/node/indentationGuesser' ;
51
50
52
51
export const applyPatchWithNotebookSupportDescription : vscode . LanguageModelToolInformation = {
53
52
name : ToolName . ApplyPatch ,
@@ -126,39 +125,10 @@ export class ApplyPatchTool implements ICopilotTool<IApplyPatchToolParams> {
126
125
return trailingEmptyLines ;
127
126
}
128
127
129
-
130
- /**
131
- * Normalize the indentation of the content to match the original document's style
132
- * @param document The original document
133
- * @param content The content to normalize
134
- * @returns The normalized content
135
- */
136
- private normalizeIndentationStyle ( document : vscode . TextDocument , content : string ) : string {
137
- // Detect the indentation style of the original document
138
- const indentInfo = guessIndentation ( document , 4 , true ) ;
139
-
140
- // Split into lines, normalize each line, and then join back
141
- const lines = content . split ( '\n' ) ;
142
- const normalizedLines = lines . map ( line => {
143
- // Only process lines that have indentation
144
- if ( line . match ( / ^ \s + / ) ) {
145
- return normalizeIndentation ( line , indentInfo . tabSize , indentInfo . insertSpaces ) ;
146
- }
147
- return line ;
148
- } ) ;
149
-
150
- return normalizedLines . join ( '\n' ) ;
151
- }
152
-
153
-
154
- private async generateUpdateTextDocumentEdit ( file : string , change : FileChange , workspaceEdit : WorkspaceEdit , applyIndentationFix : boolean ) {
128
+ private async generateUpdateTextDocumentEdit ( file : string , change : FileChange , workspaceEdit : WorkspaceEdit ) {
155
129
const uri = resolveToolInputPath ( file , this . promptPathRepresentationService ) ;
156
130
const textDocument = await this . workspaceService . openTextDocument ( uri ) ;
157
- let newContent = removeLeadingFilepathComment ( change . newContent ?? '' , textDocument . languageId , file ) ;
158
-
159
- if ( ! applyIndentationFix ) { // the 'old way' of normalizing the edit once it's created
160
- newContent = this . normalizeIndentationStyle ( textDocument , newContent ) ;
161
- }
131
+ const newContent = removeLeadingFilepathComment ( change . newContent ?? '' , textDocument . languageId , file ) ;
162
132
163
133
const lines = newContent ?. split ( '\n' ) ?? [ ] ;
164
134
let path = uri ;
@@ -242,13 +212,11 @@ export class ApplyPatchTool implements ICopilotTool<IApplyPatchToolParams> {
242
212
throw new Error ( 'Missing patch text or stream' ) ;
243
213
}
244
214
245
- const useIndentationFix = ! ! this . experimentationService . getTreatmentVariable < boolean > ( 'vscode' , 'copilotchat.applyPatchIndentationFix' ) ;
246
-
247
215
let commit : Commit | undefined ;
248
216
let healed : string | undefined ;
249
217
const docText : DocText = { } ;
250
218
try {
251
- ( { commit, healed } = await this . buildCommitWithHealing ( options . input . input , docText , options . input . explanation , useIndentationFix , token ) ) ;
219
+ ( { commit, healed } = await this . buildCommitWithHealing ( options . input . input , docText , options . input . explanation , token ) ) ;
252
220
} catch ( error ) {
253
221
if ( error instanceof HealedError ) {
254
222
healed = error . healedPatch ;
@@ -335,7 +303,7 @@ export class ApplyPatchTool implements ICopilotTool<IApplyPatchToolParams> {
335
303
}
336
304
}
337
305
else {
338
- path = await this . generateUpdateTextDocumentEdit ( file , changes , workspaceEdit , useIndentationFix ) ;
306
+ path = await this . generateUpdateTextDocumentEdit ( file , changes , workspaceEdit ) ;
339
307
}
340
308
resourceToOperation . set ( path , ActionType . UPDATE ) ;
341
309
break ;
@@ -502,9 +470,9 @@ export class ApplyPatchTool implements ICopilotTool<IApplyPatchToolParams> {
502
470
return patchEnd === - 1 ? fetchResult . value . slice ( patchStart ) : fetchResult . value . slice ( patchStart , patchEnd + PATCH_SUFFIX . length ) ;
503
471
}
504
472
505
- private async buildCommitWithHealing ( patch : string , docText : DocText , explanation : string , useIndentationFix : boolean , token : CancellationToken ) : Promise < { commit : Commit ; healed ?: string } > {
473
+ private async buildCommitWithHealing ( patch : string , docText : DocText , explanation : string , token : CancellationToken ) : Promise < { commit : Commit ; healed ?: string } > {
506
474
try {
507
- return await this . buildCommit ( patch , docText , useIndentationFix ) ;
475
+ return await this . buildCommit ( patch , docText ) ;
508
476
} catch ( error ) {
509
477
if ( ! ( error instanceof DiffError ) ) {
510
478
throw error ;
@@ -519,7 +487,7 @@ export class ApplyPatchTool implements ICopilotTool<IApplyPatchToolParams> {
519
487
throw error ;
520
488
}
521
489
522
- const { commit } = await this . buildCommit ( healed , docText , useIndentationFix ) ;
490
+ const { commit } = await this . buildCommit ( healed , docText ) ;
523
491
return { commit, healed } ;
524
492
} catch ( healedError ) {
525
493
success = false ;
@@ -543,7 +511,7 @@ export class ApplyPatchTool implements ICopilotTool<IApplyPatchToolParams> {
543
511
}
544
512
}
545
513
546
- private async buildCommit ( patch : string , docText : DocText , useIndentationFix : boolean ) : Promise < { commit : Commit } > {
514
+ private async buildCommit ( patch : string , docText : DocText ) : Promise < { commit : Commit } > {
547
515
const commit = await processPatch ( patch , async ( uri ) => {
548
516
const vscodeUri = resolveToolInputPath ( uri , this . promptPathRepresentationService ) ;
549
517
if ( this . notebookService . hasSupportedNotebooks ( vscodeUri ) ) {
@@ -556,7 +524,7 @@ export class ApplyPatchTool implements ICopilotTool<IApplyPatchToolParams> {
556
524
docText [ vscodeUri . toString ( ) ] = { text : textDocument . getText ( ) } ;
557
525
return textDocument ;
558
526
}
559
- } , useIndentationFix ) ;
527
+ } ) ;
560
528
return { commit } ;
561
529
}
562
530
0 commit comments