private void autoImport(@NotNull InsertionContext context, @Nullable String organization, @NotNull String packageName, @Nullable String alias) { PsiFile file = context.getFile(); final String importPath = organization == null ? packageName : organization + "/" + packageName; ApplicationManager.getApplication().runWriteAction(() -> { BallerinaFile.addImport(((BallerinaFile) file), importPath, alias); }); }
@Override public void handleInsert(@NotNull InsertionContext context, LookupElement item) { PsiFile file = context.getFile(); if (!(file instanceof GoFile)) return; context.commitDocument(); int offset = context.getStartOffset(); PsiElement at = file.findElementAt(offset); GoCompositeElement ref = PsiTreeUtil.getParentOfType(at, GoValue.class, GoReferenceExpression.class); if (ref instanceof GoReferenceExpression && (((GoReferenceExpression)ref).getQualifier() != null || GoPsiImplUtil.prevDot(ref))) { return; } GoValue value = PsiTreeUtil.getParentOfType(at, GoValue.class); if (value == null || PsiTreeUtil.getPrevSiblingOfType(value, GoKey.class) != null) return; super.handleInsert(context, item); } };
private static void autoImport(@NotNull InsertionContext context, @NotNull GoNamedElement element) { PsiFile file = context.getFile(); boolean vendoringEnabled = GoVendoringUtil.isVendoringEnabled(ModuleUtilCore.findModuleForPsiElement(file)); String importPath = element.getContainingFile().getImportPath(vendoringEnabled); if (StringUtil.isEmpty(importPath)) return; PsiDocumentManager.getInstance(context.getProject()).commitDocument(context.getEditor().getDocument()); PsiReference reference = file.findReferenceAt(context.getStartOffset()); if (reference != null) { PsiElement referenceElement = reference.getElement(); GoImportPackageQuickFix fix = new GoImportPackageQuickFix(referenceElement, importPath); fix.invoke(context.getProject(), file, context.getEditor(), referenceElement, referenceElement); } } }
PsiFile file = context.getFile(); if (!(file instanceof BallerinaFile)) { return;
private boolean shouldAddComma(final @NotNull InsertionContext context) { PsiFile psiFile = context.getFile(); return Optional.ofNullable(psiFile.findElementAt(context.getStartOffset())) .map(el -> !jsonTraversal.isLastChild(el)) .orElse(false); } }
@Override public void handleInsert(InsertionContext context, LookupElement item) { PsiElement elementAt = context.getFile().findElementAt(context.getStartOffset()); GoFunctionOrMethodDeclaration declaration = PsiTreeUtil.getNonStrictParentOfType(elementAt, GoFunctionOrMethodDeclaration.class); if (declaration != null) {
public void handleInsert(@NotNull InsertionContext context, @NotNull TranslatorLookupElement lookupElement) { PsiElement elementAt = context.getFile().findElementAt(context.getStartOffset()); String domain = null; if(elementAt != null) { PsiElement element = TwigUtil.getElementOnTwigViewProvider(elementAt); TwigUtil.DomainScope domainScope = TwigUtil.getTwigFileDomainScope(element != null ? element : elementAt); String transDefaultDomain = domainScope.getDefaultDomain(); String myDomain = lookupElement.getDomain(); if(!transDefaultDomain.equalsIgnoreCase(myDomain)) { domain = myDomain; } } // preappend context.getDocument().insertString(context.getStartOffset(), "{{ '"); StringBuilder stringBuilder = new StringBuilder(); // 'foo.bar' stringBuilder.append("'|trans"); // domain if(domain != null) { stringBuilder.append(String.format("({}, '%s')", domain)); } stringBuilder.append(" }}"); PhpInsertHandlerUtil.insertStringAtCaret(context.getEditor(), stringBuilder.toString()); }
public static void insertUse(InsertionContext context, String fqnAnnotation) { PsiElement element = PsiUtilCore.getElementAtOffset(context.getFile(), context.getStartOffset()); PhpPsiElement scopeForUseOperator = PhpCodeInsightUtil.findScopeForUseOperator(element); if(null == scopeForUseOperator) { return; } // PhpCodeInsightUtil.canImport: // copied from PhpReferenceInsertHandler; throws an error on PhpContractUtil because of "fully qualified names only" // but that is catch on phpstorm side already; looks fixed now so use fqn if(!fqnAnnotation.startsWith("\\")) { fqnAnnotation = "\\" + fqnAnnotation; } // this looks suitable! :) if(PhpCodeInsightUtil.alreadyImported(scopeForUseOperator, fqnAnnotation) == null) { PsiDocumentManager.getInstance(context.getProject()).commitDocument(context.getDocument()); PhpAliasImporter.insertUseStatement(fqnAnnotation, scopeForUseOperator); PsiDocumentManager.getInstance(context.getProject()).doPostponedOperationsAndUnblockDocument(context.getDocument()); } } }
@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); } } }
final PsiElement headOfFunction = PsiTreeUtil.findElementOfClassAtRange(context.getFile(), context.getStartOffset(), context.getTailOffset(), PsiElement.class); final TemplateBuilderFactory factory = TemplateBuilderFactoryImpl.getInstance(); final TemplateBuilderImpl builder = (TemplateBuilderImpl) factory.createTemplateBuilder(headOfFunction);