-
Notifications
You must be signed in to change notification settings - Fork 408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix indentation issue when convert text edit. #702
Conversation
te.setNewText(content); | ||
converted.add(te); | ||
} catch (MalformedTreeException | BadLocationException | CoreException e) { | ||
JavaLanguageServerPlugin.logException("Error converting TextEdits", e); | ||
} | ||
return false; // do not visit children | ||
} | ||
|
||
private String applygetSourceModifier(String content, ISourceModifier modifier) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
applySourceModifier
try { | ||
newEdit.apply(subDocument, TextEdit.NONE); | ||
} catch (BadLocationException e) { | ||
JavaLanguageServerPlugin.logException("Error apply edit to document", e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error applying
@fbricon Updated PR |
@@ -174,11 +183,33 @@ public boolean visit(MoveTargetEdit edit) { | |||
Document doc = new Document(compilationUnit.getSource()); | |||
edit.apply(doc, TextEdit.UPDATE_REGIONS); | |||
String content = doc.get(edit.getSourceEdit().getOffset(), edit.getSourceEdit().getLength()); | |||
if (edit.getSourceEdit() != null && edit.getSourceEdit().getSourceModifier() != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if edit.getSourceEdit()
was null, it'd have NPE'd the line before. The null check should be done earlier
@@ -128,6 +132,11 @@ public boolean visit(CopyTargetEdit edit) { | |||
Document doc = new Document(compilationUnit.getSource()); | |||
edit.apply(doc, TextEdit.UPDATE_REGIONS); | |||
String content = doc.get(edit.getSourceEdit().getOffset(), edit.getSourceEdit().getLength()); | |||
|
|||
if (edit.getSourceEdit() != null && edit.getSourceEdit().getSourceModifier() != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if edit.getSourceEdit()
was null, it'd have NPE'd the line before. The null check should be done earlier
Something's still weird. If you have: public interface Title {
public String name();
}
public static void main(String[] args) {
new Titl<complete here>
} Applying the completion item yields: public static void main(String[] args) {
new Title(){
@Override
public String name() {
return null;
}
};
} but once the document, selection or block is formatted, then the indentation is decreased: public static void main(String[] args) {
new Title() {
@Override
public String name() {
return null;
}
};
} I'd expect the completion to provide properly formatted code there |
so that last issue also exists in master, I'll open a separate bug report. @yaohaizh once you fix the NPE checks I mentioned, feel free to apply this PR. |
For format generated issue, I have logged an issue for VSCode team. microsoft/vscode#52272 (comment) |
@fbricon
This fixes the additional indentation issue for lambda conversion and other code action. Text cases are fixed.