void (final CompletionProgressIndicator indicator, boolean hasModifiers) { List<LookupElement> items = indicator.getLookup().getItems(); if (items.isEmpty()) { LookupManager.hideActiveLookup(indicator.getProject()); Caret nextCaret = getNextCaretToProcess(indicator.getEditor()); if (nextCaret != null) { invokeCompletionWithTracing(indicator.getProject(), indicator.getEditor(), indicator.getInvocationCount(), hasModifiers, nextCaret); } else { indicator.handleEmptyLookup(true); checkNotSync(indicator, items); } return; } LOG.assertTrue(!indicator.isRunning(), "running"); LOG.assertTrue(!indicator.isCanceled(), "canceled"); try { CompletionParameters parameters = indicator.getParameters(); AutoCompletionDecision decision = parameters == null ? AutoCompletionDecision.CLOSE_LOOKUP : shouldAutoComplete(indicator, items, parameters); if (decision == AutoCompletionDecision.SHOW_LOOKUP) { indicator.getLookup().setCalculating(false); indicator.showLookup(); CompletionServiceImpl.setCompletionPhase(new CompletionPhase.ItemsCalculated(indicator)); } else if (decision instanceof AutoCompletionDecision.InsertItem) { final Runnable restorePrefix = rememberDocumentState(indicator.getEditor()); final LookupElement item = ((AutoCompletionDecision.InsertItem)decision).getElement(); CommandProcessor.getInstance().executeCommand(indicator.getProject(), () -> { indicator.setMergeCommand(); indicator.getLookup().finishLookup(Lookup.AUTO_INSERT_SELECT_CHAR, item); }, CodeInsightBundle.message("completion.automatic.command.name"), null); // the insert handler may have started a live template with completion if (CompletionService.getCompletionService().getCurrentCompletion() == null && // ...or scheduled another autopopup !CompletionServiceImpl.isPhase(CompletionPhase.CommittingDocuments.class)) { CompletionServiceImpl.setCompletionPhase(hasModifiers? new CompletionPhase.InsertedSingleItem(indicator, restorePrefix) : CompletionPhase.NoCompletion); } } else if (decision == AutoCompletionDecision.CLOSE_LOOKUP) { LookupManager.hideActiveLookup(indicator.getProject()); } } catch (Throwable e) { CompletionServiceImpl.setCompletionPhase(CompletionPhase.NoCompletion); LOG.error(e); } finally { checkNotSync(indicator, items); } }