From f92efa83cd95d694578817a25015996eb5db2d1f Mon Sep 17 00:00:00 2001 From: l0ng-ai <24760907+l0ng-ai@users.noreply.github.com> Date: Tue, 24 Nov 2026 11:13:11 +0800 Subject: [PATCH] feat(workbench): keep rarely used tool windows off the stripe by default MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bookmarks and TODO are listed under the stripe's "…" until first opened. The Database window is on the stripe by default only while the project has data sources. Of the Flutter DevTools windows only Flutter Inspector has a stripe button; Deep Links, DevTools and DevTools Extensions wait under "…". A user's own stripe choice still wins. --- e2e/todo-layout.spec.ts | 4 +- src/features/database/index.ts | 51 ++++++++++++++--- src/features/database/toolWindow.test.ts | 56 +++++++++++++++++++ .../__tests__/flutterDevToolsWindows.test.tsx | 10 ++++ src/features/debugger/flutter/devTools.ts | 2 + src/features/search/index.ts | 1 + src/features/todo/index.ts | 1 + 7 files changed, 117 insertions(+), 8 deletions(-) create mode 100644 src/features/database/toolWindow.test.ts diff --git a/e2e/todo-layout.spec.ts b/e2e/todo-layout.spec.ts index 83cafcd0d3..1cbce726c0 100644 --- a/e2e/todo-layout.spec.ts +++ b/e2e/todo-layout.spec.ts @@ -5,8 +5,10 @@ test("keeps the file count visible beside a long directory in the TODO pane", as await page.evaluate(async () => { const projectModule = "/src/platform/project.ts"; const todoModule = "/src/features/todo/store.ts"; + const layoutModule = "/src/workbench/toolwindows/store.ts"; const { useProject } = await import(/* @vite-ignore */ projectModule); const { useTodos } = await import(/* @vite-ignore */ todoModule); + const { showToolWindow } = await import(/* @vite-ignore */ layoutModule); const directory = "src/features/checkout/shared/services/with-a-long-directory-name/for-order-processing"; const path = `${useProject.getState().project.root}/${directory}/orders.ts`; useTodos.setState({ @@ -14,9 +16,9 @@ test("keeps the file count visible beside a long directory in the TODO pane", as error: null, scanned: new Map([[path, [{ path, line: 8, col: 3, keyword: "TODO", text: "TODO: validate orders" }]]]), }); + showToolWindow("todo", true); }); - await page.getByRole("button", { name: "TODO" }).click(); const pane = page.locator('[data-toolwindow="todo"]'); const toolbar = pane.getByRole("toolbar", { name: "TODO actions" }); await expect(toolbar).toHaveAttribute("aria-orientation", "vertical"); diff --git a/src/features/database/index.ts b/src/features/database/index.ts index 2419dc64d0..30251cea8e 100644 --- a/src/features/database/index.ts +++ b/src/features/database/index.ts @@ -7,7 +7,7 @@ import { lazyComponent, lazyWhen, type MenuItem } from "@/ui"; import { activeEditor, lazyEditorExtension, registerEditorContribution } from "@/editor/api"; import { tx } from "@/platform/i18n"; -import { onIdeEvent } from "@/platform/ipc"; +import { call, commands, onIdeEvent } from "@/platform/ipc"; import { registerActions, type ActionContext } from "@/platform/actions"; import { activeCellGrid } from "./cellActions"; import { @@ -81,21 +81,58 @@ function tableTarget(arg: unknown): TableCommandTarget { return { rows: activeCellGrid()?.selectedRows() ?? [], editor: null }; } -export function activate(): () => void { - const disposers = [ - onIdeEvent("dbSourcesChanged", () => { - void loadSources(); - }), - registerToolWindow({ +/** The Database window, on the stripe by default only while the project has data sources. */ +function registerDatabaseWindow(): () => void { + let withSources: boolean | null = null; + let dispose = () => {}; + const sync = (next: boolean) => { + if (next === withSources) return; + withSources = next; + // Registering the same id again replaces the contribution in place. + dispose = registerToolWindow({ id: DB_TOOL_WINDOW, title: "Database", icon: "toolwindow-database", anchor: "right", order: 20, + ...(next ? {} : { stripe: "onUse" as const }), component: lazyComponent(() => import("./DatabaseView").then((m) => m.DatabaseView)), headerMenu: useDatabaseHeaderMenu, headerActions: lazyComponent(() => import("./DatabaseView").then((m) => m.DatabaseHeaderActions)), + }); + }; + // Until the window loads the sources, a quiet probe decides; a failed one leaves it under "…". + let probe = 0; + const check = () => { + const seq = ++probe; + sync(false); + if (!useProject.getState().project) return; + call(commands.dbSources()).then( + (sources) => seq === probe && !useDatabase.getState().loaded && sync(sources.length > 0), + () => {}, + ); + }; + check(); + const offSources = useDatabase.subscribe((s) => { + if (s.loaded) sync(s.sources.length > 0); + }); + const offProject = useProject.subscribe((s, prev) => { + if (s.project?.root !== prev.project?.root) check(); + }); + return () => { + probe++; + offSources(); + offProject(); + dispose(); + }; +} + +export function activate(): () => void { + const disposers = [ + onIdeEvent("dbSourcesChanged", () => { + void loadSources(); }), + registerDatabaseWindow(), registerServiceView({ id: RESULTS_VIEW, title: "Database", diff --git a/src/features/database/toolWindow.test.ts b/src/features/database/toolWindow.test.ts new file mode 100644 index 0000000000..75fd97298f --- /dev/null +++ b/src/features/database/toolWindow.test.ts @@ -0,0 +1,56 @@ +import { afterEach, describe, expect, it, vi } from "vitest"; +import { waitFor } from "@testing-library/react"; +import { useContributions } from "@/workbench/contributions"; +import { useProject } from "@/platform/project"; +import type { DataSource } from "@/platform/ipc"; + +const mocks = vi.hoisted(() => ({ sources: vi.fn(async (): Promise => []) })); + +vi.mock("@/platform/ipc", async (original) => { + const actual = await original(); + return { + ...actual, + commands: { ...actual.commands, dbSources: () => "dbSources" }, + call: (request: unknown) => (request === "dbSources" ? mocks.sources() : Promise.reject(new Error("unmocked"))), + }; +}); + +import { activate } from "./index"; +import { DB_TOOL_WINDOW, useDatabase } from "./store"; + +const stripe = () => useContributions.getState().toolWindows.get(DB_TOOL_WINDOW)?.stripe; + +describe("Database tool window", () => { + let dispose = () => {}; + afterEach(() => { + dispose(); + dispose = () => {}; + useProject.setState({ project: null }); + useDatabase.setState({ sources: [], loaded: false }); + }); + + it("is on the stripe by default only while there are data sources", () => { + dispose = activate(); + expect(stripe()).toBe("onUse"); + useDatabase.setState({ sources: [{ id: "pg" } as DataSource], loaded: true }); + expect(stripe()).toBeUndefined(); + useDatabase.setState({ sources: [] }); + expect(stripe()).toBe("onUse"); + dispose(); + dispose = () => {}; + expect(useContributions.getState().toolWindows.has(DB_TOOL_WINDOW)).toBe(false); + }); + + it("asks for the sources quietly when a project opens, before the window loads them", async () => { + dispose = activate(); + mocks.sources.mockResolvedValueOnce([{ id: "pg" }]); + useProject.setState({ project: { root: "/app" } as never }); + await waitFor(() => expect(stripe()).toBeUndefined()); + + mocks.sources.mockRejectedValueOnce(new Error("no backend")); + useProject.setState({ project: { root: "/other" } as never }); + await waitFor(() => expect(mocks.sources).toHaveBeenCalledTimes(2)); + expect(stripe()).toBe("onUse"); + expect(useDatabase.getState().loaded).toBe(false); + }); +}); diff --git a/src/features/debugger/__tests__/flutterDevToolsWindows.test.tsx b/src/features/debugger/__tests__/flutterDevToolsWindows.test.tsx index 6a5109dac0..8461286f54 100644 --- a/src/features/debugger/__tests__/flutterDevToolsWindows.test.tsx +++ b/src/features/debugger/__tests__/flutterDevToolsWindows.test.tsx @@ -76,6 +76,16 @@ describe("Flutter DevTools windows", () => { const dispose = registerDevToolsWindows(); await waitFor(() => expect(ids()).toEqual(expect.arrayContaining(DEVTOOLS_WINDOWS.map((w) => w.id)))); expect(getContext().flutterDevTools).toBe(true); + // One stripe button: the others wait under "…" until first opened. + const stripes = Object.fromEntries( + DEVTOOLS_WINDOWS.map((w) => [w.id, useContributions.getState().toolWindows.get(w.id)?.stripe]), + ); + expect(stripes).toEqual({ + "flutter-deep-links": "onUse", + "flutter-devtools": "onUse", + "flutter-devtools-extensions": "onUse", + "flutter-inspector": undefined, + }); useProject.setState({ project: { root: "/tool" } as never }); await waitFor(() => expect(ids()).not.toContain("flutter-inspector")); diff --git a/src/features/debugger/flutter/devTools.ts b/src/features/debugger/flutter/devTools.ts index 04f1db8820..2d109ff607 100644 --- a/src/features/debugger/flutter/devTools.ts +++ b/src/features/debugger/flutter/devTools.ts @@ -114,6 +114,8 @@ export function registerDevToolsWindows(): () => void { icon: w.icon, anchor: "right", order: 40 + i, + // Only the Inspector is on the stripe until the others are first opened. + ...(w.id === "flutter-inspector" ? {} : { stripe: "onUse" as const }), component: view("FlutterDevToolsView"), headerActions: view("FlutterDevToolsRefresh"), ...(w.app === "each" ? { headerContent: view("FlutterDevToolsTabs") } : {}), diff --git a/src/features/search/index.ts b/src/features/search/index.ts index 04fda8c97c..16c62c2192 100644 --- a/src/features/search/index.ts +++ b/src/features/search/index.ts @@ -218,6 +218,7 @@ export function activate(): void | (() => void) { anchor: "left", secondary: true, order: 30, + stripe: "onUse", component: lazyComponent(() => import("./bookmarks/BookmarksView").then((m) => m.BookmarksView)), headerActions: lazyComponent(() => import("./bookmarks/BookmarksView").then((m) => m.BookmarksActions)), useBadge: () => null, diff --git a/src/features/todo/index.ts b/src/features/todo/index.ts index f44c53c5ae..7cf9a9a09f 100644 --- a/src/features/todo/index.ts +++ b/src/features/todo/index.ts @@ -21,6 +21,7 @@ export function activate(): () => void { icon: hasIcon("toolwindow-todo") ? "toolwindow-todo" : "list", anchor: "bottom", order: 40, + stripe: "onUse", component: TodoView, headerContent: TodoTabs, headerMenu: useTodoHeaderMenu,