PY-26131 Commit the document before accessing PSI in PyMethodNameTypedHandler

otherwise we might end up accessing stale PSI tree where there is
"got_message" instead of "info" under the caret.
This commit is contained in:
Mikhail Golubev
2017-10-02 13:58:42 +03:00
parent ba1c99f43d
commit ce1f10dfc6
@@ -50,6 +50,7 @@ public class PyMethodNameTypedHandler extends TypedHandlerDelegate {
final Document document = editor.getDocument();
final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
final int offset = editor.getCaretModel().getOffset();
documentManager.commitDocument(document);
PsiElement token = file.findElementAt(offset - 1);
if (token == null) return Result.CONTINUE; // sanity check: beyond EOL
@@ -76,7 +77,6 @@ public class PyMethodNameTypedHandler extends TypedHandlerDelegate {
pname = "cls";
}
else if (flags.isStaticMethod()) pname = "";
documentManager.commitDocument(document);
// TODO: only print the ")" if Settings require it
int caretOffset = editor.getCaretModel().getOffset();
String textToType = "(" + pname + ")";