Search in sources :

Example 6 with CodeInsightSettings

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

the class EditorSmartKeysConfigurable method reset.

@Override
public void reset() {
    EditorSettingsExternalizable editorSettings = EditorSettingsExternalizable.getInstance();
    CodeInsightSettings codeInsightSettings = CodeInsightSettings.getInstance();
    // Paste
    switch(codeInsightSettings.REFORMAT_ON_PASTE) {
        case CodeInsightSettings.NO_REFORMAT:
            myReformatOnPasteCombo.setSelectedItem(NO_REFORMAT);
            break;
        case CodeInsightSettings.INDENT_BLOCK:
            myReformatOnPasteCombo.setSelectedItem(INDENT_BLOCK);
            break;
        case CodeInsightSettings.INDENT_EACH_LINE:
            myReformatOnPasteCombo.setSelectedItem(INDENT_EACH_LINE);
            break;
        case CodeInsightSettings.REFORMAT_BLOCK:
            myReformatOnPasteCombo.setSelectedItem(REFORMAT_BLOCK);
            break;
    }
    myCbSmartHome.setSelected(editorSettings.isSmartHome());
    myCbSmartEnd.setSelected(codeInsightSettings.SMART_END_ACTION);
    myCbSmartIndentOnEnter.setSelected(codeInsightSettings.SMART_INDENT_ON_ENTER);
    myCbInsertPairCurlyBraceOnEnter.setSelected(codeInsightSettings.INSERT_BRACE_ON_ENTER);
    myCbInsertJavadocStubOnEnter.setSelected(codeInsightSettings.JAVADOC_STUB_ON_ENTER);
    myCbInsertPairBracket.setSelected(codeInsightSettings.AUTOINSERT_PAIR_BRACKET);
    myCbInsertPairQuote.setSelected(codeInsightSettings.AUTOINSERT_PAIR_QUOTE);
    myCbReformatBlockOnTypingRBrace.setSelected(codeInsightSettings.REFORMAT_BLOCK_ON_RBRACE);
    myCbCamelWords.setSelected(editorSettings.isCamelWords());
    myCbSurroundSelectionOnTyping.setSelected(codeInsightSettings.SURROUND_SELECTION_ON_QUOTE_TYPED);
    myCbEnableAddingCaretsOnDoubleCtrlArrows.setSelected(editorSettings.addCaretsOnDoubleCtrl());
    SmartBackspaceMode backspaceMode = codeInsightSettings.getBackspaceMode();
    switch(backspaceMode) {
        case OFF:
            mySmartBackspaceCombo.setSelectedItem(OFF);
            break;
        case INDENT:
            mySmartBackspaceCombo.setSelectedItem(SIMPLE);
            break;
        case AUTOINDENT:
            mySmartBackspaceCombo.setSelectedItem(SMART);
            break;
        default:
            LOG.error("Unexpected smart backspace mode value: " + backspaceMode);
    }
    super.reset();
}
Also used : CodeInsightSettings(com.intellij.codeInsight.CodeInsightSettings) SmartBackspaceMode(com.intellij.codeInsight.editorActions.SmartBackspaceMode) EditorSettingsExternalizable(com.intellij.openapi.editor.ex.EditorSettingsExternalizable)

Example 7 with CodeInsightSettings

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

the class EnterHandler method executeWriteActionInner.

private void executeWriteActionInner(Editor editor, Caret caret, DataContext dataContext, Project project) {
    CodeInsightSettings settings = CodeInsightSettings.getInstance();
    if (project == null) {
        myOriginalHandler.execute(editor, caret, dataContext);
        return;
    }
    final Document document = editor.getDocument();
    final PsiFile file = PsiUtilBase.getPsiFileInEditor(editor, project);
    if (file == null) {
        myOriginalHandler.execute(editor, caret, dataContext);
        return;
    }
    CommandProcessor.getInstance().setCurrentCommandName(CodeInsightBundle.message("command.name.typing"));
    EditorModificationUtil.deleteSelectedText(editor);
    int caretOffset = editor.getCaretModel().getOffset();
    CharSequence text = document.getCharsSequence();
    int length = document.getTextLength();
    if (caretOffset < length && text.charAt(caretOffset) != '\n') {
        int offset1 = CharArrayUtil.shiftBackward(text, caretOffset, " \t");
        if (offset1 < 0 || text.charAt(offset1) == '\n') {
            int offset2 = CharArrayUtil.shiftForward(text, offset1 + 1, " \t");
            boolean isEmptyLine = offset2 >= length || text.charAt(offset2) == '\n';
            if (!isEmptyLine) {
                // we are in leading spaces of a non-empty line
                myOriginalHandler.execute(editor, caret, dataContext);
                return;
            }
        }
    }
    boolean forceIndent = false;
    boolean forceSkipIndent = false;
    Ref<Integer> caretOffsetRef = new Ref<>(caretOffset);
    Ref<Integer> caretAdvanceRef = new Ref<>(0);
    final EnterHandlerDelegate[] delegates = Extensions.getExtensions(EnterHandlerDelegate.EP_NAME);
    for (EnterHandlerDelegate delegate : delegates) {
        EnterHandlerDelegate.Result result = delegate.preprocessEnter(file, editor, caretOffsetRef, caretAdvanceRef, dataContext, myOriginalHandler);
        if (caretOffsetRef.get() > document.getTextLength()) {
            throw new AssertionError("Wrong caret offset change by " + delegate);
        }
        if (result == EnterHandlerDelegate.Result.Stop) {
            return;
        }
        if (result != EnterHandlerDelegate.Result.Continue) {
            if (result == EnterHandlerDelegate.Result.DefaultForceIndent) {
                forceIndent = true;
            } else if (result == EnterHandlerDelegate.Result.DefaultSkipIndent) {
                forceSkipIndent = true;
            }
            break;
        }
    }
    // update after changes done in preprocessEnter()
    text = document.getCharsSequence();
    caretOffset = caretOffsetRef.get().intValue();
    boolean isFirstColumn = caretOffset == 0 || text.charAt(caretOffset - 1) == '\n';
    final boolean insertSpace = !isFirstColumn && !(caretOffset >= text.length() || text.charAt(caretOffset) == ' ' || text.charAt(caretOffset) == '\t');
    editor.getCaretModel().moveToOffset(caretOffset);
    myOriginalHandler.execute(editor, caret, dataContext);
    if (!editor.isInsertMode() || forceSkipIndent) {
        return;
    }
    if (settings.SMART_INDENT_ON_ENTER || forceIndent) {
        caretOffset += 1;
        caretOffset = CharArrayUtil.shiftForward(editor.getDocument().getCharsSequence(), caretOffset, " \t");
    } else {
        caretOffset = editor.getCaretModel().getOffset();
    }
    final DoEnterAction action = new DoEnterAction(file, editor, document, dataContext, caretOffset, !insertSpace, caretAdvanceRef.get(), project);
    action.setForceIndent(forceIndent);
    action.run();
    for (EnterHandlerDelegate delegate : delegates) {
        if (delegate.postProcessEnter(file, editor, dataContext) == EnterHandlerDelegate.Result.Stop) {
            break;
        }
    }
    if (settings.SMART_INDENT_ON_ENTER && action.isIndentAdjustmentNeeded()) {
        FormatterBasedIndentAdjuster.scheduleIndentAdjustment(project, document, editor.getCaretModel().getOffset());
    }
}
Also used : CodeInsightSettings(com.intellij.codeInsight.CodeInsightSettings) EnterHandlerDelegate(com.intellij.codeInsight.editorActions.enter.EnterHandlerDelegate)

Example 8 with CodeInsightSettings

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

the class EditorSettingsStatisticsCollector method getUsages.

@NotNull
@Override
public Set<UsageDescriptor> getUsages() throws CollectUsagesException {
    Set<UsageDescriptor> set = new HashSet<>();
    EditorSettingsExternalizable es = EditorSettingsExternalizable.getInstance();
    addIfDiffers(set, es.isVirtualSpace(), false, "caretAfterLineEnd");
    addIfDiffers(set, es.isCaretInsideTabs(), false, "caretInsideTabs");
    addIfDiffers(set, es.isAdditionalPageAtBottom(), false, "virtualSpaceAtFileBottom");
    addIfDiffers(set, es.isUseSoftWraps(SoftWrapAppliancePlaces.MAIN_EDITOR), false, "softWraps");
    addIfDiffers(set, es.isUseSoftWraps(SoftWrapAppliancePlaces.CONSOLE), false, "softWraps.console");
    addIfDiffers(set, es.isUseSoftWraps(SoftWrapAppliancePlaces.PREVIEW), false, "softWraps.preview");
    addIfDiffers(set, es.isUseCustomSoftWrapIndent(), false, "softWraps.relativeIndent");
    addIfDiffers(set, es.isAllSoftWrapsShown(), false, "softWraps.showAll");
    addIfDiffers(set, es.getStripTrailingSpaces(), EditorSettingsExternalizable.STRIP_TRAILING_SPACES_CHANGED, "stripTrailingSpaces");
    addIfDiffers(set, es.isEnsureNewLineAtEOF(), false, "ensureNewlineAtEOF");
    addIfDiffers(set, es.isShowQuickDocOnMouseOverElement(), false, "quickDocOnMouseHover");
    addIfDiffers(set, es.isBlinkCaret(), true, "blinkingCaret");
    addIfDiffers(set, es.isBlockCursor(), false, "blockCaret");
    addIfDiffers(set, es.isRightMarginShown(), true, "rightMargin");
    addIfDiffers(set, es.isLineNumbersShown(), true, "lineNumbers");
    addIfDiffers(set, es.areGutterIconsShown(), true, "gutterIcons");
    addIfDiffers(set, es.isFoldingOutlineShown(), true, "foldingOutline");
    addIfDiffers(set, es.isWhitespacesShown() && es.isLeadingWhitespacesShown(), false, "showLeadingWhitespace");
    addIfDiffers(set, es.isWhitespacesShown() && es.isInnerWhitespacesShown(), false, "showInnerWhitespace");
    addIfDiffers(set, es.isWhitespacesShown() && es.isTrailingWhitespacesShown(), false, "showTrailingWhitespace");
    addIfDiffers(set, es.isIndentGuidesShown(), true, "indentGuides");
    addIfDiffers(set, es.isSmoothScrolling(), true, "animatedScroll");
    addIfDiffers(set, es.isDndEnabled(), true, "dragNDrop");
    addIfDiffers(set, es.isWheelFontChangeEnabled(), false, "wheelZoom");
    addIfDiffers(set, es.isMouseClickSelectionHonorsCamelWords(), true, "mouseCamel");
    addIfDiffers(set, es.isVariableInplaceRenameEnabled(), true, "inplaceRename");
    addIfDiffers(set, es.isPreselectRename(), true, "preselectOnRename");
    addIfDiffers(set, es.isShowInlineLocalDialog(), true, "inlineDialog");
    addIfDiffers(set, es.isRefrainFromScrolling(), false, "minimizeScrolling");
    addIfDiffers(set, es.getOptions().SHOW_NOTIFICATION_AFTER_REFORMAT_CODE_ACTION, true, "afterReformatNotification");
    addIfDiffers(set, es.getOptions().SHOW_NOTIFICATION_AFTER_OPTIMIZE_IMPORTS_ACTION, true, "afterOptimizeNotification");
    addIfDiffers(set, es.isSmartHome(), true, "smartHome");
    addIfDiffers(set, es.isCamelWords(), false, "camelWords");
    addIfDiffers(set, es.isShowParameterNameHints(), true, "editor.inlay.parameter.hints");
    RichCopySettings rcs = RichCopySettings.getInstance();
    addIfDiffers(set, rcs.isEnabled(), true, "richCopy");
    CodeInsightSettings cis = CodeInsightSettings.getInstance();
    addIfDiffers(set, cis.AUTO_POPUP_PARAMETER_INFO, true, "parameterAutoPopup");
    addIfDiffers(set, cis.AUTO_POPUP_JAVADOC_INFO, false, "javadocAutoPopup");
    addIfDiffers(set, cis.AUTO_POPUP_COMPLETION_LOOKUP, true, "completionAutoPopup");
    addIfDiffers(set, cis.COMPLETION_CASE_SENSITIVE, CodeInsightSettings.FIRST_LETTER, "completionCaseSensitivity");
    addIfDiffers(set, cis.SELECT_AUTOPOPUP_SUGGESTIONS_BY_CHARS, false, "autoPopupCharComplete");
    addIfDiffers(set, cis.AUTOCOMPLETE_ON_CODE_COMPLETION, true, "autoCompleteBasic");
    addIfDiffers(set, cis.AUTOCOMPLETE_ON_SMART_TYPE_COMPLETION, true, "autoCompleteSmart");
    addIfDiffers(set, cis.SHOW_FULL_SIGNATURES_IN_PARAMETER_INFO, false, "parameterInfoFullSignature");
    addIfDiffers(set, cis.getBackspaceMode(), SmartBackspaceMode.AUTOINDENT, "smartBackspace");
    addIfDiffers(set, cis.SMART_INDENT_ON_ENTER, true, "indentOnEnter");
    addIfDiffers(set, cis.INSERT_BRACE_ON_ENTER, true, "braceOnEnter");
    addIfDiffers(set, cis.JAVADOC_STUB_ON_ENTER, true, "javadocOnEnter");
    addIfDiffers(set, cis.SMART_END_ACTION, true, "smartEnd");
    addIfDiffers(set, cis.JAVADOC_GENERATE_CLOSING_TAG, true, "autoCloseJavadocTags");
    addIfDiffers(set, cis.SURROUND_SELECTION_ON_QUOTE_TYPED, false, "surroundByQuoteOrBrace");
    addIfDiffers(set, cis.AUTOINSERT_PAIR_BRACKET, true, "pairBracketAutoInsert");
    addIfDiffers(set, cis.AUTOINSERT_PAIR_QUOTE, true, "pairQuoteAutoInsert");
    addIfDiffers(set, cis.REFORMAT_BLOCK_ON_RBRACE, true, "reformatOnRBrace");
    addIfDiffers(set, cis.REFORMAT_ON_PASTE, CodeInsightSettings.INDENT_EACH_LINE, "reformatOnPaste");
    addIfDiffers(set, cis.ADD_IMPORTS_ON_PASTE, CodeInsightSettings.ASK, "importsOnPaste");
    addIfDiffers(set, cis.HIGHLIGHT_BRACES, true, "bracesHighlight");
    addIfDiffers(set, cis.HIGHLIGHT_SCOPE, false, "scopeHighlight");
    addIfDiffers(set, cis.HIGHLIGHT_IDENTIFIER_UNDER_CARET, true, "identifierUnderCaretHighlight");
    addIfDiffers(set, cis.ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY, false, "autoAddImports");
    return set;
}
Also used : CodeInsightSettings(com.intellij.codeInsight.CodeInsightSettings) RichCopySettings(com.intellij.openapi.editor.richcopy.settings.RichCopySettings) UsageDescriptor(com.intellij.internal.statistic.beans.UsageDescriptor) HashSet(java.util.HashSet) EditorSettingsExternalizable(com.intellij.openapi.editor.ex.EditorSettingsExternalizable) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with CodeInsightSettings

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

the class JavaAutoImportOptions method apply.

public void apply() {
    CodeInsightSettings codeInsightSettings = CodeInsightSettings.getInstance();
    DaemonCodeAnalyzerSettings daemonSettings = DaemonCodeAnalyzerSettings.getInstance();
    codeInsightSettings.ADD_IMPORTS_ON_PASTE = getSmartPasteValue();
    daemonSettings.setImportHintEnabled(myCbShowImportPopup.isSelected());
    CodeInsightWorkspaceSettings.getInstance(myProject).optimizeImportsOnTheFly = myCbOptimizeImports.isSelected();
    codeInsightSettings.ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY = myCbAddUnambiguousImports.isSelected();
    codeInsightSettings.ADD_MEMBER_IMPORTS_ON_THE_FLY = myCbAddMethodImports.isSelected();
    myExcludePackagesTable.apply();
    for (Project project : ProjectManager.getInstance().getOpenProjects()) {
        DaemonCodeAnalyzer.getInstance(project).restart();
    }
}
Also used : DaemonCodeAnalyzerSettings(com.intellij.codeInsight.daemon.DaemonCodeAnalyzerSettings) CodeInsightSettings(com.intellij.codeInsight.CodeInsightSettings) Project(com.intellij.openapi.project.Project)

Example 10 with CodeInsightSettings

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

the class MethodParameterInfoHandler method updateMethodPresentation.

public static String updateMethodPresentation(@NotNull PsiMethod method, @Nullable PsiSubstitutor substitutor, @NotNull ParameterInfoUIContext context) {
    CodeInsightSettings settings = CodeInsightSettings.getInstance();
    if (!method.isValid() || substitutor != null && !substitutor.isValid()) {
        context.setUIComponentEnabled(false);
        return null;
    }
    StringBuilder buffer = new StringBuilder();
    if (settings.SHOW_FULL_SIGNATURES_IN_PARAMETER_INFO) {
        if (!method.isConstructor()) {
            PsiType returnType = method.getReturnType();
            if (substitutor != null) {
                returnType = substitutor.substitute(returnType);
            }
            assert returnType != null : method;
            appendModifierList(buffer, method);
            buffer.append(returnType.getPresentableText(true));
            buffer.append(" ");
        }
        buffer.append(method.getName());
        buffer.append("(");
    }
    final int currentParameter = context.getCurrentParameterIndex();
    PsiParameter[] parms = method.getParameterList().getParameters();
    int numParams = parms.length;
    int highlightStartOffset = -1;
    int highlightEndOffset = -1;
    if (numParams > 0) {
        for (int j = 0; j < numParams; j++) {
            PsiParameter param = parms[j];
            int startOffset = buffer.length();
            if (param.isValid()) {
                PsiType paramType = param.getType();
                assert paramType.isValid();
                if (substitutor != null) {
                    assert substitutor.isValid();
                    paramType = substitutor.substitute(paramType);
                }
                appendModifierList(buffer, param);
                buffer.append(paramType.getPresentableText(true));
                String name = param.getName();
                if (name != null) {
                    buffer.append(" ");
                    buffer.append(name);
                }
            }
            int endOffset = buffer.length();
            if (j < numParams - 1) {
                buffer.append(", ");
            }
            if (context.isUIComponentEnabled() && (j == currentParameter || j == numParams - 1 && param.isVarArgs() && currentParameter >= numParams)) {
                highlightStartOffset = startOffset;
                highlightEndOffset = endOffset;
            }
        }
    } else {
        buffer.append(CodeInsightBundle.message("parameter.info.no.parameters"));
    }
    if (settings.SHOW_FULL_SIGNATURES_IN_PARAMETER_INFO) {
        buffer.append(")");
    }
    return context.setupUIComponentPresentation(buffer.toString(), highlightStartOffset, highlightEndOffset, !context.isUIComponentEnabled(), method.isDeprecated(), false, context.getDefaultParameterColor());
}
Also used : CodeInsightSettings(com.intellij.codeInsight.CodeInsightSettings)

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