com.intellij.codeInsight.AutoPopupController Java Examples

The following examples show how to use com.intellij.codeInsight.AutoPopupController. 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: BuildCompletionAutoPopupHandler.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Override
public Result checkAutoPopup(
    char charTyped, final Project project, final Editor editor, final PsiFile file) {
  if (!(file instanceof BuildFile)) {
    return Result.CONTINUE;
  }
  if (LookupManager.getActiveLookup(editor) != null) {
    return Result.CONTINUE;
  }

  if (charTyped != '/' && charTyped != ':') {
    return Result.CONTINUE;
  }
  PsiElement psi = file.findElementAt(editor.getCaretModel().getOffset());
  if (psi != null && psi.getParent() instanceof StringLiteral) {
    AutoPopupController.getInstance(project).scheduleAutoPopup(editor);
    return Result.STOP;
  }
  return Result.CONTINUE;
}
 
Example #2
Source File: AddColonSpaceInsertHandler.java    From js-graphql-intellij-plugin with MIT License 6 votes vote down vote up
public void handleInsert(InsertionContext context, LookupElement item) {
  Editor editor = context.getEditor();
  char completionChar = context.getCompletionChar();
  if (completionChar == ' ' || StringUtil.containsChar(myIgnoreOnChars, completionChar)) return;
  Project project = editor.getProject();
  if (project != null) {
    if (!isCharAtColon(editor)) {
      EditorModificationUtil.insertStringAtCaret(editor, ": ");
      PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());
    } else {
      editor.getCaretModel().moveToOffset(editor.getCaretModel().getOffset() + 2);
    }
    if (myTriggerAutoPopup) {
      AutoPopupController.getInstance(project).autoPopupMemberLookup(editor, null);
    }
  }
}
 
Example #3
Source File: CompletionAutoPopupHandler.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public Result checkAutoPopup(char charTyped, @Nonnull final Project project, @Nonnull final Editor editor, @Nonnull final PsiFile file) {
  LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(editor);

  if (LOG.isDebugEnabled()) {
    LOG.debug("checkAutoPopup: character=" + charTyped + ";");
    LOG.debug("phase=" + CompletionServiceImpl.getCompletionPhase());
    LOG.debug("lookup=" + lookup);
    LOG.debug("currentCompletion=" + CompletionServiceImpl.getCompletionService().getCurrentCompletion());
  }

  if (lookup != null) {
    if (editor.getSelectionModel().hasSelection()) {
      lookup.performGuardedChange(() -> EditorModificationUtil.deleteSelectedText(editor));
    }
    return Result.STOP;
  }

  if (Character.isLetterOrDigit(charTyped) || charTyped == '_') {
    AutoPopupController.getInstance(project).scheduleAutoPopup(editor);
    return Result.STOP;
  }

  return Result.CONTINUE;
}
 
Example #4
Source File: AddSpaceInsertHandler.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void handleInsert(InsertionContext context, LookupElement item) {
  Editor editor = context.getEditor();
  char completionChar = context.getCompletionChar();
  if (completionChar == ' ' || StringUtil.containsChar(myIgnoreOnChars, completionChar)) return;
  Project project = editor.getProject();
  if (project != null) {
    if (!isCharAtSpace(editor)) {
      EditorModificationUtil.insertStringAtCaret(editor, " ");
      PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());
    }
    else if (shouldOverwriteExistingSpace(editor)) {
      editor.getCaretModel().moveToOffset(editor.getCaretModel().getOffset() + 1);
    }
    if (myTriggerAutoPopup) {
      AutoPopupController.getInstance(project).autoPopupMemberLookup(editor, null);
    }
  }
}
 
Example #5
Source File: BuckTargetAutoPopupHandler.java    From buck with Apache License 2.0 6 votes vote down vote up
@NotNull
@Override
public Result checkAutoPopup(
    char charTyped, @NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) {
  if (!file.getLanguage().isKindOf(BuckLanguage.INSTANCE)
      || (charTyped != '/' && charTyped != ':')) {
    return Result.CONTINUE;
  }
  final PsiElement at = file.findElementAt(editor.getCaretModel().getOffset());
  if (at == null
      || !BuckPsiUtils.hasElementType(
          at,
          BuckTypes.APOSTROPHED_STRING,
          BuckTypes.APOSTROPHED_RAW_STRING,
          BuckTypes.TRIPLE_APOSTROPHED_STRING,
          BuckTypes.TRIPLE_APOSTROPHED_RAW_STRING,
          BuckTypes.QUOTED_STRING,
          BuckTypes.QUOTED_RAW_STRING,
          BuckTypes.TRIPLE_QUOTED_STRING,
          BuckTypes.TRIPLE_QUOTED_RAW_STRING)) {
    return Result.CONTINUE;
  }
  AutoPopupController.getInstance(project).scheduleAutoPopup(editor);
  return Result.STOP;
}
 
Example #6
Source File: HaxeTypedHandler.java    From intellij-haxe with Apache License 2.0 6 votes vote down vote up
@NotNull
@Override
public Result checkAutoPopup(char charTyped, @NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) {

  int offset = editor.getCaretModel().getOffset();
  PsiElement prevElement = file.findElementAt(offset-1);
  if (prevElement == null || prevElement.getLanguage() != HaxeLanguage.INSTANCE) {
    return Result.CONTINUE;
  }

  if (isAutoPopChar(charTyped) || (isAutoPopSpace(charTyped) && isAutoPopChar(prevElement))) {
    AutoPopupController.getInstance(project).scheduleAutoPopup(editor, CompletionType.SMART, null);
    return Result.STOP;
  }
  return super.checkAutoPopup(charTyped, project, editor, file);
}
 
Example #7
Source File: TextFieldWithCompletion.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected EditorEx createEditor() {
  EditorEx editor = super.createEditor();
  EditorCustomization disableSpellChecking = SpellCheckingEditorCustomizationProvider.getInstance().getDisabledCustomization();
  if (disableSpellChecking != null) disableSpellChecking.customize(editor);
  editor.putUserData(AutoPopupController.ALWAYS_AUTO_POPUP, myForceAutoPopup);

  if (myShowHint) {
    TextCompletionUtil.installCompletionHint(editor);
  }

  return editor;
}
 
Example #8
Source File: JsxNameCompletionProvider.java    From reasonml-idea-plugin with MIT License 5 votes vote down vote up
private static void insertTagNameHandler(@NotNull Project project, @NotNull InsertionContext context, @NotNull String tagName) {
    char completionChar = context.getCompletionChar();
    if (completionChar == ' ') {
        context.setAddCompletionChar(false);
    }

    Editor editor = context.getEditor();
    EditorModificationUtil.insertStringAtCaret(editor, " ></" + tagName + ">");
    editor.getCaretModel().moveToOffset(editor.getCaretModel().getOffset() - 4 - tagName.length());

    AutoPopupController.getInstance(project).autoPopupMemberLookup(editor, null);
}
 
Example #9
Source File: TemplateExpressionLookupElement.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static boolean handleCompletionChar(InsertionContext context) {
  if (context.getCompletionChar() == '.') {
    EditorModificationUtil.insertStringAtCaret(context.getEditor(), ".");
    AutoPopupController.getInstance(context.getProject()).autoPopupMemberLookup(context.getEditor(), null);
    return false;
  }
  return true;
}
 
Example #10
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);
  }
}
 
Example #11
Source File: XQueryFunctionInsertHandler.java    From intellij-xquery with Apache License 2.0 5 votes vote down vote up
@Override
public void handleInsert(InsertionContext context, LookupElement item) {
    super.handleInsert(context, item);
    InsertHandlerUtils.removePreviousNamespaceAndColonIfPresent(context);
    AutoPopupController.getInstance(context.getProject()).autoPopupParameterInfo(context.getEditor(),
            item.getPsiElement());
}
 
Example #12
Source File: CSharpStatementCompletionContributor.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Override
@RequiredReadAction
public void handleInsert(InsertionContext insertionContext, LookupElement item)
{
	Editor editor = insertionContext.getEditor();
	int offset = editor.getCaretModel().getOffset();
	boolean isVoidReturnType = DotNetTypeRefUtil.isVmQNameEqual(myPseudoMethod.getReturnTypeRef(), myPseudoMethod, DotNetTypes.System.Void);

	if(isVoidReturnType)
	{
		if(insertionContext.getCompletionChar() == '\n')
		{
			TailType.insertChar(editor, offset, ';');
			insertionContext.getEditor().getCaretModel().moveToOffset(offset + 1);
		}
	}
	else
	{
		if(insertionContext.getCompletionChar() == '\n')
		{
			TailType.insertChar(editor, offset, ' ');

			insertionContext.getEditor().getCaretModel().moveToOffset(offset + 1);
		}

		AutoPopupController.getInstance(editor.getProject()).autoPopupMemberLookup(editor, null);
	}
}
 
Example #13
Source File: CSharpTypedHandler.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
private static void autoPopupMemberLookup(Project project, final Editor editor)
{
	AutoPopupController.getInstance(project).autoPopupMemberLookup(editor, new Condition<PsiFile>()
	{
		@Override
		@RequiredReadAction
		public boolean value(final PsiFile file)
		{
			int offset = editor.getCaretModel().getOffset();

			PsiElement lastElement = file.findElementAt(offset - 1);
			if(lastElement == null)
			{
				return false;
			}

			final PsiElement prevSibling = PsiTreeUtil.prevVisibleLeaf(lastElement);
			if(prevSibling == null || ".".equals(prevSibling.getText()))
			{
				return false;
			}
			PsiElement parent = prevSibling;
			do
			{
				parent = parent.getParent();
			}
			while(parent instanceof CSharpReferenceExpression);

			return true;
		}
	});
}
 
Example #14
Source File: CSharpTypedHandler.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Override
public Result checkAutoPopup(char charTyped, Project project, Editor editor, PsiFile file)
{
	if(charTyped == '@')
	{
		AutoPopupController.getInstance(project).scheduleAutoPopup(editor);
		return Result.STOP;
	}
	return Result.CONTINUE;
}
 
Example #15
Source File: JSGraphQLEndpointImportInsertHandler.java    From js-graphql-intellij-plugin with MIT License 5 votes vote down vote up
public void handleInsert(InsertionContext context, LookupElement item) {
  final Editor editor = context.getEditor();
  final Project project = editor.getProject();
  if (project != null) {
    EditorModificationUtil.insertStringAtCaret(editor, " \"\"");
    PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());
    editor.getCaretModel().moveToOffset(editor.getCaretModel().getOffset() - 1);
    if (myTriggerAutoPopup) {
      AutoPopupController.getInstance(project).autoPopupMemberLookup(editor, null);
    }
  }
}
 
Example #16
Source File: CSharpParenthesesInsertHandler.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@RequiredUIAccess
@Override
public void handleInsert(final InsertionContext context, final LookupElement item)
{
	final Editor editor = context.getEditor();
	final Document document = editor.getDocument();
	context.commitDocument();
	PsiElement element = findNextToken(context);

	final char completionChar = context.getCompletionChar();
	final boolean putCaretInside = completionChar == '(' || placeCaretInsideParentheses();

	if(completionChar == '(')
	{
		context.setAddCompletionChar(false);
	}

	if(isToken(element, "("))
	{
		int lparenthOffset = element.getTextRange().getStartOffset();

		if(completionChar == '(' || completionChar == '\t')
		{
			editor.getCaretModel().moveToOffset(lparenthOffset + 1);
		}
		else
		{
			editor.getCaretModel().moveToOffset(context.getTailOffset());
		}

		context.setTailOffset(lparenthOffset + 1);

		PsiElement list = element.getParent();
		PsiElement last = list.getLastChild();
		if(isToken(last, ")"))
		{
			int rparenthOffset = last.getTextRange().getStartOffset();
			context.setTailOffset(rparenthOffset + 1);
			if(!putCaretInside)
			{
				for(int i = lparenthOffset + 1; i < rparenthOffset; i++)
				{
					if(!Character.isWhitespace(document.getCharsSequence().charAt(i)))
					{
						return;
					}
				}
				editor.getCaretModel().moveToOffset(context.getTailOffset());
			}
			else
			{
				AutoPopupController.getInstance(context.getProject()).autoPopupParameterInfo(editor, CSharpParameterInfoHandler.item(myLikeMethodDeclaration));

				editor.getCaretModel().moveToOffset(lparenthOffset + 1);
			}
			return;
		}
	}
	else
	{
		document.insertString(context.getTailOffset(), "" + "(" + "");
		editor.getCaretModel().moveToOffset(context.getTailOffset());
	}

	if(context.getCompletionChar() == '(')
	{
		//todo use BraceMatchingUtil.isPairedBracesAllowedBeforeTypeInFileType
		int tail = context.getTailOffset();
		if(tail < document.getTextLength() && StringUtil.isJavaIdentifierPart(document.getCharsSequence().charAt(tail)))
		{
			return;
		}
	}

	document.insertString(context.getTailOffset(), ")");
	if(!putCaretInside)
	{
		editor.getCaretModel().moveToOffset(context.getTailOffset());
	}
	else
	{
		AutoPopupController.getInstance(context.getProject()).autoPopupParameterInfo(editor, CSharpParameterInfoHandler.item(myLikeMethodDeclaration));
	}
}
 
Example #17
Source File: ParameterInfoController.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void updateComponent() {
  if (!myKeepOnHintHidden && !myHint.isVisible() && !ApplicationManager.getApplication().isHeadlessEnvironment() || myEditor instanceof EditorWindow && !((EditorWindow)myEditor).isValid()) {
    Disposer.dispose(this);
    return;
  }

  final PsiFile file = PsiUtilBase.getPsiFileInEditor(myEditor, myProject);
  int caretOffset = myEditor.getCaretModel().getOffset();
  final int offset = getCurrentOffset();
  final MyUpdateParameterInfoContext context = new MyUpdateParameterInfoContext(offset, file);
  executeFindElementForUpdatingParameterInfo(context, elementForUpdating -> {
    myHandler.processFoundElementForUpdatingParameterInfo(elementForUpdating, context);
    if (elementForUpdating != null) {
      executeUpdateParameterInfo(elementForUpdating, context, () -> {
        boolean knownParameter = (myComponent.getObjects().length == 1 || myComponent.getHighlighted() != null) && myComponent.getCurrentParameterIndex() != -1;
        if (mySingleParameterInfo && !knownParameter && myHint.isVisible()) {
          hideHint();
        }
        if (myKeepOnHintHidden && knownParameter && !myHint.isVisible()) {
          AutoPopupController.getInstance(myProject).autoPopupParameterInfo(myEditor, null);
        }
        if (!myDisposed &&
            (myHint.isVisible() && !myEditor.isDisposed() && (myEditor.getComponent().getRootPane() != null || ApplicationManager.getApplication().isUnitTestMode()) ||
             ApplicationManager.getApplication().isHeadlessEnvironment())) {
          Model result = myComponent.update(mySingleParameterInfo);
          result.project = myProject;
          result.range = myComponent.getParameterOwner().getTextRange();
          result.editor = myEditor;
          //for (ParameterInfoListener listener : ParameterInfoListener.EP_NAME.getExtensionList()) {
          //  listener.hintUpdated(result);
          //}
          if (ApplicationManager.getApplication().isHeadlessEnvironment()) return;
          IdeTooltip tooltip = myHint.getCurrentIdeTooltip();
          short position = tooltip != null ? toShort(tooltip.getPreferredPosition()) : HintManager.ABOVE;
          Pair<Point, Short> pos = myProvider.getBestPointPosition(myHint, elementForUpdating, caretOffset, myEditor.getCaretModel().getVisualPosition(), position);
          HintManagerImpl.adjustEditorHintPosition(myHint, myEditor, pos.getFirst(), pos.getSecond());
        }
      });
    }
    else {
      hideHint();
      if (!myKeepOnHintHidden) {
        Disposer.dispose(this);
      }
    }
  });
}
 
Example #18
Source File: TypedHandler.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static void autoPopupParameterInfo(@Nonnull Editor editor, char charTyped, @Nonnull Project project, @Nonnull PsiFile file) {
  if ((charTyped == '(' || charTyped == ',') && !isInsideStringLiteral(editor, file)) {
    AutoPopupController.getInstance(project).autoPopupParameterInfo(editor, null);
  }
}
 
Example #19
Source File: TypedHandler.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static void autoPopupCompletion(@Nonnull Editor editor, char charTyped, @Nonnull Project project, @Nonnull PsiFile file) {
  if (charTyped == '.' || isAutoPopup(editor, file, charTyped)) {
    AutoPopupController.getInstance(project).autoPopupMemberLookup(editor, null);
  }
}
 
Example #20
Source File: GraphQLCompletionContributor.java    From js-graphql-intellij-plugin with MIT License 4 votes vote down vote up
private void completeFieldNames() {
    CompletionProvider<CompletionParameters> provider = new CompletionProvider<CompletionParameters>() {
        @Override
        protected void addCompletions(@NotNull final CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {

            // move "__*" fields to bottom
            final CompletionResultSet orderedResult = updateResult(parameters, result);

            final PsiElement completionElement = Optional.ofNullable(parameters.getOriginalPosition()).orElse(parameters.getPosition());

            GraphQLTypeScopeProvider typeScopeProvider = PsiTreeUtil.getParentOfType(completionElement, GraphQLTypeScopeProvider.class);

            // check for incomplete field name, in which case we want the parent element as type scope to find this field name
            GraphQLField completionField = null;
            if (completionElement.getNode().getElementType() == GraphQLElementTypes.NAME) {
                completionField = PsiTreeUtil.getParentOfType(completionElement, GraphQLField.class);
            }
            if (typeScopeProvider == completionField) {
                // completed on incomplete field name, use parent
                typeScopeProvider = PsiTreeUtil.getParentOfType(typeScopeProvider, GraphQLTypeScopeProvider.class);
            }

            if (typeScopeProvider != null) {

                PsiElement textBeforeCompletion = PsiTreeUtil.prevLeaf(completionElement);
                boolean isSpread = textBeforeCompletion != null && textBeforeCompletion.getText().startsWith(".");

                if (!isSpread) {
                    GraphQLType typeScope = typeScopeProvider.getTypeScope();
                    if (typeScope != null) {
                        // we need the raw type to get the fields
                        typeScope = GraphQLUtil.getUnmodifiedType(typeScope);
                    }
                    if (typeScope instanceof GraphQLFieldsContainer) {
                        ((GraphQLFieldsContainer) typeScope).getFieldDefinitions().forEach(field -> {
                            LookupElementBuilder element = LookupElementBuilder
                                    .create(field.getName())
                                    .withBoldness(true)
                                    .withTypeText(SchemaIDLUtil.typeString(field.getType()));
                            if (field.getDescription() != null) {
                                final String fieldDocumentation = GraphQLDocumentationMarkdownRenderer.getDescriptionAsPlainText(field.getDescription(), true);
                                element = element.withTailText(" - " + fieldDocumentation, true);
                            }
                            if (field.isDeprecated()) {
                                element = element.strikeout();
                                if (field.getDeprecationReason() != null) {
                                    final String deprecationReason = GraphQLDocumentationMarkdownRenderer.getDescriptionAsPlainText(field.getDeprecationReason(), true);
                                    element = element.withTailText(" - Deprecated: " + deprecationReason, true);
                                }
                            }
                            for (graphql.schema.GraphQLArgument fieldArgument : field.getArguments()) {
                                if (fieldArgument.getType() instanceof GraphQLNonNull) {
                                    // on of the field arguments are required, so add the '()' for arguments
                                    element = element.withInsertHandler((ctx, item) -> {
                                        ParenthesesInsertHandler.WITH_PARAMETERS.handleInsert(ctx, item);
                                        AutoPopupController.getInstance(ctx.getProject()).autoPopupMemberLookup(ctx.getEditor(), null);
                                    });
                                    break;
                                }
                            }
                            orderedResult.addElement(element);
                        });
                    }
                    if (!(typeScopeProvider instanceof GraphQLOperationDefinition)) {
                        // show the '...' except when top level selection in an operation
                        orderedResult.addElement(LookupElementBuilder.create("...").withInsertHandler((ctx, item) -> {
                            AutoPopupController.getInstance(ctx.getProject()).autoPopupMemberLookup(ctx.getEditor(), null);
                        }));
                        // and add the built-in __typename option
                        orderedResult.addElement(LookupElementBuilder.create("__typename"));
                    }
                }
            }
        }
    };
    extend(CompletionType.BASIC, psiElement(GraphQLElementTypes.NAME).withSuperParent(2, GraphQLField.class), provider);
}
 
Example #21
Source File: LookupImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
public boolean showLookup() {
  ApplicationManager.getApplication().assertIsDispatchThread();
  checkValid();
  LOG.assertTrue(!myShown);
  myShown = true;
  myStampShown = System.currentTimeMillis();

  fireLookupShown();

  if (ApplicationManager.getApplication().isHeadlessEnvironment()) return true;

  if (!myEditor.getContentComponent().isShowing()) {
    hideLookup(false);
    return false;
  }

  myAdComponent.showRandomText();
  if (Boolean.TRUE.equals(myEditor.getUserData(AutoPopupController.NO_ADS))) {
    myAdComponent.clearAdvertisements();
  }

  myUi = new LookupUi(this, myAdComponent, myList);//, myProject);
  myUi.setCalculating(myCalculating);
  Point p = myUi.calculatePosition().getLocation();
  if (ScreenReader.isActive()) {
    myList.setFocusable(true);
    setFocusRequestor(myList);

    AnActionEvent actionEvent = AnActionEvent.createFromDataContext(ActionPlaces.EDITOR_POPUP, null, ((DesktopEditorImpl)myEditor).getDataContext());
    delegateActionToEditor(IdeActions.ACTION_EDITOR_BACKSPACE, null, actionEvent);
    delegateActionToEditor(IdeActions.ACTION_EDITOR_ESCAPE, null, actionEvent);
    delegateActionToEditor(IdeActions.ACTION_EDITOR_TAB, () -> new ChooseItemAction.Replacing(), actionEvent);
    delegateActionToEditor(IdeActions.ACTION_EDITOR_ENTER,
            /* e.g. rename popup comes initially unfocused */
                           () -> getFocusDegree() == FocusDegree.UNFOCUSED ? new NextVariableAction() : new ChooseItemAction.FocusedOnly(), actionEvent);
    delegateActionToEditor(IdeActions.ACTION_EDITOR_MOVE_CARET_UP, null, actionEvent);
    delegateActionToEditor(IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN, null, actionEvent);
    delegateActionToEditor(IdeActions.ACTION_EDITOR_MOVE_CARET_RIGHT, null, actionEvent);
    delegateActionToEditor(IdeActions.ACTION_EDITOR_MOVE_CARET_LEFT, null, actionEvent);
    delegateActionToEditor(IdeActions.ACTION_RENAME, null, actionEvent);
  }
  try {
    HintManagerImpl.getInstanceImpl()
            .showEditorHint(this, myEditor, p, HintManager.HIDE_BY_ESCAPE | HintManager.UPDATE_BY_SCROLLING, 0, false, HintManagerImpl.createHintHint(myEditor, p, this, HintManager.UNDER).
                    setRequestFocus(ScreenReader.isActive()).
                    setAwtTooltip(false));
  }
  catch (Exception e) {
    LOG.error(e);
  }

  if (!isVisible() || !myList.isShowing()) {
    hideLookup(false);
    return false;
  }

  return true;
}
 
Example #22
Source File: GraphQLCompletionContributor.java    From js-graphql-intellij-plugin with MIT License 4 votes vote down vote up
private void completeConstantsOrListOrInputObject() {
    CompletionProvider<CompletionParameters> provider = new CompletionProvider<CompletionParameters>() {
        @Override
        protected void addCompletions(@NotNull final CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {

            final PsiElement completionElement = parameters.getPosition();
            final GraphQLTypeScopeProvider typeScopeProvider = PsiTreeUtil.getParentOfType(completionElement, GraphQLTypeScopeProvider.class);
            if (typeScopeProvider != null) {
                final GraphQLType typeScope = typeScopeProvider.getTypeScope();
                if (typeScope != null) {
                    final InsertHandler<LookupElement> literalInsertHandler = (ctx, item) -> {
                        ctx.getEditor().getCaretModel().moveCaretRelatively(-1, 0, false, false, false);
                        AutoPopupController.getInstance(ctx.getProject()).autoPopupMemberLookup(ctx.getEditor(), null);
                    };
                    if (typeScope instanceof GraphQLList || (typeScope instanceof GraphQLNonNull && ((GraphQLNonNull) typeScope).getWrappedType() instanceof GraphQLList)) {
                        // list or non-null list
                        result.addElement(LookupElementBuilder.create("[]").withInsertHandler(literalInsertHandler));
                    } else {
                        // raw type is enum, boolean or object
                        final GraphQLUnmodifiedType rawType = GraphQLUtil.getUnmodifiedType(typeScope);
                        if (rawType instanceof GraphQLEnumType) {
                            ((GraphQLEnumType) rawType).getValues().forEach(value -> {
                                result.addElement(LookupElementBuilder.create(value.getName()).withTypeText(GraphQLUtil.getName(typeScope)));
                            });
                        } else if (rawType instanceof GraphQLInputObjectType) {
                            if (parameters.getOriginalPosition() != null && !parameters.getOriginalPosition().getText().equals("{")) {
                                result.addElement(LookupElementBuilder.create("{}").withInsertHandler(literalInsertHandler));
                            }
                        } else {
                            if ("Boolean".equals(rawType.getName())) {
                                result.addElement(LookupElementBuilder.create("true").withBoldness(true));
                                result.addElement(LookupElementBuilder.create("false").withBoldness(true));
                            }
                            // TODO JKM 'null' completion?
                        }
                    }
                }
            }

        }
    };
    // NOTE: the PSI produces enum values when none of the keywords match, e.g. 'tru' is considered a possible enum value
    extend(CompletionType.BASIC, psiElement(GraphQLElementTypes.NAME).afterLeaf(":").withSuperParent(2, GraphQLEnumValue.class), provider);
}