Promise<Object> (final @NotNull PlaybackContext context) { final ActionCallback actionCallback = new ActionCallbackProfilerStopper(); Project project = context.getProject(); String[] args = getArgs(); final String tab = myOptions.tab; final String insertText = args.length > 1 ? args[1] : ""; Ref<String> tabId = new Ref<>(); switch (tab) { case "text" -> tabId.set(TextSearchContributor.class.getSimpleName()); case "file" -> tabId.set(FileSearchEverywhereContributor.class.getSimpleName()); case "class" -> tabId.set(ClassSearchEverywhereContributor.class.getSimpleName()); case "action" -> tabId.set(ActionSearchEverywhereContributor.class.getSimpleName()); case "symbol" -> tabId.set(SymbolSearchEverywhereContributor.class.getSimpleName()); case "all" -> tabId.set(SearchEverywhereManagerImpl.ALL_CONTRIBUTORS_GROUP_ID); default -> throw new RuntimeException("Tab is not set"); } LOG.info(tabId.get()); int numberOfPermits; if(insertText.isEmpty() && myOptions.typingText.isEmpty()){ numberOfPermits = 1; //we don't wait for any text insertion } else if(!insertText.isEmpty() && !myOptions.typingText.isEmpty()){ numberOfPermits = -1; //we wait till both operations are finished } else { numberOfPermits = 0; //we wait till one operation is finished } Semaphore typingSemaphore = new Semaphore(numberOfPermits); TraceUtil.runWithSpanThrows(PerformanceTestSpan.TRACER, "searchEverywhere", globalSpan -> { ApplicationManager.getApplication().invokeAndWait(Context.current().wrap(() -> { try { TypingTarget target = findTarget(context); Component component; if(!(target instanceof EditorComponentImpl)){ LOG.info("Editor is not opened, focus owner will be used."); component = IdeFocusManager.getInstance(project).getFocusOwner(); } else{ component = (EditorComponentImpl) target; } DataContext dataContext = DataManager.getInstance().getDataContext(component); IdeEventQueue.getInstance().getPopupManager().closeAllPopups(false); AnActionEvent actionEvent = AnActionEvent.createFromDataContext(ActionPlaces.EDITOR_POPUP, null, dataContext); if(actionEvent.getProject() == null && !(tab.equals("action") || tab.equals("all"))) { actionCallback.reject("Project is null, SE requires project to show any tab except actions."); } TraceUtil.runWithSpanThrows(PerformanceTestSpan.TRACER, "searchEverywhere_dialog_shown", dialogSpan -> { var manager = SearchEverywhereManager.getInstance(project); manager.show(tabId.get(), "", actionEvent); attachSearchListeners(manager.getCurrentlyShownUI()); }); if (!insertText.isEmpty()) { insertText(context.getProject(), insertText, typingSemaphore); } if (!myOptions.typingText.isEmpty()) { typeText(context.getProject(), myOptions.typingText, typingSemaphore); } } catch (Exception e) { LOG.error(e); } })); try { typingSemaphore.acquire(); SearchEverywhereUI ui = SearchEverywhereManager.getInstance(project).getCurrentlyShownUI(); if (myOptions.close) { ApplicationManager.getApplication().invokeAndWait(() -> ui.closePopup()); } if (myOptions.selectFirst) { WriteAction.runAndWait(() -> { ApplicationManager.getApplication().invokeAndWait(() -> ui.selectFirst()); }); } } catch (InterruptedException e) { LOG.error(e); } finally { actionCallback.setDone(); } }); return Promises.toPromise(actionCallback); }