@Override public void handleInsert(@NotNull InsertionContext context, @NotNull LookupElement item) { PsiElement element = item.getPsiElement(); if (element instanceof GoNamedElement) { if (myClass != null && myDelegate != null && myClass.isInstance(element)) { myDelegate.handleInsert(context, item); } autoImport(context, (GoNamedElement)element); } }
@Override public void handleInsert(InsertionContext context, @NotNull LookupElement item) { PsiElement e = item.getPsiElement(); if (e instanceof GoSignatureOwner) { doInsert(context, item, ((GoSignatureOwner)e).getSignature()); } else if (e instanceof GoNamedElement) { GoType type = ((GoNamedElement)e).getGoType(null); if (type instanceof GoFunctionType) { doInsert(context, item, ((GoFunctionType)type).getSignature()); } } }
@Override public void renderElement(LookupElement element, LookupElementPresentation presentation) { presentation.setItemText(name); presentation.setItemTextBold(true); PsiElement psiElement = element.getPsiElement(); if (psiElement == null) { renderObject(element); } else { renderPsiElement(psiElement, presentation); } }
@Override public void renderElement(@NotNull LookupElement element, @NotNull LookupElementPresentation p) { PsiElement o = element.getPsiElement(); if (!(o instanceof GoNamedElement)) return; GoNamedElement v = (GoNamedElement)o; GoType type = typesDisabled ? null : v.getGoType(null); String text = GoPsiImplUtil.getText(type); Icon icon = v instanceof GoVarDefinition ? GoIcons.VARIABLE : v instanceof GoParamDefinition ? GoIcons.PARAMETER : v instanceof GoFieldDefinition ? GoIcons.FIELD : v instanceof GoReceiver ? GoIcons.RECEIVER : v instanceof GoConstDefinition ? GoIcons.CONSTANT : v instanceof GoAnonymousFieldDefinition ? GoIcons.FIELD : null; p.setIcon(icon); p.setTailText(calcTailTextForFields(v), true); p.setTypeText(text); p.setTypeGrayed(true); p.setItemText(element.getLookupString()); } };
@Override public void renderElement(@NotNull LookupElement element, @NotNull LookupElementPresentation p) { PsiElement o = element.getPsiElement(); if (!(o instanceof GoNamedSignatureOwner)) return; GoNamedSignatureOwner f = (GoNamedSignatureOwner)o; Icon icon = f instanceof GoMethodDeclaration || f instanceof GoMethodSpec ? GoIcons.METHOD : GoIcons.FUNCTION; String typeText = ""; GoSignature signature = f.getSignature(); String paramText = ""; if (signature != null) { GoResult result = signature.getResult(); paramText = signature.getParameters().getText(); if (result != null) typeText = result.getText(); } p.setIcon(icon); p.setTypeText(typeText); p.setTypeGrayed(true); p.setTailText(calcTailText(f), true); p.setItemText(element.getLookupString() + paramText); } };
@Override public void fillActions(LookupElement element, Lookup lookup, Consumer<LookupElementAction> consumer) { PsiElement psiElement = element.getPsiElement(); PsiFile file = psiElement != null && psiElement.isValid() ? psiElement.getContainingFile() : null; String importPath = file instanceof GoFile ? ((GoFile)file).getImportPath(false) : null; if (importPath != null) { Project project = psiElement.getProject(); for (String path : getPaths(importPath)) { consumer.consume(new ExcludePathAction(project, path)); } consumer.consume(new EditExcludedAction(project)); } }
@Override public void renderElement(LookupElement element, LookupElementPresentation presentation) { presentation.setItemText(name); presentation.setItemTextBold(true); PsiElement psiElement = element.getPsiElement(); assert psiElement != null; presentation.setIcon(icon(psiElement)); presentation.setItemTextForeground(color(psiElement)); /* Add a space between variable name and match. See https://github.com/KronicDeth/intellij-elixir/issues/506 */ presentation.appendTailText(" ", false); TextRange psiElementTextRange = psiElement.getTextRange(); PsiElement enclosingMatch = enclosingMatch(psiElement); TextRange enclosingMatchTextRange = enclosingMatch.getTextRange(); String enclosingMatchText = enclosingMatch.getText(); int enclosingMatchTextRangeStartOffset = enclosingMatchTextRange.getStartOffset(); int itemStartOffset = psiElementTextRange.getStartOffset() - enclosingMatchTextRangeStartOffset; String prefix = enclosingMatchText.substring(0, itemStartOffset); presentation.appendTailText(prefix, true); int itemEndOffset = psiElementTextRange.getEndOffset() - enclosingMatchTextRangeStartOffset; String item = enclosingMatchText.substring(itemStartOffset, itemEndOffset); presentation.appendTailText(item, false); String suffix = enclosingMatchText.substring( itemEndOffset, enclosingMatchTextRange.getEndOffset() - enclosingMatchTextRangeStartOffset ); presentation.appendTailText(suffix, true); }
@Nullable @Override public PsiElement getPsiElement() { return lookupElement.getPsiElement(); }
ApplicationManager.getApplication().invokeLater(() -> { CommandProcessor.getInstance().runUndoTransparentAction(() -> { PsiElement element = item.getPsiElement(); if (element == null) { return;
int completionCharOffset = getCompletionCharOffset(editor); if (completionCharOffset == -1) { PsiElement psiElement = item.getPsiElement(); if (psiElement != null) { String hasAReturnValue = psiElement.getUserData(HAS_A_RETURN_VALUE);
public void handleInsert(@NotNull InsertionContext context, @NotNull LookupElement lookupElement) { PsiElement psiElement = lookupElement.getPsiElement(); if(psiElement instanceof Method && needParameter((Method) psiElement)) { // check this: // {{ form_javasc|() }} // {{ form_javasc| }} if(PhpInsertHandlerUtil.isStringAtCaret(context.getEditor(), "(")) { return; } String addText = "()"; PhpInsertHandlerUtil.insertStringAtCaret(context.getEditor(), addText); context.getEditor().getCaretModel().moveCaretRelatively(-1, 0, false, false, true); } }
public static CompletionInfo<?> from(LookupElement el) { final PsiElement psi = el.getPsiElement(); if (psi instanceof PsiMethod) { return new MethodCompletionInfo(el, (PsiMethod) psi); } else if (psi instanceof PsiClass) { return new ClassCompletionInfo(el, (PsiClass) psi); } else if (psi instanceof PsiField) { return new FieldCompletionInfo(el, (PsiField) psi); } else if (psi instanceof PsiPackage) { return new PackageCompletionInfo(el, (PsiPackage) psi); } else if (psi instanceof PsiVariable) { return new VariableCompletionInfo(el, (PsiVariable) psi); } // any other (useful) info types? if (el != null) { final Class<?> type = psi == null ? null : psi.getClass(); System.out.println("Unexpected completion: " + el + " with element type " + type); } else { System.err.println("Null LookupElement?!"); } return null; } }
@Override public void handleInsert(@NotNull final InsertionContext context, @NotNull LookupElement item) { final Editor editor = context.getEditor(); int caretOffset = editor.getCaretModel().getOffset(); PsiElement targetElement = context.getFile().findElementAt(caretOffset); if (targetElement != null && targetElement.getNode().getElementType() == LEFT_PAREN) { return; } PsiElement subDefitnition = item.getPsiElement(); EditorModificationUtil.insertStringAtCaret(editor, "()"); // todo we need hint with prototype here, but prototypes handling NYI if (!(subDefitnition instanceof PerlSubDefinitionElement && ((PerlSubDefinitionElement)subDefitnition).getSubArgumentsList().isEmpty())) { editor.getCaretModel().moveCaretRelatively(-1, 0, false, false, true); } } }