Search in sources :

Example 31 with EditorSettingsExternalizable

use of com.intellij.openapi.editor.ex.EditorSettingsExternalizable in project intellij-community by JetBrains.

the class Pep8ExternalAnnotator method ignoreDueToSettings.

private static boolean ignoreDueToSettings(Project project, Problem problem, @Nullable PsiElement element) {
    final EditorSettingsExternalizable editorSettings = EditorSettingsExternalizable.getInstance();
    if (!editorSettings.getStripTrailingSpaces().equals(EditorSettingsExternalizable.STRIP_TRAILING_SPACES_NONE)) {
        // ignore trailing spaces errors if they're going to disappear after save
        if (problem.myCode.equals("W291") || problem.myCode.equals("W293")) {
            return true;
        }
    }
    final CodeStyleSettings codeStyleSettings = CodeStyleSettingsManager.getSettings(project);
    final CommonCodeStyleSettings commonSettings = codeStyleSettings.getCommonSettings(PythonLanguage.getInstance());
    final PyCodeStyleSettings pySettings = codeStyleSettings.getCustomSettings(PyCodeStyleSettings.class);
    if (element instanceof PsiWhiteSpace) {
        // E303 too many blank lines (num)
        if (problem.myCode.equals("E303")) {
            final Matcher matcher = E303_LINE_COUNT_PATTERN.matcher(problem.myDescription);
            if (matcher.matches()) {
                final int reportedBlanks = Integer.parseInt(matcher.group(1));
                final PsiElement nonWhitespaceAfter = PyPsiUtils.getNextNonWhitespaceSibling(element);
                final PsiElement nonWhitespaceBefore = PyPsiUtils.getPrevNonWhitespaceSibling(element);
                final boolean classNearby = nonWhitespaceBefore instanceof PyClass || nonWhitespaceAfter instanceof PyClass;
                final boolean functionNearby = nonWhitespaceBefore instanceof PyFunction || nonWhitespaceAfter instanceof PyFunction;
                if (functionNearby || classNearby) {
                    if (PyUtil.isTopLevel(element)) {
                        if (reportedBlanks <= pySettings.BLANK_LINES_AROUND_TOP_LEVEL_CLASSES_FUNCTIONS) {
                            return true;
                        }
                    } else {
                        // Blanks around classes have priority over blanks around functions as defined in Python spacing builder
                        if (classNearby && reportedBlanks <= commonSettings.BLANK_LINES_AROUND_CLASS || functionNearby && reportedBlanks <= commonSettings.BLANK_LINES_AROUND_METHOD) {
                            return true;
                        }
                    }
                }
            }
        }
        // Note that E222 (multiple spaces after operator) is not suppressed, though. 
        if (problem.myCode.equals("E251") && (element.getParent() instanceof PyParameter && pySettings.SPACE_AROUND_EQ_IN_NAMED_PARAMETER || element.getParent() instanceof PyKeywordArgument && pySettings.SPACE_AROUND_EQ_IN_KEYWORD_ARGUMENT)) {
            return true;
        }
    }
    // thus underlying PSI element is not necessarily a whitespace
    if (problem.myCode.equals("W191") && codeStyleSettings.useTabCharacter(PythonFileType.INSTANCE)) {
        return true;
    }
    return false;
}
Also used : Matcher(java.util.regex.Matcher) EditorSettingsExternalizable(com.intellij.openapi.editor.ex.EditorSettingsExternalizable) CodeStyleSettings(com.intellij.psi.codeStyle.CodeStyleSettings) CommonCodeStyleSettings(com.intellij.psi.codeStyle.CommonCodeStyleSettings) PyCodeStyleSettings(com.jetbrains.python.formatter.PyCodeStyleSettings) CommonCodeStyleSettings(com.intellij.psi.codeStyle.CommonCodeStyleSettings) PyCodeStyleSettings(com.jetbrains.python.formatter.PyCodeStyleSettings) PsiElement(com.intellij.psi.PsiElement) PsiWhiteSpace(com.intellij.psi.PsiWhiteSpace)

Aggregations

EditorSettingsExternalizable (com.intellij.openapi.editor.ex.EditorSettingsExternalizable)31 CodeInsightSettings (com.intellij.codeInsight.CodeInsightSettings)7 UISettings (com.intellij.ide.ui.UISettings)7 RichCopySettings (com.intellij.openapi.editor.richcopy.settings.RichCopySettings)4 CommonCodeStyleSettings (com.intellij.psi.codeStyle.CommonCodeStyleSettings)4 Document (com.intellij.openapi.editor.Document)3 VcsApplicationSettings (com.intellij.openapi.vcs.VcsApplicationSettings)3 CodeStyleSettings (com.intellij.psi.codeStyle.CodeStyleSettings)3 QuickDocOnMouseOverManager (com.intellij.codeInsight.documentation.QuickDocOnMouseOverManager)1 SmartBackspaceMode (com.intellij.codeInsight.editorActions.SmartBackspaceMode)1 DocumentWindow (com.intellij.injected.editor.DocumentWindow)1 UsageDescriptor (com.intellij.internal.statistic.beans.UsageDescriptor)1 Editor (com.intellij.openapi.editor.Editor)1 LogicalPosition (com.intellij.openapi.editor.LogicalPosition)1 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)1 FileDocumentManager (com.intellij.openapi.fileEditor.FileDocumentManager)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiElement (com.intellij.psi.PsiElement)1 PsiWhiteSpace (com.intellij.psi.PsiWhiteSpace)1