Skip to content

Commit

Permalink
Fix issue computing replace offset text edit.
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioz committed Apr 28, 2024
1 parent c506615 commit 279d1d8
Showing 1 changed file with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,19 @@ public ComputedInfo(String realImportRep, int fReplacementOffset, int fLen, Stri
public List<ReplaceEdit> replaceEdit = new ArrayList<ReplaceEdit>(2);

public void replace(int offset, int length, String text) {
replaceEdit.add(new ReplaceEdit(offset, length, text));
try {
replaceEdit.add(new ReplaceEdit(offset, length, text));
} catch (Exception e) {
Log.log("Error trying to create ReplaceEdit with offset: " + offset + " len: " + length + " text: "
+ text, e);
}
}

}

private IDocument document;
private char trigger;
private int offset;
private final int offset;
private boolean addLocalImport;
private boolean addLocalImportsOnTopOfMethod;
private boolean groupImports;
Expand Down Expand Up @@ -234,12 +239,12 @@ public void createTextEdit(ComputedInfo computedInfo) {
lastImportLineBuf.deleteLast();
}

offset = TextSelectionUtils.getAbsoluteCursorOffset(document, lastImportLineNum,
int replaceOffset = TextSelectionUtils.getAbsoluteCursorOffset(document, lastImportLineNum,
lastImportLineBuf.length());
offset -= lastImportLineBuf.length() - lastImportLineBuf.rightTrim().length();
replaceOffset -= lastImportLineBuf.length() - lastImportLineBuf.rightTrim().length();

while (lastImportLineBuf.endsWith(',')) {
offset--;
replaceOffset--;
lastImportLineBuf.deleteLast();
}

Expand All @@ -254,12 +259,12 @@ public void createTextEdit(ComputedInfo computedInfo) {
+ realImportHandleInfo.getImportedStr().get(0);
}
computedInfo.importLen = strToAdd.length();
computedInfo.replace(offset, 0, strToAdd);
computedInfo.replace(replaceOffset, 0, strToAdd);
return;
} else {
//regular addition (it won't pass the number of columns expected).
computedInfo.importLen = strToAdd.length();
computedInfo.replace(offset, 0, strToAdd);
computedInfo.replace(replaceOffset, 0, strToAdd);
return;
}
}
Expand Down

0 comments on commit 279d1d8

Please sign in to comment.