Skip to content

Commit 481bb4a

Browse files
author
Kapil Borle
committed
Snap updated range to first and last character
1 parent 14c13bd commit 481bb4a

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/features/DocumentFormatter.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import {
1212
DocumentFormattingEditProvider,
1313
DocumentRangeFormattingEditProvider,
1414
Range,
15-
TextEditor
15+
TextEditor,
16+
TextLine
1617
} from 'vscode';
1718
import { LanguageClient, RequestType } from 'vscode-languageclient';
1819
import Window = vscode.window;
@@ -181,12 +182,6 @@ class PSDocumentFormattingEditProvider implements DocumentFormattingEditProvider
181182
return this.emptyPromise;
182183
}
183184

184-
// Extend the range such that it starts at the first character of the
185-
// start line of the range.
186-
if (range !== null) {
187-
range = this.snapRangeToLineStart(range);
188-
}
189-
190185
let textEdits: Thenable<TextEdit[]> = this.executeRulesInOrder(editor, range, options, 0);
191186
this.lockDocument(document, textEdits);
192187
PSDocumentFormattingEditProvider.showStatusBar(document, textEdits);
@@ -203,9 +198,10 @@ class PSDocumentFormattingEditProvider implements DocumentFormattingEditProvider
203198
PSDocumentFormattingEditProvider.disposeAllStatusBars();
204199
}
205200

206-
private snapRangeToLineStart(range: Range): Range {
207-
// TODO snap to the last character of the end line too!
208-
return range.with({start: range.start.with({character: 0})});
201+
private snapRangeToEdges(range: Range, document: TextDocument): Range {
202+
return range.with({
203+
start: range.start.with({ character: 0 }),
204+
end: document.lineAt(range.end.line).range.end });
209205
}
210206

211207
private getEditor(document: TextDocument): TextEditor {
@@ -262,8 +258,12 @@ class PSDocumentFormattingEditProvider implements DocumentFormattingEditProvider
262258
// have changed the original layout
263259
if (range !== null) {
264260
if (this.lineDiff !== 0) {
265-
range = range.with({end: range.end.translate({lineDelta: this.lineDiff})});
261+
range = range.with({ end: range.end.translate({ lineDelta: this.lineDiff }) });
266262
}
263+
264+
// extend the range such that it starts at the first character of the
265+
// start line of the range.
266+
range = this.snapRangeToEdges(range, document);
267267
}
268268

269269
// reset line difference to 0

0 commit comments

Comments
 (0)