void (CompletionInitializationContext initContext, CompletionParameters parameters) { PsiUtilCore.ensureValid(parameters.getPosition()); if (isAutopopupCompletion() && shouldPreselectFirstSuggestion(parameters)) { LookupFocusDegree degree = CodeInsightSettings.getInstance().isSelectAutopopupSuggestionsByChars() ? LookupFocusDegree.FOCUSED : LookupFocusDegree.SEMI_FOCUSED; myLookup.setLookupFocusDegree(degree); } addDefaultAdvertisements(parameters); ProgressManager.checkCanceled(); Document document = initContext.getEditor().getDocument(); if (!initContext.getOffsetMap().wasModified(CompletionInitializationContext.IDENTIFIER_END_OFFSET)) { try { final int selectionEndOffset = initContext.getSelectionEndOffset(); final PsiReference reference = TargetElementUtil.findReference(myEditor, selectionEndOffset); if (reference != null) { final int replacementOffset = findReplacementOffset(selectionEndOffset, reference); if (replacementOffset > document.getTextLength()) { LOG.error("Invalid replacementOffset: " + replacementOffset + " returned by reference " + reference + " of " + reference.getClass() + "; doc=" + document + "; doc actual=" + (document == initContext.getFile().getViewProvider().getDocument()) + "; doc committed=" + PsiDocumentManager.getInstance(getProject()).isCommitted(document)); } else { initContext.setReplacementOffset(replacementOffset); } } } catch (IndexNotReadyException ignored) { } } DumbModeAccessType.RELIABLE_DATA_ONLY.ignoreDumbMode(() -> { for (CompletionContributor contributor : CompletionContributor.forLanguageHonorDumbness(initContext.getPositionLanguage(), initContext.getProject())) { ProgressManager.checkCanceled(); contributor.duringCompletion(initContext); } }); if (document instanceof DocumentWindow) { myHostOffsets = new OffsetsInFile(initContext.getFile(), initContext.getOffsetMap()).toTopLevelFile(); } }