Skip to content
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

Merged
merged 1 commit into from
Jun 21, 2018
Merged

Fix indentation issue when convert text edit. #702

merged 1 commit into from
Jun 21, 2018

Conversation

yaohaizh
Copy link
Contributor

@yaohaizh yaohaizh commented Jun 20, 2018

@fbricon
This fixes the additional indentation issue for lambda conversion and other code action. Text cases are fixed.

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) {
Copy link
Contributor

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error applying

@yaohaizh
Copy link
Contributor Author

@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) {
Copy link
Contributor

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) {
Copy link
Contributor

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

@fbricon
Copy link
Contributor

fbricon commented Jun 20, 2018

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

@fbricon
Copy link
Contributor

fbricon commented Jun 20, 2018

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.

@yaohaizh
Copy link
Contributor Author

For format generated issue, I have logged an issue for VSCode team. microsoft/vscode#52272 (comment)

@fbricon fbricon merged commit e50499a into master Jun 21, 2018
@fbricon fbricon deleted the yaohai_dev branch June 21, 2018 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants