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

This commit is contained in:
Mikhail Golubev
2017-03-06 17:15:58 +03:00
parent 496fe62d7a
commit ddc66d519c
2 changed files with 9 additions and 12 deletions
@@ -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);