From 49e26d1de17c1880dfed618bc6435c1167ca0517 Mon Sep 17 00:00:00 2001
From: audichuang <72485427+audichuang@users.noreply.github.com>
Date: Fri, 4 Dec 2026 22:10:49 +0800
Subject: [PATCH] fix(code-insight): hide the usage count while Show Usages is
still searching with nothing found (#8041)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Show Usages opens 300 ms into a slow search, before anything is found, and its header then read "0 found" as if the search had finished empty. The count is hidden while the search runs with no results; the header spinner and "Searching for usages…" show progress, and the count appears once usages arrive or the search ends.
Refs #6823
Co-authored-by: audichuang <72485427+audichuang@users.noreply.github.com>
---
src/features/code-insight/UsagesPopup.tsx | 8 +++++---
src/features/code-insight/usagesPopup.test.tsx | 18 ++++++++++++++++++
2 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/src/features/code-insight/UsagesPopup.tsx b/src/features/code-insight/UsagesPopup.tsx
index 931a76d4af..2e323fd430 100644
--- a/src/features/code-insight/UsagesPopup.tsx
+++ b/src/features/code-insight/UsagesPopup.tsx
@@ -228,9 +228,11 @@ function UsagesPopupInner() {
{symbol ? tx`Usages of ${symbol}` : tx("Usages")}{" "}
-
- {filter || items.length !== total ? tx`${items.length} of ${total} found` : tx`${total} found`}
-
+ {(total > 0 || !loading) && (
+
+ {filter || items.length !== total ? tx`${items.length} of ${total} found` : tx`${total} found`}
+
+ )}
diff --git a/src/features/code-insight/usagesPopup.test.tsx b/src/features/code-insight/usagesPopup.test.tsx
index 5b528ab1bd..e2a5d16e6f 100644
--- a/src/features/code-insight/usagesPopup.test.tsx
+++ b/src/features/code-insight/usagesPopup.test.tsx
@@ -362,6 +362,7 @@ it("opens while a slow search has found nothing yet, and closes when it ends wit
await act(() => new Promise((r) => setTimeout(r, 350)));
expect(useUsagesPopup.getState()).toMatchObject({ open: true, loading: true, groups: [] });
expect(screen.getByText("Searching for usages…")).toBeInTheDocument();
+ expect(screen.queryByText("0 found")).not.toBeInTheDocument();
await act(async () => {
resolve({ locations, incomplete: null });
await pending;
@@ -385,6 +386,23 @@ it("opens while a slow search has found nothing yet, and closes when it ends wit
expect(calls.slice(before)).toEqual(["hint No usages of 'used' found"]);
});
+it("shows the count once a search in the open popup ends with none", async () => {
+ render();
+ const at = (line: number) => ({ ...loc, range: { start: { line, col: 4 }, end: { line, col: 8 } } });
+ referenceResponse.mockResolvedValueOnce({ locations: [], incomplete: null, librariesSkipped: true });
+ await showUsagesPopup();
+ referenceResponse.mockResolvedValueOnce({ locations: [at(1), at(2)], incomplete: null });
+ await act(() => showUsagesPopup());
+ expect(useUsagesPopup.getState()).toMatchObject({ open: true, scope: "libraries" });
+ expect(screen.getByText("2 found")).toBeInTheDocument();
+ referenceResponse.mockResolvedValueOnce({ locations: [], incomplete: null, librariesSkipped: true });
+ await act(async () => setUsagesPopupScope("project"));
+ await vi.waitFor(() => expect(useUsagesPopup.getState()).toMatchObject({ loading: false, scope: "project" }));
+ expect(useUsagesPopup.getState().open).toBe(true);
+ expect(screen.getByText("0 found")).toBeInTheDocument();
+ act(() => dismissUsagesPopup());
+});
+
it("searches Project Files, and Project and Libraries when invoked again", async () => {
render();
const at = (line: number) => ({ ...loc, range: { start: { line, col: 4 }, end: { line, col: 8 } } });