void (Project project, String typingText, Semaphore typingSemaphore) { SearchEverywhereUI ui = SearchEverywhereManager.getInstance(project).getCurrentlyShownUI(); Document document = ui.getSearchField().getDocument(); Semaphore oneLetterLock = new Semaphore(1); ThreadPoolExecutor typing = ConcurrencyUtil.newSingleThreadExecutor("Performance plugin delayed type"); Ref<Boolean> isTypingFinished = new Ref<>(false); Ref<Span> oneLetterSpan = new Ref<>(); Ref<Span> firstBatchAddedSpan = new Ref<>(); ui.addSearchListener(new SearchAdapter() { @Override public void elementsAdded(@NotNull List<? extends SearchEverywhereFoundElementInfo> list) { firstBatchAddedSpan.get().setAttribute("number", list.size()); firstBatchAddedSpan.get().end(); } @Override public void searchFinished(@NotNull List<Object> items) { super.searchFinished(items); oneLetterLock.release(); oneLetterSpan.get().setAttribute("number", items.size()); oneLetterSpan.get().end(); if (isTypingFinished.get()) { typingSemaphore.release(); typing.shutdown(); } } }); for (int i = 0; i < typingText.length(); i++) { final int index = i; typing.execute(Context.current().wrap(() -> { try { oneLetterLock.acquire(); } catch (InterruptedException e) { throw new RuntimeException(e); } ApplicationManager.getApplication().invokeAndWait(Context.current().wrap(() -> { try { char currentChar = typingText.charAt(index); oneLetterSpan.set( PerformanceTestSpan.TRACER.spanBuilder("searchEverywhere_items_loaded").startSpan() .setAttribute("text", String.valueOf(currentChar))); firstBatchAddedSpan.set(PerformanceTestSpan.TRACER.spanBuilder("searchEverywhere_first_elements_added").startSpan()); document.insertString(document.getLength(), String.valueOf(currentChar), null); if (index == typingText.length() - 1) { isTypingFinished.set(true); } } catch (BadLocationException e) { throw new RuntimeException(e); } })); })); } }