下面列出了怎么用 com.intellij.codeInsight.completion.CompletionPhase 的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public void scheduleAutoPopup(@Nonnull Editor editor, @Nonnull CompletionType completionType, @Nullable final Condition<? super PsiFile> condition) {
//if (ApplicationManager.getApplication().isUnitTestMode() && !TestModeFlags.is(CompletionAutoPopupHandler.ourTestingAutopopup)) {
// return;
//}
boolean alwaysAutoPopup = Boolean.TRUE.equals(editor.getUserData(ALWAYS_AUTO_POPUP));
if (!CodeInsightSettings.getInstance().AUTO_POPUP_COMPLETION_LOOKUP && !alwaysAutoPopup) {
return;
}
if (PowerSaveMode.isEnabled()) {
return;
}
if (!CompletionServiceImpl.isPhase(CompletionPhase.CommittingDocuments.class, CompletionPhase.NoCompletion.getClass())) {
return;
}
final CompletionProgressIndicator currentCompletion = CompletionServiceImpl.getCurrentCompletionProgressIndicator();
if (currentCompletion != null) {
currentCompletion.closeAndFinish(true);
}
CompletionPhase.CommittingDocuments.scheduleAsyncCompletion(editor, completionType, condition, myProject, null);
}
/**
* PhpTypedHandler.scheduleAutoPopup but use SMART since BASIC is blocked
*/
public void scheduleAutoPopup(final Project project, final Editor editor, @Nullable final Condition<PsiFile> condition) {
if (ApplicationManager.getApplication().isUnitTestMode()/* && !CompletionAutoPopupHandler.ourTestingAutopopup*/) {
return;
}
if (!CodeInsightSettings.getInstance().AUTO_POPUP_COMPLETION_LOOKUP) {
return;
}
if (PowerSaveMode.isEnabled()) {
return;
}
if (!CompletionServiceImpl.isPhase(CompletionPhase.CommittingDocuments.class, CompletionPhase.NoCompletion.getClass())) {
return;
}
//
// final CompletionProgressIndicator currentCompletion = CompletionServiceImpl.getCompletionService().getCurrentCompletion();
// if (currentCompletion != null) {
// currentCompletion.closeAndFinish(true);
// }
//
// final CompletionPhase.CommittingDocuments phase = new CompletionPhase.CommittingDocuments(null, editor);
// CompletionServiceImpl.setCompletionPhase(phase);
//
// CompletionAutoPopupHandler.runLaterWithCommitted(project, editor.getDocument(), new Runnable() {
// @Override
// public void run() {
// CompletionAutoPopupHandler.invokeCompletion(CompletionType.BASIC, true, project, editor, 0, false);
// }
// });
}
@Override
public void execute(@Nonnull Editor originalEditor, char charTyped, @Nonnull DataContext dataContext) {
final Project project = dataContext.getData(CommonDataKeys.PROJECT);
PsiFile file = project == null ? null : PsiUtilBase.getPsiFileInEditor(originalEditor, project);
if (file == null) {
if (myOriginalHandler != null) {
myOriginalHandler.execute(originalEditor, charTyped, dataContext);
}
return;
}
if (!EditorModificationUtil.checkModificationAllowed(originalEditor)) {
return;
}
CompletionPhase oldPhase = CompletionServiceImpl.getCompletionPhase();
if (oldPhase instanceof CompletionPhase.CommittingDocuments && oldPhase.indicator != null) {
oldPhase.indicator.scheduleRestart();
}
Editor editor = TypedHandler.injectedEditorIfCharTypedIsSignificant(charTyped, originalEditor, file);
if (editor != originalEditor) {
file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
}
if (originalEditor.isInsertMode() && beforeCharTyped(charTyped, project, originalEditor, editor, file)) {
return;
}
if (myOriginalHandler != null) {
myOriginalHandler.execute(originalEditor, charTyped, dataContext);
}
}