Search in sources :

Example 1 with CodeInsightSettings

use of com.intellij.codeInsight.CodeInsightSettings in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoReferenceImporterTest method tearDown.

@Override
protected void tearDown() throws Exception {
    try {
        updateSettings(defaultGoOnTheFly);
        CodeInsightSettings codeInsightSettings = CodeInsightSettings.getInstance();
        codeInsightSettings.ADD_MEMBER_IMPORTS_ON_THE_FLY = defaultJavaMemberOnTheFly;
        codeInsightSettings.ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY = defaultJavaOnTheFly;
    } finally {
        //noinspection ThrowFromFinallyBlock
        super.tearDown();
    }
}
Also used : CodeInsightSettings(com.intellij.codeInsight.CodeInsightSettings)

Example 2 with CodeInsightSettings

use of com.intellij.codeInsight.CodeInsightSettings in project intellij-community by JetBrains.

the class PythonEnterHandler method preprocessEnter.

@Override
public Result preprocessEnter(@NotNull PsiFile file, @NotNull Editor editor, @NotNull Ref<Integer> caretOffset, @NotNull Ref<Integer> caretAdvance, @NotNull DataContext dataContext, EditorActionHandler originalHandler) {
    int offset = caretOffset.get();
    if (editor instanceof EditorWindow) {
        file = InjectedLanguageManager.getInstance(file.getProject()).getTopLevelFile(file);
        editor = InjectedLanguageUtil.getTopLevelEditor(editor);
        offset = editor.getCaretModel().getOffset();
    }
    if (!(file instanceof PyFile)) {
        return Result.Continue;
    }
    final Boolean isSplitLine = DataManager.getInstance().loadFromDataContext(dataContext, SplitLineAction.SPLIT_LINE_KEY);
    if (isSplitLine != null) {
        return Result.Continue;
    }
    final Document doc = editor.getDocument();
    PsiDocumentManager.getInstance(file.getProject()).commitDocument(doc);
    final PsiElement element = file.findElementAt(offset);
    CodeInsightSettings codeInsightSettings = CodeInsightSettings.getInstance();
    if (codeInsightSettings.JAVADOC_STUB_ON_ENTER) {
        PsiElement comment = element;
        if (comment == null && offset != 0) {
            comment = file.findElementAt(offset - 1);
        }
        // """ or '''
        int expectedStringStart = editor.getCaretModel().getOffset() - 3;
        if (comment != null) {
            final DocstringState state = canGenerateDocstring(comment, expectedStringStart, doc);
            if (state != DocstringState.NONE) {
                insertDocStringStub(editor, comment, state);
                return Result.Continue;
            }
        }
    }
    if (element == null) {
        return Result.Continue;
    }
    PsiElement elementParent = element.getParent();
    if (element.getNode().getElementType() == PyTokenTypes.LPAR)
        elementParent = elementParent.getParent();
    if (elementParent instanceof PyParenthesizedExpression || elementParent instanceof PyGeneratorExpression)
        return Result.Continue;
    if (offset > 0 && !(PyTokenTypes.STRING_NODES.contains(element.getNode().getElementType()))) {
        final PsiElement prevElement = file.findElementAt(offset - 1);
        if (prevElement == element)
            return Result.Continue;
    }
    if (PyTokenTypes.TRIPLE_NODES.contains(element.getNode().getElementType()) || element.getNode().getElementType() == PyTokenTypes.DOCSTRING) {
        return Result.Continue;
    }
    final PsiElement prevElement = file.findElementAt(offset - 1);
    PyStringLiteralExpression string = PsiTreeUtil.findElementOfClassAtOffset(file, offset, PyStringLiteralExpression.class, false);
    if (string != null && prevElement != null && PyTokenTypes.STRING_NODES.contains(prevElement.getNode().getElementType()) && string.getTextOffset() < offset && !(element.getNode() instanceof PsiWhiteSpace)) {
        final String stringText = element.getText();
        final int prefixLength = PyStringLiteralExpressionImpl.getPrefixLength(stringText);
        if (string.getTextOffset() + prefixLength >= offset) {
            return Result.Continue;
        }
        final String pref = element.getText().substring(0, prefixLength);
        final String quote = element.getText().substring(prefixLength, prefixLength + 1);
        final boolean nextIsBackslash = "\\".equals(doc.getText(TextRange.create(offset - 1, offset)));
        final boolean isEscapedQuote = quote.equals(doc.getText(TextRange.create(offset, offset + 1))) && nextIsBackslash;
        final boolean isEscapedBackslash = "\\".equals(doc.getText(TextRange.create(offset - 2, offset - 1))) && nextIsBackslash;
        if (nextIsBackslash && !isEscapedQuote && !isEscapedBackslash)
            return Result.Continue;
        final StringBuilder replacementString = new StringBuilder();
        myPostprocessShift = prefixLength + quote.length();
        if (PsiTreeUtil.getParentOfType(string, IMPLICIT_WRAP_CLASSES) != null) {
            replacementString.append(quote).append(pref).append(quote);
            doc.insertString(offset, replacementString);
            caretOffset.set(caretOffset.get() + 1);
            return Result.Continue;
        } else {
            if (isEscapedQuote) {
                replacementString.append(quote);
                caretOffset.set(caretOffset.get() + 1);
            }
            replacementString.append(quote).append(" \\").append(pref);
            if (!isEscapedQuote)
                replacementString.append(quote);
            doc.insertString(offset, replacementString.toString());
            caretOffset.set(caretOffset.get() + 3);
            return Result.Continue;
        }
    }
    if (!PyCodeInsightSettings.getInstance().INSERT_BACKSLASH_ON_WRAP) {
        return Result.Continue;
    }
    return checkInsertBackslash(file, caretOffset, dataContext, offset, doc);
}
Also used : PyCodeInsightSettings(com.jetbrains.python.codeInsight.PyCodeInsightSettings) CodeInsightSettings(com.intellij.codeInsight.CodeInsightSettings) Document(com.intellij.openapi.editor.Document) EditorWindow(com.intellij.injected.editor.EditorWindow)

Example 3 with CodeInsightSettings

use of com.intellij.codeInsight.CodeInsightSettings in project intellij-community by JetBrains.

the class PythonSpaceHandler method charTyped.

@Override
public Result charTyped(char c, Project project, @NotNull Editor editor, @NotNull PsiFile file) {
    CodeInsightSettings codeInsightSettings = CodeInsightSettings.getInstance();
    if (c == ' ' && codeInsightSettings.JAVADOC_STUB_ON_ENTER) {
        int offset = editor.getCaretModel().getOffset();
        PsiElement element = file.findElementAt(offset);
        if (element == null && offset > 1) {
            element = file.findElementAt(offset - 2);
        }
        if (element == null)
            return Result.CONTINUE;
        // """ or ''' plus space char
        int expectedStringStart = offset - 4;
        final Document document = editor.getDocument();
        if (PythonEnterHandler.canGenerateDocstring(element, expectedStringStart, document) == DocstringState.INCOMPLETE) {
            final PyDocStringOwner docOwner = PsiTreeUtil.getParentOfType(element, PyDocStringOwner.class);
            if (docOwner != null) {
                final String quotes = document.getText(TextRange.from(expectedStringStart, 3));
                final String docString = PyDocstringGenerator.forDocStringOwner(docOwner).forceNewMode().withInferredParameters(true).withQuotes(quotes).buildDocString();
                document.insertString(offset, docString.substring(3));
                if (!StringUtil.isEmptyOrSpaces(docString.substring(3, docString.length() - 3))) {
                    editor.getCaretModel().moveCaretRelatively(100, 1, false, false, false);
                }
                return Result.STOP;
            }
        }
    }
    return Result.CONTINUE;
}
Also used : CodeInsightSettings(com.intellij.codeInsight.CodeInsightSettings) PyDocStringOwner(com.jetbrains.python.psi.PyDocStringOwner) Document(com.intellij.openapi.editor.Document) PsiElement(com.intellij.psi.PsiElement)

Example 4 with CodeInsightSettings

use of com.intellij.codeInsight.CodeInsightSettings in project intellij-community by JetBrains.

the class PySmartEnterTest method testDocRest.

public void testDocRest() {
    CodeInsightSettings codeInsightSettings = CodeInsightSettings.getInstance();
    boolean oldStubOnEnter = codeInsightSettings.JAVADOC_STUB_ON_ENTER;
    codeInsightSettings.JAVADOC_STUB_ON_ENTER = true;
    PyDocumentationSettings documentationSettings = PyDocumentationSettings.getInstance(myFixture.getModule());
    documentationSettings.setFormat(DocStringFormat.REST);
    try {
        doTest();
    } finally {
        documentationSettings.setFormat(DocStringFormat.PLAIN);
        codeInsightSettings.JAVADOC_STUB_ON_ENTER = oldStubOnEnter;
    }
}
Also used : CodeInsightSettings(com.intellij.codeInsight.CodeInsightSettings) PyCodeInsightSettings(com.jetbrains.python.codeInsight.PyCodeInsightSettings) PyDocumentationSettings(com.jetbrains.python.documentation.PyDocumentationSettings)

Example 5 with CodeInsightSettings

use of com.intellij.codeInsight.CodeInsightSettings in project intellij-community by JetBrains.

the class EditorOptionsPanel method isModified.

@Override
public boolean isModified() {
    EditorSettingsExternalizable editorSettings = EditorSettingsExternalizable.getInstance();
    CodeInsightSettings codeInsightSettings = CodeInsightSettings.getInstance();
    UISettings uiSettings = UISettings.getInstance();
    VcsApplicationSettings vcsSettings = VcsApplicationSettings.getInstance();
    // Display
    boolean isModified = isModified(myCbSmoothScrolling, editorSettings.isSmoothScrolling());
    // Brace highlighting
    isModified |= isModified(myCbHighlightBraces, codeInsightSettings.HIGHLIGHT_BRACES);
    isModified |= isModified(myCbHighlightScope, codeInsightSettings.HIGHLIGHT_SCOPE);
    isModified |= isModified(myCbHighlightIdentifierUnderCaret, codeInsightSettings.HIGHLIGHT_IDENTIFIER_UNDER_CARET);
    // Virtual space
    isModified |= isModified(myCbUseSoftWrapsAtEditor, editorSettings.isUseSoftWraps(SoftWrapAppliancePlaces.MAIN_EDITOR));
    isModified |= isModified(myCbUseCustomSoftWrapIndent, editorSettings.isUseCustomSoftWrapIndent());
    isModified |= editorSettings.getCustomSoftWrapIndent() != getCustomSoftWrapIndent();
    isModified |= isModified(myCbShowSoftWrapsOnlyOnCaretLine, !editorSettings.isAllSoftWrapsShown());
    isModified |= isModified(myCbVirtualSpace, editorSettings.isVirtualSpace());
    isModified |= isModified(myCbCaretInsideTabs, editorSettings.isCaretInsideTabs());
    isModified |= isModified(myCbVirtualPageAtBottom, editorSettings.isAdditionalPageAtBottom());
    // Limits
    isModified |= getMaxClipboardContents() != uiSettings.getMaxClipboardContents();
    // Paste
    // Strip trailing spaces, ensure EOL on EOF on save
    isModified |= !getStripTrailingSpacesValue().equals(editorSettings.getStripTrailingSpaces());
    isModified |= isModified(myCbKeepTrailingSpacesOnCaretLine, editorSettings.isKeepTrailingSpacesOnCaretLine());
    isModified |= isModified(myCbEnsureBlankLineBeforeCheckBox, editorSettings.isEnsureNewLineAtEOF());
    isModified |= isModified(myCbShowQuickDocOnMouseMove, editorSettings.isShowQuickDocOnMouseOverElement());
    isModified |= isModified(myQuickDocDelayTextField, editorSettings.getQuickDocOnMouseOverElementDelayMillis(), EditorSettingsExternalizable.QUICK_DOC_DELAY_RANGE);
    // advanced mouse
    isModified |= isModified(myCbEnableDnD, editorSettings.isDndEnabled());
    isModified |= isModified(myCbEnableWheelFontChange, editorSettings.isWheelFontChangeEnabled());
    isModified |= isModified(myCbHonorCamelHumpsWhenSelectingByClicking, editorSettings.isMouseClickSelectionHonorsCamelWords());
    isModified |= isModified(myRbPreferMovingCaret, editorSettings.isRefrainFromScrolling());
    isModified |= isModified(myRecentFilesLimitField, UISettings.getInstance().getRecentFilesLimit(), RECENT_FILES_RANGE);
    isModified |= isModified(myCbRenameLocalVariablesInplace, editorSettings.isVariableInplaceRenameEnabled());
    isModified |= isModified(myPreselectCheckBox, editorSettings.isPreselectRename());
    isModified |= isModified(myShowInlineDialogForCheckBox, editorSettings.isShowInlineLocalDialog());
    isModified |= isModified(myShowNotificationAfterReformatCodeCheckBox, editorSettings.getOptions().SHOW_NOTIFICATION_AFTER_REFORMAT_CODE_ACTION);
    isModified |= isModified(myShowNotificationAfterOptimizeImportsCheckBox, editorSettings.getOptions().SHOW_NOTIFICATION_AFTER_OPTIMIZE_IMPORTS_ACTION);
    isModified |= isModified(myShowLSTInGutterCheckBox, vcsSettings.SHOW_LST_GUTTER_MARKERS);
    isModified |= isModified(myShowWhitespacesModificationsInLSTGutterCheckBox, vcsSettings.SHOW_WHITESPACES_IN_LST);
    isModified |= myErrorHighlightingPanel.isModified();
    RichCopySettings settings = RichCopySettings.getInstance();
    isModified |= isModified(myCbEnableRichCopyByDefault, settings.isEnabled());
    isModified |= !Comparing.equal(settings.getSchemeName(), myRichCopyColorSchemeComboBox.getSelectedItem());
    return isModified;
}
Also used : CodeInsightSettings(com.intellij.codeInsight.CodeInsightSettings) RichCopySettings(com.intellij.openapi.editor.richcopy.settings.RichCopySettings) UISettings(com.intellij.ide.ui.UISettings) VcsApplicationSettings(com.intellij.openapi.vcs.VcsApplicationSettings) EditorSettingsExternalizable(com.intellij.openapi.editor.ex.EditorSettingsExternalizable)

Aggregations

CodeInsightSettings (com.intellij.codeInsight.CodeInsightSettings)27 EditorSettingsExternalizable (com.intellij.openapi.editor.ex.EditorSettingsExternalizable)7 RichCopySettings (com.intellij.openapi.editor.richcopy.settings.RichCopySettings)4 PyCodeInsightSettings (com.jetbrains.python.codeInsight.PyCodeInsightSettings)4 DaemonCodeAnalyzerSettings (com.intellij.codeInsight.daemon.DaemonCodeAnalyzerSettings)3 UISettings (com.intellij.ide.ui.UISettings)3 Project (com.intellij.openapi.project.Project)3 VcsApplicationSettings (com.intellij.openapi.vcs.VcsApplicationSettings)3 PyDocumentationSettings (com.jetbrains.python.documentation.PyDocumentationSettings)3 Document (com.intellij.openapi.editor.Document)2 PsiFile (com.intellij.psi.PsiFile)2 NotNull (org.jetbrains.annotations.NotNull)2 CompletionProcess (com.intellij.codeInsight.completion.CompletionProcess)1 CamelHumpMatcher (com.intellij.codeInsight.completion.impl.CamelHumpMatcher)1 QuickDocOnMouseOverManager (com.intellij.codeInsight.documentation.QuickDocOnMouseOverManager)1 SmartBackspaceMode (com.intellij.codeInsight.editorActions.SmartBackspaceMode)1 EnterHandlerDelegate (com.intellij.codeInsight.editorActions.enter.EnterHandlerDelegate)1 EditorWindow (com.intellij.injected.editor.EditorWindow)1 UsageDescriptor (com.intellij.internal.statistic.beans.UsageDescriptor)1 Disposable (com.intellij.openapi.Disposable)1