@Override public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) { if (!(file instanceof GoFile)) { return; } String testingQualifier = null; if (myType.getParamType() != null) { testingQualifier = importTestingPackageIfNeeded((GoFile)file); PsiDocumentManager.getInstance(file.getProject()).doPostponedOperationsAndUnblockDocument(editor.getDocument()); } String functionText = "func " + myType.getPrefix(); int offset = functionText.length(); functionText += "(" + myType.getSignature(testingQualifier) + ") {\n\t\n}"; EditorModificationUtil.insertStringAtCaret(editor, functionText, false, offset); AutoPopupController.getInstance(project).scheduleAutoPopup(editor); }
@Override public void handleInsert(@NotNull InsertionContext context, LookupElement item) { Editor editor = context.getEditor(); int tailOffset = context.getTailOffset(); Document document = editor.getDocument(); context.commitDocument(); boolean staysAtChar = document.getTextLength() > tailOffset && document.getCharsSequence().charAt(tailOffset) == myChar; context.setAddCompletionChar(false); if (!staysAtChar) { document.insertString(tailOffset, String.valueOf(myChar)); } editor.getCaretModel().moveToOffset(tailOffset + 1); AutoPopupController.getInstance(context.getProject()).scheduleAutoPopup(editor); } }
@Override public void handleInsert(@NotNull InsertionContext context, LookupElement item) { Editor editor = context.getEditor(); int tailOffset = context.getTailOffset(); Document document = editor.getDocument(); context.commitDocument(); boolean staysAtChar = (document.getTextLength() > tailOffset) && (document.getCharsSequence().charAt(tailOffset) == myCharacter); context.setAddCompletionChar(false); if (!staysAtChar) { document.insertString(tailOffset, String.valueOf(myCharacter)); } editor.getCaretModel().moveToOffset(tailOffset + 1); AutoPopupController.getInstance(context.getProject()).scheduleAutoPopup(editor); } }
@NotNull @Override public Result checkAutoPopup(char typedChar, @NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) { int currentOffset = editor.getCaretModel().getOffset(); if (currentOffset > 0) { currentOffset--; } PsiElement element = file.findElementAt(currentOffset); if (element == null) { return super.checkAutoPopup(typedChar, project, editor, file); } IElementType elementType = PsiUtilCore.getElementType(element); if (typedChar == '>' && elementType == OPERATOR_MINUS || typedChar == ':' && elementType == COLON || typedChar == ' ' && (AUTO_OPENED_TOKENS.contains(elementType) || element.getParent() instanceof PsiPerlStringList) || typedChar == '{' && SIGILS.contains(elementType) || StringUtil.containsChar("$@%#", typedChar)) { AutoPopupController.getInstance(project).scheduleAutoPopup(editor); return Result.STOP; } return super.checkAutoPopup(typedChar, project, editor, file); } }
document.insertString(currentOffset, "::"); caretModel.moveToOffset(currentOffset + 2); AutoPopupController.getInstance(project).scheduleAutoPopup(editor); return Result.STOP;
AutoPopupController.getInstance(project).scheduleAutoPopup(editor); AutoPopupController.getInstance(project).scheduleAutoPopup(editor, CompletionType.BASIC, psiFile -> { PsiElement newElement = psiFile.findElementAt(offset); return PsiUtilCore.getElementType(newElement) == elementTokenType &&
PsiDocumentManager.getInstance(project).commitDocument(document); CodeStyleManager.getInstance(project).reformatText(file, reformatFrom, offset + 2); AutoPopupController.getInstance(project).scheduleAutoPopup(editor);