Removed commit before EnterHandlerDelegate.postProcessEnter() (implementors must take care of commits if needed)

This commit is contained in:
Rustam Vishnyakov
2016-04-20 13:21:25 +03:00
parent fe3da07870
commit b7d04031ed
4 changed files with 22 additions and 4 deletions
@@ -137,6 +137,7 @@ public class JavadocHelper {
@NotNull
public Pair<JavadocParameterInfo, List<JavadocParameterInfo>> parse(@NotNull PsiFile psiFile, @NotNull Editor editor, int offset) {
List<JavadocParameterInfo> result = new ArrayList<JavadocParameterInfo>();
PsiDocumentManager.getInstance(psiFile.getProject()).commitDocument(editor.getDocument());
final PsiElement elementAtCaret = psiFile.findElementAt(offset);
if (elementAtCaret == null) {
return EMPTY;
@@ -170,7 +170,6 @@ public class EnterHandler extends BaseEnterHandler {
);
action.setForceIndent(forceIndent);
action.run();
documentManager.commitDocument(document);
for (EnterHandlerDelegate delegate : delegates) {
if (delegate.postProcessEnter(file, editor, dataContext) == EnterHandlerDelegate.Result.Stop) {
break;
@@ -16,10 +16,10 @@
package com.intellij.codeInsight.editorActions.enter;
import com.intellij.openapi.extensions.ExtensionPointName;
import com.intellij.openapi.editor.actionSystem.EditorActionHandler;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.actionSystem.EditorActionHandler;
import com.intellij.openapi.extensions.ExtensionPointName;
import com.intellij.openapi.util.Ref;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
@@ -39,5 +39,22 @@ public interface EnterHandlerDelegate {
@NotNull final Ref<Integer> caretAdvance, @NotNull final DataContext dataContext,
@Nullable final EditorActionHandler originalHandler);
/**
* Called at the end of Enter handling after line feed insertion and indentation adjustment.
* <p>
* <b>Important Note: A document associated with the editor has modifications which are not reflected yet in the PSI file. If any
* operations with PSI are needed including a search for PSI elements, the document must be committed first to update the PSI.
* For example:</b>
* <code><pre>
* PsiDocumentManager.getInstance(file.getProject()).commitDocument(editor.getDocument);
* </pre></code>
*
* @param file The PSI file associated with the document.
* @param editor The document.
* @param dataContext The data context passed to the Enter handler.
* @return One of <code>{@link Result} values.</code>
* @see DataContext
* @see com.intellij.psi.PsiDocumentManager
*/
Result postProcessEnter(@NotNull PsiFile file, @NotNull Editor editor, @NotNull DataContext dataContext);
}
@@ -369,6 +369,7 @@ public class PythonEnterHandler extends EnterHandlerDelegateAdapter {
private static void addGoogleDocStringSectionIndent(@NotNull PsiFile file, @NotNull Editor editor, int offset) {
final Document document = editor.getDocument();
PsiDocumentManager.getInstance(file.getProject()).commitDocument(document);
final PsiElement element = file.findElementAt(offset);
if (element != null) {
// Insert additional indentation after section header in Google code style docstrings