Skip to content

Commit

Permalink
Fix extract to function formatting. (#12679)
Browse files Browse the repository at this point in the history
  • Loading branch information
sean-mcmanus authored Sep 6, 2024
1 parent 8111083 commit 8718b96
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Extension/src/LanguageServer/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3774,6 +3774,7 @@ export class DefaultClient implements Client {
const formatRangeStartLine: number = range.start.line + lineOffset;
let rangeStartLine: number = formatRangeStartLine;
let rangeStartCharacter: number = 0;
let startWithNewLine: boolean = true;
if (edit.newText.startsWith("\r\n\r\n")) {
rangeStartCharacter = 4;
rangeStartLine += 2;
Expand All @@ -3786,12 +3787,16 @@ export class DefaultClient implements Client {
} else if (edit.newText.startsWith("\n")) {
rangeStartCharacter = 1;
rangeStartLine += 1;
} else {
startWithNewLine = false;
}
const newFormatRange: vscode.Range = new vscode.Range(
new vscode.Position(formatRangeStartLine + (nextLineOffset < 0 ? nextLineOffset : 0), range.start.character),
new vscode.Position(rangeStartLine + (nextLineOffset < 0 ? 0 : nextLineOffset),
new vscode.Position(formatRangeStartLine + (nextLineOffset < 0 ? 0 : nextLineOffset),
isReplace ? range.end.character :
range.end.character + edit.newText.length - rangeStartCharacter));
((startWithNewLine ? 0 : range.end.character) + (edit.newText.endsWith("\n") ? 0 : edit.newText.length - rangeStartCharacter))
)
);
if (isSourceFile) {
sourceFormatUriAndRanges.push({ uri, range: newFormatRange });
} else {
Expand Down

0 comments on commit 8718b96

Please sign in to comment.