/** * Handles QuickFix action invoked on {@link IgnoreSyntax}. * * @param project the {@link Project} containing the working file * @param file the {@link PsiFile} containing handled entry * @param startElement the {@link IgnoreSyntax} that will be selected and replaced * @param endElement the {@link PsiElement} which is ignored in invoked action */ @Override public void invoke(@NotNull Project project, @NotNull PsiFile file, @Nullable("is null when called from inspection") Editor editor, @NotNull PsiElement startElement, @NotNull PsiElement endElement) { if (startElement instanceof IgnoreSyntax) { PsiElement value = ((IgnoreSyntax) startElement).getValue(); if (editor != null) { editor.getSelectionModel().setSelection( value.getTextOffset(), value.getTextOffset() + value.getTextLength() ); } new CodeCompletionHandlerBase(CompletionType.BASIC).invokeCompletion(project, editor); } }
@Override public void handleInsert(@NotNull final InsertionContext context, @NotNull LookupElement item) { final Editor editor = context.getEditor(); if ("returns".equals(item.getLookupString())) { EditorModificationUtil.insertStringAtCaret(editor, " "); context.setLaterRunnable(() -> new CodeCompletionHandlerBase(CompletionType.BASIC).invokeCompletion(context.getProject(), editor, 1)); } } }
@Override public void handleInsert(@NotNull final InsertionContext context, @NotNull final LookupElement item) { // fixme this is bad check for auto-inserting, i belive if (context.getCompletionChar() != '\u0000') { context.setLaterRunnable(() -> { Editor editor = context.getEditor(); new CodeCompletionHandlerBase(CompletionType.BASIC).invokeCompletion(context.getProject(), editor, 1); }); } } }
@Override public void run() { //当前文件是否最新,没有未提交的 if (PsiDocumentManager.getInstance(project).isCommitted(editor.getDocument())) { //唤醒代码自动补全 , CompletionContributor new CodeCompletionHandlerBase(CompletionType.BASIC).invokeCompletion(project, editor, 1); } } });