com.intellij.codeInsight.CodeInsightSettings Java Examples

The following examples show how to use com.intellij.codeInsight.CodeInsightSettings. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LiveTemplateCharFilter.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public Result acceptChar(char c, int prefixLength, Lookup lookup) {
  LookupElement item = lookup.getCurrentItem();
  if (item instanceof LiveTemplateLookupElement && lookup.isCompletion()) {
    if (Character.isJavaIdentifierPart(c)) return Result.ADD_TO_PREFIX;

    if (c == ((LiveTemplateLookupElement)item).getTemplateShortcut()) {
      return Result.SELECT_ITEM_AND_FINISH_LOOKUP;
    }
    return Result.HIDE_LOOKUP;
  }
  if (item instanceof TemplateExpressionLookupElement) {
    if (Character.isJavaIdentifierPart(c)) return Result.ADD_TO_PREFIX;
    if (CodeInsightSettings.getInstance().SELECT_AUTOPOPUP_SUGGESTIONS_BY_CHARS) {
      return null;
    }
    return Result.HIDE_LOOKUP;
  }

  return null;
}
 
Example #2
Source File: CamelHumpMatcher.java    From consulo with Apache License 2.0 6 votes vote down vote up
private MinusculeMatcher createMatcher(final boolean caseSensitive) {
  String prefix = applyMiddleMatching(myPrefix);

  NameUtil.MatcherBuilder builder = NameUtil.buildMatcher(prefix);
  if (caseSensitive) {
    int setting = CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE;
    if (setting == CodeInsightSettings.FIRST_LETTER) {
      builder = builder.withCaseSensitivity(NameUtil.MatchingCaseSensitivity.FIRST_LETTER);
    }
    else if (setting == CodeInsightSettings.ALL) {
      builder = builder.withCaseSensitivity(NameUtil.MatchingCaseSensitivity.ALL);
    }
  }
  if (myTypoTolerant) {
    builder = builder.typoTolerant();
  }
  return builder.build();
}
 
Example #3
Source File: CompletionProgressIndicator.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void addDefaultAdvertisements(CompletionParameters parameters) {
  if (DumbService.isDumb(getProject())) {
    addAdvertisement("Results might be incomplete while indexing is in progress", AllIcons.General.Warning);
    return;
  }

  String enterShortcut = CompletionUtil.getActionShortcut(IdeActions.ACTION_CHOOSE_LOOKUP_ITEM);
  String tabShortcut = CompletionUtil.getActionShortcut(IdeActions.ACTION_CHOOSE_LOOKUP_ITEM_REPLACE);
  addAdvertisement("Press " + enterShortcut + " to insert, " + tabShortcut + " to replace", null);

  advertiseTabReplacement(parameters);
  if (isAutopopupCompletion()) {
    if (shouldPreselectFirstSuggestion(parameters) && !CodeInsightSettings.getInstance().isSelectAutopopupSuggestionsByChars()) {
      advertiseCtrlDot();
    }
    advertiseCtrlArrows();
  }
}
 
Example #4
Source File: TabOutScopesTrackerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void registerEmptyScope(@Nonnull Editor editor, int offset, int tabOutOffset) {
  ApplicationManager.getApplication().assertIsDispatchThread();
  if (editor.isDisposed()) throw new IllegalArgumentException("Editor is already disposed");
  if (tabOutOffset <= offset) throw new IllegalArgumentException("tabOutOffset should be larger than offset");

  if (!CodeInsightSettings.getInstance().TAB_EXITS_BRACKETS_AND_QUOTES) return;

  if (editor instanceof EditorWindow) {
    DocumentWindow documentWindow = ((EditorWindow)editor).getDocument();
    offset = documentWindow.injectedToHost(offset);
    editor = ((EditorWindow)editor).getDelegate();
  }
  if (!(editor instanceof DesktopEditorImpl)) return;

  Tracker tracker = Tracker.forEditor((DesktopEditorImpl)editor, true);
  tracker.registerScope(offset, tabOutOffset - offset);
}
 
Example #5
Source File: TabOutScopesTrackerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static int checkOrRemoveScopeEndingAt(@Nonnull Editor editor, int offset, boolean removeScope) {
  ApplicationManager.getApplication().assertIsDispatchThread();

  if (!CodeInsightSettings.getInstance().TAB_EXITS_BRACKETS_AND_QUOTES) return 0;

  if (editor instanceof EditorWindow) {
    DocumentWindow documentWindow = ((EditorWindow)editor).getDocument();
    offset = documentWindow.injectedToHost(offset);
    editor = ((EditorWindow)editor).getDelegate();
  }
  if (!(editor instanceof DesktopEditorImpl)) return 0;

  Tracker tracker = Tracker.forEditor((DesktopEditorImpl)editor, false);
  if (tracker == null) return 0;

  return tracker.getCaretShiftForScopeEndingAt(offset, removeScope);
}
 
Example #6
Source File: LookupManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void showJavadoc(LookupImpl lookup) {
  if (myActiveLookup != lookup) return;

  DocumentationManager docManager = DocumentationManager.getInstance(myProject);
  if (docManager.getDocInfoHint() != null) return; // will auto-update

  LookupElement currentItem = lookup.getCurrentItem();
  CompletionProcess completion = CompletionService.getCompletionService().getCurrentCompletion();
  if (currentItem != null && currentItem.isValid() && isAutoPopupJavadocSupportedBy(currentItem) && completion != null) {
    try {
      boolean hideLookupWithDoc = completion.isAutopopupCompletion() || CodeInsightSettings.getInstance().JAVADOC_INFO_DELAY == 0;
      docManager.showJavaDocInfo(lookup.getEditor(), lookup.getPsiFile(), false, () -> {
        if (hideLookupWithDoc && completion == CompletionService.getCompletionService().getCurrentCompletion()) {
          hideActiveLookup();
        }
      });
    }
    catch (IndexNotReadyException ignored) {
    }
  }
}
 
Example #7
Source File: HaxeTypedHandler.java    From intellij-haxe with Apache License 2.0 6 votes vote down vote up
@Override
public Result beforeCharTyped(char c,
                              Project project,
                              Editor editor,
                              PsiFile file,
                              FileType fileType) {
  if (c == '<') {
    myAfterTypeOrComponentName = checkAfterTypeOrComponentName(file, editor.getCaretModel().getOffset());
  }
  if (c == '{') {
    myAfterDollar = checkAfterDollarInString(file, editor.getCaretModel().getOffset());
  }
  if (c == '>') {
    if (CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET &&
        JavaTypedHandler.handleJavaGT(editor, HaxeTokenTypes.OLESS, HaxeTokenTypes.OGREATER, INVALID_INSIDE_REFERENCE)) {
      return Result.STOP;
    }
  }
  return super.beforeCharTyped(c, project, editor, file, fileType);
}
 
Example #8
Source File: EditorSmartKeysConfigurable.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredUIAccess
@Override
protected void apply(@Nonnull Panel panel) throws ConfigurationException {
  EditorSettingsExternalizable editorSettings = EditorSettingsExternalizable.getInstance();
  CodeInsightSettings codeInsightSettings = CodeInsightSettings.getInstance();

  editorSettings.setSmartHome(panel.myCbSmartHome.getValue());
  codeInsightSettings.SMART_END_ACTION = panel.myCbSmartEnd.getValue();
  codeInsightSettings.SMART_INDENT_ON_ENTER = panel.myCbSmartIndentOnEnter.getValue();
  codeInsightSettings.INSERT_BRACE_ON_ENTER = panel.myCbInsertPairCurlyBraceOnEnter.getValue();
  codeInsightSettings.INDENT_TO_CARET_ON_PASTE = panel.mySmartIndentPastedLinesCheckBox.getValue();
  codeInsightSettings.JAVADOC_STUB_ON_ENTER = panel.myCbInsertJavadocStubOnEnter.getValue();
  codeInsightSettings.AUTOINSERT_PAIR_BRACKET = panel.myCbInsertPairBracket.getValue();
  codeInsightSettings.AUTOINSERT_PAIR_QUOTE = panel.myCbInsertPairQuote.getValue();
  codeInsightSettings.REFORMAT_BLOCK_ON_RBRACE = panel.myCbReformatBlockOnTypingRBrace.getValue();
  codeInsightSettings.SURROUND_SELECTION_ON_QUOTE_TYPED = panel.myCbSurroundSelectionOnTyping.getValue();
  editorSettings.setCamelWords(panel.myCbCamelWords.getValue());
  codeInsightSettings.REFORMAT_ON_PASTE = panel.myReformatOnPasteCombo.getValue();
  codeInsightSettings.setBackspaceMode(panel.myCbIndentingBackspace.getValue());
}
 
Example #9
Source File: EditorSmartKeysConfigurable.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredUIAccess
@Override
protected void reset(@Nonnull Panel panel) {
  EditorSettingsExternalizable editorSettings = EditorSettingsExternalizable.getInstance();
  CodeInsightSettings codeInsightSettings = CodeInsightSettings.getInstance();

  panel.myReformatOnPasteCombo.setValue(codeInsightSettings.REFORMAT_ON_PASTE);

  panel.myCbSmartHome.setValue(editorSettings.isSmartHome());
  panel.myCbSmartEnd.setValue(codeInsightSettings.SMART_END_ACTION);

  panel.myCbSmartIndentOnEnter.setValue(codeInsightSettings.SMART_INDENT_ON_ENTER);
  panel.myCbInsertPairCurlyBraceOnEnter.setValue(codeInsightSettings.INSERT_BRACE_ON_ENTER);
  panel.myCbInsertJavadocStubOnEnter.setValue(codeInsightSettings.JAVADOC_STUB_ON_ENTER);

  panel.myCbInsertPairBracket.setValue(codeInsightSettings.AUTOINSERT_PAIR_BRACKET);
  panel.mySmartIndentPastedLinesCheckBox.setValue(codeInsightSettings.INDENT_TO_CARET_ON_PASTE);
  panel.myCbInsertPairQuote.setValue(codeInsightSettings.AUTOINSERT_PAIR_QUOTE);
  panel.myCbReformatBlockOnTypingRBrace.setValue(codeInsightSettings.REFORMAT_BLOCK_ON_RBRACE);
  panel.myCbCamelWords.setValue(editorSettings.isCamelWords());

  panel.myCbSurroundSelectionOnTyping.setValue(codeInsightSettings.SURROUND_SELECTION_ON_QUOTE_TYPED);

  panel.myCbIndentingBackspace.setValue(codeInsightSettings.getBackspaceMode());
}
 
Example #10
Source File: CodeCompletionPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void apply() {

    CodeInsightSettings codeInsightSettings = CodeInsightSettings.getInstance();

    codeInsightSettings.COMPLETION_CASE_SENSITIVE = getCaseSensitiveValue();

    codeInsightSettings.SELECT_AUTOPOPUP_SUGGESTIONS_BY_CHARS = myCbSelectByChars.isSelected();
    codeInsightSettings.AUTOCOMPLETE_ON_CODE_COMPLETION = myCbOnCodeCompletion.isSelected();
    codeInsightSettings.AUTOCOMPLETE_ON_SMART_TYPE_COMPLETION = myCbOnSmartTypeCompletion.isSelected();
    codeInsightSettings.SHOW_FULL_SIGNATURES_IN_PARAMETER_INFO = myCbShowFullParameterSignatures.isSelected();

    codeInsightSettings.AUTO_POPUP_PARAMETER_INFO = myCbParameterInfoPopup.isSelected();
    codeInsightSettings.AUTO_POPUP_COMPLETION_LOOKUP = myCbAutocompletion.isSelected();
    codeInsightSettings.AUTO_POPUP_JAVADOC_INFO = myCbAutopopupJavaDoc.isSelected();

    codeInsightSettings.PARAMETER_INFO_DELAY = getIntegerValue(myParameterInfoDelayField.getText(), 0);
    codeInsightSettings.JAVADOC_INFO_DELAY = getIntegerValue(myAutopopupJavaDocField.getText(), 0);

    UISettings.getInstance().SORT_LOOKUP_ELEMENTS_LEXICOGRAPHICALLY = myCbSorting.isSelected();

    final Project project = DataManager.getInstance().getDataContext(myPanel).getData(CommonDataKeys.PROJECT);
    if (project != null){
      DaemonCodeAnalyzer.getInstance(project).settingsChanged();
    }
  }
 
Example #11
Source File: BashUnmatchedBraceEnterProcessor.java    From BashSupport with Apache License 2.0 6 votes vote down vote up
@Override
public Result preprocessEnter(@NotNull PsiFile file, @NotNull Editor editor, @NotNull Ref<Integer> caretOffset, @NotNull Ref<Integer> caretAdvance, @NotNull DataContext dataContext, @Nullable EditorActionHandler originalHandler) {
    Project project = editor.getProject();

    if (CodeInsightSettings.getInstance().INSERT_BRACE_ON_ENTER && file instanceof BashFile && project != null) {
        Document document = editor.getDocument();
        CharSequence chars = document.getCharsSequence();

        int offset = caretOffset.get();
        int length = chars.length();

        if (offset < length && offset >= 1 && chars.charAt(offset - 1) == '{') {
            int start = offset + 1;
            int end = offset + 1 + "function".length();

            if (start < length && end < length && "function".contentEquals(chars.subSequence(start, end))) {
                document.insertString(start, "\n");
                PsiDocumentManager.getInstance(project).commitDocument(document);
            }
        }
    }

    return Result.Continue;
}
 
Example #12
Source File: FilePathCompletionTest.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Test
public void testInsertPairQuoteOptionRespected() {
  boolean old = CodeInsightSettings.getInstance().AUTOINSERT_PAIR_QUOTE;
  try {
    CodeInsightSettings.getInstance().AUTOINSERT_PAIR_QUOTE = false;
    BuildFile file = createBuildFile(new WorkspacePath("java/BUILD"), "'//");
    Editor editor = editorTest.openFileInEditor(file);
    editorTest.setCaretPosition(editor, 0, "'//".length());

    assertThat(editorTest.completeIfUnique()).isTrue();
    assertFileContents(file, "'//java");

    CodeInsightSettings.getInstance().AUTOINSERT_PAIR_QUOTE = true;
    file = createBuildFile(new WorkspacePath("foo/BUILD"), "'//j");
    editor = editorTest.openFileInEditor(file);
    editorTest.setCaretPosition(editor, 0, "'//j".length());

    assertThat(editorTest.completeIfUnique()).isTrue();
    assertFileContents(file, "'//java'");
  } finally {
    CodeInsightSettings.getInstance().AUTOINSERT_PAIR_QUOTE = old;
  }
}
 
Example #13
Source File: EditorSmartKeysConfigurable.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
public Panel() {
  myWholeLayout = VerticalLayout.create();
  myWholeLayout.add(myCbSmartHome = CheckBox.create(ApplicationBundle.message("checkbox.smart.home")));
  myWholeLayout.add(myCbSmartEnd = CheckBox.create(ApplicationBundle.message("checkbox.smart.end.on.blank.line")));
  myWholeLayout.add(myCbInsertPairBracket = CheckBox.create(ApplicationBundle.message("checkbox.insert.pair.bracket")));
  myWholeLayout.add(myCbInsertPairQuote = CheckBox.create(ApplicationBundle.message("checkbox.insert.pair.quote")));
  myWholeLayout.add(myCbReformatBlockOnTypingRBrace = CheckBox.create(ApplicationBundle.message("checkbox.reformat.on.typing.rbrace")));
  myWholeLayout.add(myCbCamelWords = CheckBox.create(ApplicationBundle.message("checkbox.use.camelhumps.words")));
  myWholeLayout.add(myCbSurroundSelectionOnTyping = CheckBox.create(ApplicationBundle.message("checkbox.surround.selection.on.typing.quote.or.brace")));
  myWholeLayout.add(mySmartIndentPastedLinesCheckBox = CheckBox.create(ApplicationBundle.message("checkbox.indent.on.paste")));

  ComboBox.Builder<Integer> reformatOnPasteBuilder = ComboBox.builder();
  reformatOnPasteBuilder.add(CodeInsightSettings.NO_REFORMAT, ApplicationBundle.message("combobox.paste.reformat.none"));
  reformatOnPasteBuilder.add(CodeInsightSettings.INDENT_BLOCK, ApplicationBundle.message("combobox.paste.reformat.indent.block"));
  reformatOnPasteBuilder.add(CodeInsightSettings.INDENT_EACH_LINE, ApplicationBundle.message("combobox.paste.reformat.indent.each.line"));
  reformatOnPasteBuilder.add(CodeInsightSettings.REFORMAT_BLOCK, ApplicationBundle.message("combobox.paste.reformat.reformat.block"));

  myWholeLayout.add(LabeledComponents.left(ApplicationBundle.message("combobox.paste.reformat"), myReformatOnPasteCombo = reformatOnPasteBuilder.build()));

  VerticalLayout enterLayout = VerticalLayout.create();
  myWholeLayout.add(LabeledLayout.create("Enter", enterLayout));

  enterLayout.add(myCbSmartIndentOnEnter = CheckBox.create(ApplicationBundle.message("checkbox.smart.indent")));
  enterLayout.add(myCbInsertPairCurlyBraceOnEnter = CheckBox.create(ApplicationBundle.message("checkbox.insert.pair.curly.brace")));
  enterLayout.add(myCbInsertJavadocStubOnEnter = CheckBox.create(ApplicationBundle.message("checkbox.javadoc.stub.after.slash.star.star")));
  myCbInsertJavadocStubOnEnter.setVisible(hasAnyDocAwareCommenters());

  VerticalLayout backspaceLayout = VerticalLayout.create();
  myWholeLayout.add(LabeledLayout.create("Backspace", backspaceLayout));

  ComboBox.Builder<SmartBackspaceMode> smartIndentBuilder = ComboBox.builder();
  smartIndentBuilder.add(SmartBackspaceMode.OFF, ApplicationBundle.message("combobox.smart.backspace.off"));
  smartIndentBuilder.add(SmartBackspaceMode.INDENT, ApplicationBundle.message("combobox.smart.backspace.simple"));
  smartIndentBuilder.add(SmartBackspaceMode.AUTOINDENT, ApplicationBundle.message("combobox.smart.backspace.smart"));
  backspaceLayout.add(LabeledComponents.left(ApplicationBundle.message("combobox.smart.backspace"), myCbIndentingBackspace = smartIndentBuilder.build()));
}
 
Example #14
Source File: CodeCompletionPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
@MagicConstant(intValues = {CodeInsightSettings.ALL, CodeInsightSettings.NONE, CodeInsightSettings.FIRST_LETTER})
private int getCaseSensitiveValue() {
  Object value = myCaseSensitiveCombo.getSelectedItem();
  if (CASE_SENSITIVE_ALL.equals(value)){
    return CodeInsightSettings.ALL;
  }
  else if (CASE_SENSITIVE_NONE.equals(value)){
    return CodeInsightSettings.NONE;
  }
  else {
    return CodeInsightSettings.FIRST_LETTER;
  }
}
 
Example #15
Source File: EnterHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private PsiComment createJavaDocStub(final CodeInsightSettings settings, final PsiComment comment, final Project project) {
  if (settings.JAVADOC_STUB_ON_ENTER) {
    final DocumentationProvider langDocumentationProvider = LanguageDocumentation.INSTANCE.forLanguage(comment.getParent().getLanguage());

    @Nullable final CodeDocumentationProvider docProvider;
    if (langDocumentationProvider instanceof CompositeDocumentationProvider) {
      docProvider = ((CompositeDocumentationProvider)langDocumentationProvider).getFirstCodeDocumentationProvider();
    }
    else {
      docProvider = langDocumentationProvider instanceof CodeDocumentationProvider ? (CodeDocumentationProvider)langDocumentationProvider : null;
    }

    if (docProvider != null) {
      if (docProvider.findExistingDocComment(comment) != comment) return comment;
      String docStub;

      DumbService.getInstance(project).setAlternativeResolveEnabled(true);
      try {
        docStub = docProvider.generateDocumentationContentStub(comment);
      }
      finally {
        DumbService.getInstance(project).setAlternativeResolveEnabled(false);
      }

      if (docStub != null && docStub.length() != 0) {
        myOffset = CharArrayUtil.shiftForwardUntil(myDocument.getCharsSequence(), myOffset, LINE_SEPARATOR);
        myOffset = CharArrayUtil.shiftForward(myDocument.getCharsSequence(), myOffset, LINE_SEPARATOR);
        myDocument.insertString(myOffset, docStub);
      }
    }

    PsiDocumentManager.getInstance(project).commitAllDocuments();
    return PsiTreeUtil.getNonStrictParentOfType(myFile.findElementAt(myOffset), PsiComment.class);
  }
  return comment;
}
 
Example #16
Source File: EnterHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private PsiComment createComment(final CharSequence buffer, final CodeInsightSettings settings) throws IncorrectOperationException {
  myDocument.insertString(myOffset, buffer);

  PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
  CodeStyleManager.getInstance(getProject()).adjustLineIndent(myFile, myOffset + buffer.length() - 2);

  PsiComment comment = PsiTreeUtil.getNonStrictParentOfType(myFile.findElementAt(myOffset), PsiComment.class);

  comment = createJavaDocStub(settings, comment, getProject());
  if (comment == null) {
    return null;
  }

  CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(getProject());
  final Ref<PsiComment> commentRef = Ref.create(comment);
  codeStyleManager.runWithDocCommentFormattingDisabled(myFile, () -> formatComment(commentRef, codeStyleManager));
  comment = commentRef.get();

  PsiElement next = comment.getNextSibling();
  if (next == null && comment.getParent().getClass() == comment.getClass()) {
    next = comment.getParent().getNextSibling(); // expanding chameleon comment produces comment under comment
  }
  if (next != null) {
    next = myFile.findElementAt(next.getTextRange().getStartOffset()); // maybe switch to another tree
  }
  if (next != null && (!FormatterUtil.containsWhiteSpacesOnly(next.getNode()) || !next.getText().contains(LINE_SEPARATOR))) {
    int lineBreakOffset = comment.getTextRange().getEndOffset();
    myDocument.insertString(lineBreakOffset, LINE_SEPARATOR);
    PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
    codeStyleManager.adjustLineIndent(myFile, lineBreakOffset + 1);
    comment = PsiTreeUtil.getNonStrictParentOfType(myFile.findElementAt(myOffset), PsiComment.class);
  }
  return comment;
}
 
Example #17
Source File: AbstractIndentingBackspaceHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static SmartBackspaceMode getBackspaceMode(Language language) {
  SmartBackspaceMode mode = CodeInsightSettings.getInstance().getBackspaceMode();
  BackspaceModeOverride override = LanguageBackspaceModeOverride.INSTANCE.forLanguage(language);
  if (override != null) {
    mode = override.getBackspaceMode(mode);
  }
  return mode;
}
 
Example #18
Source File: CodeCompletionPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void reset() {
  CodeInsightSettings codeInsightSettings = CodeInsightSettings.getInstance();

  final String value;
  switch(codeInsightSettings.COMPLETION_CASE_SENSITIVE){
    case CodeInsightSettings.ALL:
      value = CASE_SENSITIVE_ALL;
      break;

    case CodeInsightSettings.NONE:
      value = CASE_SENSITIVE_NONE;
      break;

    default:
      value = CASE_SENSITIVE_FIRST_LETTER;
      break;
  }
  myCaseSensitiveCombo.setSelectedItem(value);

  myCbSelectByChars.setSelected(codeInsightSettings.SELECT_AUTOPOPUP_SUGGESTIONS_BY_CHARS);

  myCbOnCodeCompletion.setSelected(codeInsightSettings.AUTOCOMPLETE_ON_CODE_COMPLETION);
  myCbOnSmartTypeCompletion.setSelected(codeInsightSettings.AUTOCOMPLETE_ON_SMART_TYPE_COMPLETION);

  myCbAutocompletion.setSelected(codeInsightSettings.AUTO_POPUP_COMPLETION_LOOKUP);

  myCbAutopopupJavaDoc.setSelected(codeInsightSettings.AUTO_POPUP_JAVADOC_INFO);
  myAutopopupJavaDocField.setEnabled(codeInsightSettings.AUTO_POPUP_JAVADOC_INFO);
  myAutopopupJavaDocField.setText(String.valueOf(codeInsightSettings.JAVADOC_INFO_DELAY));

  myCbParameterInfoPopup.setSelected(codeInsightSettings.AUTO_POPUP_PARAMETER_INFO);
  myParameterInfoDelayField.setEnabled(codeInsightSettings.AUTO_POPUP_PARAMETER_INFO);
  myParameterInfoDelayField.setText(String.valueOf(codeInsightSettings.PARAMETER_INFO_DELAY));
  myCbShowFullParameterSignatures.setSelected(codeInsightSettings.SHOW_FULL_SIGNATURES_IN_PARAMETER_INFO);

  myCbAutocompletion.setSelected(codeInsightSettings.AUTO_POPUP_COMPLETION_LOOKUP);
  myCbSorting.setSelected(UISettings.getInstance().SORT_LOOKUP_ELEMENTS_LEXICOGRAPHICALLY);

  myCbAutocompletion.setText("Autopopup code completion" + (PowerSaveMode.isEnabled() ? " (not available in Power Save mode)" : ""));
}
 
Example #19
Source File: IdentifierHighlighterPassFactory.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public TextEditorHighlightingPass createHighlightingPass(@Nonnull final PsiFile file, @Nonnull final Editor editor) {
  if (editor.isOneLineMode()) return null;

  if (CodeInsightSettings.getInstance().HIGHLIGHT_IDENTIFIER_UNDER_CARET && (!ApplicationManager.getApplication().isHeadlessEnvironment() || ourTestingIdentifierHighlighting)) {
    return new IdentifierHighlighterPass(file.getProject(), file, editor);
  }
  return null;
}
 
Example #20
Source File: BraceHighlightingHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
private BraceHighlightingHandler(@Nonnull Project project, @Nonnull Editor editor, @Nonnull Alarm alarm, PsiFile psiFile) {
  myProject = project;

  myEditor = editor;
  myAlarm = alarm;
  myDocument = (DocumentEx)myEditor.getDocument();

  myPsiFile = psiFile;
  myCodeInsightSettings = CodeInsightSettings.getInstance();
}
 
Example #21
Source File: CamelHumpMatcher.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean prefixMatches(@Nonnull final String name) {
  if (name.startsWith("_") && CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE == CodeInsightSettings.FIRST_LETTER && firstLetterCaseDiffers(name)) {
    return false;
  }

  return myMatcher.matches(name);
}
 
Example #22
Source File: CamelHumpMatcher.java    From consulo with Apache License 2.0 5 votes vote down vote up
private boolean prefixMatchersInternal(final LookupElement element, final boolean itemCaseInsensitive) {
  for (final String name : element.getAllLookupStrings()) {
    if (itemCaseInsensitive && StringUtil.startsWithIgnoreCase(name, myPrefix) || prefixMatches(name)) {
      return true;
    }
    if (itemCaseInsensitive && CodeInsightSettings.ALL != CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE) {
      if (myCaseInsensitiveMatcher.matches(name)) {
        return true;
      }
    }
  }
  return false;
}
 
Example #23
Source File: AbstractCompletionTest.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
    super.setUp();

    oldBasic = CodeInsightSettings.getInstance().AUTOCOMPLETE_ON_CODE_COMPLETION;
    oldSmart = CodeInsightSettings.getInstance().AUTOCOMPLETE_ON_SMART_TYPE_COMPLETION;

    CodeInsightSettings.getInstance().AUTOCOMPLETE_ON_CODE_COMPLETION = autoInsertionEnabled;
    CodeInsightSettings.getInstance().AUTOCOMPLETE_ON_SMART_TYPE_COMPLETION = autoInsertionEnabled;

}
 
Example #24
Source File: AbstractCompletionTest.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
@Override
protected void tearDown() throws Exception {
    CodeInsightSettings.getInstance().AUTOCOMPLETE_ON_CODE_COMPLETION = oldBasic;
    CodeInsightSettings.getInstance().AUTOCOMPLETE_ON_SMART_TYPE_COMPLETION = oldSmart;

    super.tearDown();
}
 
Example #25
Source File: BashUnmatchedBraceEnterProcessorTest.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
@Test
public void testEmptyFile() throws Exception {
    boolean previous = CodeInsightSettings.getInstance().INSERT_BRACE_ON_ENTER;
    CodeInsightSettings.getInstance().INSERT_BRACE_ON_ENTER = true;

    try {
        myFixture.configureByText(BashFileType.BASH_FILE_TYPE, "abc");
        myFixture.type("\n");
    } finally {
        CodeInsightSettings.getInstance().INSERT_BRACE_ON_ENTER = previous;
    }
}
 
Example #26
Source File: HaskellTypedHandler.java    From intellij-haskforce with Apache License 2.0 5 votes vote down vote up
@Override
public Result charTyped(char c, Project project, @NotNull Editor editor, @NotNull PsiFile file) {
    if (!(file instanceof HaskellFile)) return super.charTyped(c, project, editor, file);

    if ((c != '{' && c != '-' && c != '#') ||
            !CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET) {
        return Result.CONTINUE;
    }
    insertMatchedEndComment(project, editor, file, c);
    return Result.CONTINUE;
}
 
Example #27
Source File: PhpAutoPopupSpaceTypedHandler.java    From idea-php-advanced-autocomplete with MIT License 5 votes vote down vote up
/**
     * PhpTypedHandler.scheduleAutoPopup but use SMART since BASIC is blocked
     */
    public void scheduleAutoPopup(final Project project, final Editor editor, @Nullable final Condition<PsiFile> condition) {
        if (ApplicationManager.getApplication().isUnitTestMode()/* && !CompletionAutoPopupHandler.ourTestingAutopopup*/) {
            return;
        }

        if (!CodeInsightSettings.getInstance().AUTO_POPUP_COMPLETION_LOOKUP) {
            return;
        }
        if (PowerSaveMode.isEnabled()) {
            return;
        }

        if (!CompletionServiceImpl.isPhase(CompletionPhase.CommittingDocuments.class, CompletionPhase.NoCompletion.getClass())) {
            return;
        }
//
//        final CompletionProgressIndicator currentCompletion = CompletionServiceImpl.getCompletionService().getCurrentCompletion();
//        if (currentCompletion != null) {
//            currentCompletion.closeAndFinish(true);
//        }
//
//        final CompletionPhase.CommittingDocuments phase = new CompletionPhase.CommittingDocuments(null, editor);
//        CompletionServiceImpl.setCompletionPhase(phase);
//
//        CompletionAutoPopupHandler.runLaterWithCommitted(project, editor.getDocument(), new Runnable() {
//            @Override
//            public void run() {
//                CompletionAutoPopupHandler.invokeCompletion(CompletionType.BASIC, true, project, editor, 0, false);
//            }
//        });
    }
 
Example #28
Source File: CompletionProgressIndicator.java    From consulo with Apache License 2.0 5 votes vote down vote up
void duringCompletion(CompletionInitializationContext initContext, CompletionParameters parameters) {
  if (isAutopopupCompletion() && shouldPreselectFirstSuggestion(parameters)) {
    myLookup.setFocusDegree(CodeInsightSettings.getInstance().isSelectAutopopupSuggestionsByChars() ? LookupImpl.FocusDegree.FOCUSED : LookupImpl.FocusDegree.SEMI_FOCUSED);
  }
  addDefaultAdvertisements(parameters);

  ProgressManager.checkCanceled();

  Document document = initContext.getEditor().getDocument();
  if (!initContext.getOffsetMap().wasModified(CompletionInitializationContext.IDENTIFIER_END_OFFSET)) {
    try {
      final int selectionEndOffset = initContext.getSelectionEndOffset();
      final PsiReference reference = TargetElementUtil.findReference(myEditor, selectionEndOffset);
      if (reference != null) {
        final int replacementOffset = findReplacementOffset(selectionEndOffset, reference);
        if (replacementOffset > document.getTextLength()) {
          LOG.error("Invalid replacementOffset: " + replacementOffset + " returned by reference " + reference + " of " + reference.getClass() +
                    "; doc=" + document +
                    "; doc actual=" + (document == initContext.getFile().getViewProvider().getDocument()) +
                    "; doc committed=" + PsiDocumentManager.getInstance(getProject()).isCommitted(document));
        }
        else {
          initContext.setReplacementOffset(replacementOffset);
        }
      }
    }
    catch (IndexNotReadyException ignored) {
    }
  }

  for (CompletionContributor contributor : CompletionContributor.forLanguageHonorDumbness(initContext.getPositionLanguage(), initContext.getProject())) {
    ProgressManager.checkCanceled();
    contributor.duringCompletion(initContext);
  }
  if (document instanceof DocumentWindow) {
    myHostOffsets = new OffsetsInFile(initContext.getFile(), initContext.getOffsetMap()).toTopLevelFile();
  }
}
 
Example #29
Source File: CodeCompletionHandlerBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static boolean isAutocompleteOnInvocation(final CompletionType type) {
  final CodeInsightSettings settings = CodeInsightSettings.getInstance();
  if (type == CompletionType.SMART) {
    return settings.AUTOCOMPLETE_ON_SMART_TYPE_COMPLETION;
  }
  return settings.AUTOCOMPLETE_ON_CODE_COMPLETION;
}
 
Example #30
Source File: ParameterInfoController.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void moveToParameterAtOffset(int offset) {
  PsiFile file = PsiDocumentManager.getInstance(myProject).getPsiFile(myEditor.getDocument());
  PsiElement argsList = findArgumentList(file, offset, -1);
  if (argsList == null && !CodeInsightSettings.getInstance().SHOW_PARAMETER_NAME_HINTS_ON_COMPLETION) return;

  if (!myHint.isVisible()) AutoPopupController.getInstance(myProject).autoPopupParameterInfo(myEditor, null);

 offset = adjustOffsetToInlay(offset);
  myEditor.getCaretModel().moveToOffset(offset);
  myEditor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
  myEditor.getSelectionModel().removeSelection();
  if (argsList != null) {
    executeUpdateParameterInfo(argsList, new MyUpdateParameterInfoContext(offset, file), null);
  }
}