void (int offset, char completionChar, Environment env) { Project project = getProject(); Editor editor = FileEditorManager.getInstance(project).openTextEditor(new OpenFileDescriptor(project, getVirtualFile(), 0), true); assert editor != null; PsiDocumentManager.getInstance(project).commitAllDocuments(); editor.getCaretModel().moveToOffset(offset); CharSequence textBefore = editor.getDocument().getImmutableCharSequence(); MadTestingUtil.restrictChangesToDocument(editor.getDocument(), () -> { Disposable raiseCompletionLimit = Disposer.newDisposable(); Registry.get("ide.completion.variant.limit").setValue(100_000, raiseCompletionLimit); try { PsiTestUtil.checkPsiStructureWithCommit(getFile(), PsiTestUtil::checkStubsMatchText); Editor caretEditor = InjectedLanguageUtil.getEditorForInjectedLanguageNoCommit(editor, getFile()); performCompletion(caretEditor, Objects.requireNonNull(PsiUtilBase.getPsiFileInEditor(caretEditor, project)), completionChar, env); PsiTestUtil.checkPsiStructureWithCommit(getFile(), PsiTestUtil::checkStubsMatchText); } catch (Throwable e) { LOG.debug("Text before completion:\n" + textBefore); env.logMessage("Error happened, the file's text before invoking printed to the debug log, search for 'Text before completion' there"); throw e; } finally { Disposer.dispose(raiseCompletionLimit); LookupManager.getInstance(project).hideActiveLookup(); UIUtil.dispatchAllInvocationEvents(); } }); }