Skip to content

Commit e7e862e

Browse files
authored
Fix end of line trimming in inline completions (microsoft#239297)
fix ned of line trimming
1 parent 09cef23 commit e7e862e

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/vs/editor/contrib/inlineCompletions/browser/model/inlineCompletionsSource.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,9 @@ export class InlineCompletionWithUpdatedRange {
378378
}
379379

380380
private _toIndividualEdits(editRange: Range, _replaceText: string): OffsetEdit {
381+
const eol = this._textModel.getEOL();
381382
const editOriginalText = this._textModel.getValueInRange(editRange);
382-
const editReplaceText = _replaceText.replace(/\r\n|\r|\n/g, this._textModel.getEOL());
383+
const editReplaceText = _replaceText.replace(/\r\n|\r|\n/g, eol);
383384

384385
const diffAlgorithm = linesDiffComputers.getDefault();
385386
const lineDiffs = diffAlgorithm.computeDiff(
@@ -414,7 +415,15 @@ export class InlineCompletionWithUpdatedRange {
414415
const startOffset = this._textModel.getOffsetAt(range.getStartPosition());
415416
const endOffset = this._textModel.getOffsetAt(range.getEndPosition());
416417
const originalRange = OffsetRange.ofStartAndLength(startOffset, endOffset - startOffset);
417-
return new SingleOffsetEdit(originalRange, modifiedText.getValueOfRange(c.modifiedRange));
418+
419+
// TODO: EOL are not properly trimmed by the diffAlgorithm #12680
420+
const replaceText = modifiedText.getValueOfRange(c.modifiedRange);
421+
const oldText = this._textModel.getValueInRange(range);
422+
if (replaceText.endsWith(eol) && oldText.endsWith(eol)) {
423+
return new SingleOffsetEdit(originalRange.deltaEnd(-eol.length), replaceText.slice(0, -eol.length));
424+
}
425+
426+
return new SingleOffsetEdit(originalRange, replaceText);
418427
})
419428
);
420429
}

0 commit comments

Comments
 (0)