Search in sources :

Example 1 with PyCommentBreakerEnterProcessor

use of com.jetbrains.python.codeInsight.editorActions.smartEnter.enterProcessors.PyCommentBreakerEnterProcessor in project intellij-community by JetBrains.

the class PySmartEnterProcessor method process.

private void process(@NotNull final Project project, @NotNull final Editor editor, @NotNull final PsiFile psiFile, final int attempt) throws TooManyAttemptsException {
    if (attempt > MAX_ATTEMPTS) {
        throw new TooManyAttemptsException();
    }
    try {
        commit(editor);
        if (myFirstErrorOffset != Integer.MAX_VALUE) {
            editor.getCaretModel().moveToOffset(myFirstErrorOffset);
        }
        //myFirstErrorOffset = Integer.MAX_VALUE;
        PsiElement statementAtCaret = getStatementAtCaret(editor, psiFile);
        if (statementAtCaret == null) {
            if (!new PyCommentBreakerEnterProcessor().doEnter(editor, psiFile, false)) {
                SmartEnterUtil.plainEnter(editor);
            }
            return;
        }
        List<PsiElement> queue = new ArrayList<>();
        collectAllElements(statementAtCaret, queue, true);
        queue.add(statementAtCaret);
        for (PsiElement element : queue) {
            for (PyFixer fixer : ourFixers) {
                fixer.apply(editor, this, element);
                if (LookupManager.getInstance(project).getActiveLookup() != null) {
                    return;
                }
                PyPsiUtils.assertValid(element);
                if (isUncommited(project) || !element.isValid()) {
                    process(project, editor, psiFile, attempt + 1);
                    return;
                }
            }
        }
        doEnter(statementAtCaret, editor);
    } catch (IncorrectOperationException e) {
        LOG.error(e);
    }
}
Also used : PyCommentBreakerEnterProcessor(com.jetbrains.python.codeInsight.editorActions.smartEnter.enterProcessors.PyCommentBreakerEnterProcessor) ArrayList(java.util.ArrayList) IncorrectOperationException(com.intellij.util.IncorrectOperationException) PsiElement(com.intellij.psi.PsiElement)

Aggregations

PsiElement (com.intellij.psi.PsiElement)1 IncorrectOperationException (com.intellij.util.IncorrectOperationException)1 PyCommentBreakerEnterProcessor (com.jetbrains.python.codeInsight.editorActions.smartEnter.enterProcessors.PyCommentBreakerEnterProcessor)1 ArrayList (java.util.ArrayList)1