Skip to content

Commit 4037db9

Browse files
authored
remove extra adjustments to textEdit for CDD (#11110)
* remove extra adjustments to textEdit * combine conditionals
1 parent a67c661 commit 4037db9

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

Extension/src/LanguageServer/client.ts

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3500,7 +3500,6 @@ export class DefaultClient implements Client {
35003500
const workspaceEdits: vscode.WorkspaceEdit = new vscode.WorkspaceEdit();
35013501
let modifiedDocument: vscode.Uri | undefined;
35023502
let lastEdit: vscode.TextEdit | undefined;
3503-
let editPositionAdjustment: number = 0;
35043503
let selectionPositionAdjustment: number = 0;
35053504
for (const file in result.edit.changes) {
35063505
const uri: vscode.Uri = vscode.Uri.file(file);
@@ -3510,23 +3509,13 @@ export class DefaultClient implements Client {
35103509
for (const edit of result.edit.changes[file]) {
35113510
const range: vscode.Range = makeVscodeRange(edit.range);
35123511
// Get new lines from an edit for: #include header file.
3513-
if (lastEdit && lastEdit.newText.includes("#include")) {
3514-
if (lastEdit.range.isEqual(range)) {
3515-
// Destination file is empty.
3516-
// The edit positions for #include header file and definition or declaration are the same.
3517-
selectionPositionAdjustment = (lastEdit.newText.match(/\n/g) || []).length;
3518-
} else {
3519-
// Destination file is not empty.
3520-
// VS Code workspace.applyEdit calculates the position of subsequent edits.
3521-
// That is, the positions of text edits that are originally calculated by the language server
3522-
// are adjusted based on the number of text edits applied by VS Code workspace.applyEdit.
3523-
// Since the language server's refactoring API already pre-calculates the positions of multiple text edits,
3524-
// re-adjust the new line of the next text edit for the VS Code applyEdit to calculate again.
3525-
editPositionAdjustment = (lastEdit.newText.match(/\n/g) || []).length;
3526-
}
3512+
if (lastEdit && lastEdit.newText.includes("#include") && lastEdit.range.isEqual(range)) {
3513+
// Destination file is empty.
3514+
// The edit positions for #include header file and definition or declaration are the same.
3515+
selectionPositionAdjustment = (lastEdit.newText.match(/\n/g) || []).length;
35273516
}
35283517
lastEdit = new vscode.TextEdit(range, edit.newText);
3529-
const position: vscode.Position = new vscode.Position(edit.range.start.line - editPositionAdjustment, edit.range.start.character);
3518+
const position: vscode.Position = new vscode.Position(edit.range.start.line, edit.range.start.character);
35303519
workspaceEdits.insert(uri, position, edit.newText);
35313520
}
35323521
modifiedDocument = uri;

0 commit comments

Comments
 (0)