Commit 4c1cbb95 authored by Mikhail Golubev's avatar Mikhail Golubev
Browse files

PY-22422 PyPreFormatProcessor doesn't need to unblock/commit document, it operates on PSI

parent b7b82877
Branches unavailable Tags unavailable
No related merge requests found
Showing with 9 additions and 12 deletions
+9 -12
......@@ -155,9 +155,12 @@ public class PyFromImportPostFormatProcessor implements PostFormatProcessor {
return newFromImport;
}
else {
final int oldLength = fromImport.getTextLength();
// Add only trailing comma
final PsiElement comma = fromImport.addAfter(generator.createComma().getPsi(), allNames[allNames.length - 1]);
codeStyleManager.reformat(comma);
fromImport.addAfter(generator.createComma().getPsi(), allNames[allNames.length - 1]);
// Adjust spaces around the comma if necessary
codeStyleManager.reformat(fromImport, true);
myHelper.updateResultRange(oldLength, fromImport.getTextLength());
return fromImport;
}
}
......
......@@ -82,16 +82,10 @@ public class PyPreFormatProcessor implements PreFormatProcessor {
final PsiDocumentManager manager = PsiDocumentManager.getInstance(myProject);
final Document document = manager.getDocument(element.getContainingFile());
if (document != null) {
manager.doPostponedOperationsAndUnblockDocument(document);
try {
// collect all comments
element.accept(this);
for (Couple<PsiComment> pair : myCommentReplacements) {
pair.getFirst().replace(pair.getSecond());
}
}
finally {
manager.commitDocument(document);
// collect all comments
element.accept(this);
for (Couple<PsiComment> pair : myCommentReplacements) {
pair.getFirst().replace(pair.getSecond());
}
}
return TextRange.create(range.getStartOffset(), range.getEndOffset() + myDelta);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment