From 4e82599c49f4a5228dd41367f766b021d15b42fb Mon Sep 17 00:00:00 2001 From: Vadim Lazuk Date: Fri, 27 Nov 2026 22:26:26 +0300 Subject: [PATCH] feat(dotnet): show solution tree discovery states (#6566) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit While the .NET workspace scan runs, or after it failed, the Project view showed nothing where the solutions would appear. One placeholder .NET root now carries the state as grey detail text (Scanning… / Scan failed); idle and empty still registers no root, and a failed scan still retries on next use. Refs #5635 Co-authored-by: Inf1mum <8135225+Inf1mum@users.noreply.github.com> --- src/features/dotnet/tree.test.ts | 63 +++++++++++++++++++++++++++++++ src/features/dotnet/tree.ts | 49 +++++++++++++++++++++--- src/platform/locales/text/zh.json | 2 + 3 files changed, 108 insertions(+), 6 deletions(-) diff --git a/src/features/dotnet/tree.test.ts b/src/features/dotnet/tree.test.ts index e871402743..8d3593e541 100644 --- a/src/features/dotnet/tree.test.ts +++ b/src/features/dotnet/tree.test.ts @@ -137,6 +137,69 @@ describe("the .NET solution tree", () => { dispose = activateTree(); await vi.waitFor(() => expect(useDotnet.getState().busy).toBe(false)); expect(dotnetRoots()).toEqual([]); + // Idle and empty also means no state placeholder: the root hides entirely. + expect(useProjectViewRoots.getState().roots.get("dotnetDiscovery")).toBeUndefined(); + }); + + it("shows a scanning placeholder while the shared scan runs", async () => { + indexed(["/repo/App.sln"]); + let resolveScan!: (model: platform.DotnetWorkspace) => void; + vi.spyOn(platform, "dotnetWorkspace").mockImplementation( + () => new Promise((resolve) => (resolveScan = resolve)), + ); + dispose = activateTree(); + await gateChecked(); + // The model is still loading: one placeholder root carries the state as grey detail text. + await vi.waitFor(() => expect(useDotnet.getState().busy).toBe(true)); + const loading = useProjectViewRoots.getState().roots.get("dotnetDiscovery")!; + expect([loading.label, loading.detail, loading.beforeProject]).toEqual([".NET", "Scanning…", true]); + expect(loading.children).toBeUndefined(); + // Once the scan lands, the placeholder gives way to the discovered roots. + resolveScan({ + projects: [project("/repo/src/App/App.csproj", "App")], + solutions: [{ path: "/repo/App.sln", projects: ["/repo/src/App/App.csproj"] }], + }); + await vi.waitFor(() => expect(rootIds()).toContain("dotnetSolution:/repo/App.sln")); + expect(useProjectViewRoots.getState().roots.get("dotnetDiscovery")).toBeUndefined(); + }); + + it("shows a scan-failed placeholder when discovery fails", async () => { + indexed(["/repo/App.sln"]); + const scan = vi.spyOn(platform, "dotnetWorkspace").mockRejectedValue(new Error("dotnet not found")); + dispose = activateTree(); + // The failure shows where discovery lives; the store's retry-on-next-use behaviour is untouched. + await vi.waitFor(() => { + const failed = useProjectViewRoots.getState().roots.get("dotnetDiscovery"); + expect([failed?.label, failed?.detail]).toEqual([".NET", "Scan failed"]); + }); + expect(useDotnet.getState().busy).toBe(false); + // A retry (a context action or the NuGet window calling the shared scan) replaces it. + scan.mockResolvedValue({ + projects: [project("/repo/App/App.csproj", "App")], + solutions: [], + }); + await reloadDotnet(); + await vi.waitFor(() => expect(rootIds()).toContain("dotnetProject:/repo/App/App.csproj")); + expect(useProjectViewRoots.getState().roots.get("dotnetDiscovery")).toBeUndefined(); + }); + + it("shows the state text through the tx template", async () => { + await setLocale("zh"); + indexed(["/repo/App.sln"]); + let settleScan!: (model: platform.DotnetWorkspace | Error) => void; + vi.spyOn(platform, "dotnetWorkspace").mockImplementation( + () => + new Promise((resolve, reject) => { + settleScan = (model) => (model instanceof Error ? reject(model) : resolve(model)); + }), + ); + dispose = activateTree(); + await vi.waitFor(() => expect(useDotnet.getState().busy).toBe(true)); + expect(useProjectViewRoots.getState().roots.get("dotnetDiscovery")!.detail).toBe("正在扫描…"); + settleScan(new Error("boom")); + await vi.waitFor(() => + expect(useProjectViewRoots.getState().roots.get("dotnetDiscovery")!.detail).toBe("扫描失败"), + ); }); it("does not scan a workspace whose index holds no .NET files", async () => { diff --git a/src/features/dotnet/tree.ts b/src/features/dotnet/tree.ts index 5e9c797ae8..b39a273e22 100644 --- a/src/features/dotnet/tree.ts +++ b/src/features/dotnet/tree.ts @@ -7,8 +7,9 @@ * roots re-register in place on change (as External Libraries does) and nothing * registers while the model is empty. The scan starts only when the file index * shows .NET files (a cheap index lookup, retried once indexing finishes), so a - * workspace without .NET pays nothing on open. Discovery states (loading / - * empty / failure) are the second slice of #5635. + * workspace without .NET pays nothing on open. Discovery states (#5635 item 4) + * ride on one placeholder root's grey detail text — scanning while the shared + * scan runs, the failure after it failed; idle and empty means no root at all. */ import type { DotnetWorkspace } from "@/platform/dotnet"; import { tx } from "@/platform/i18n"; @@ -47,9 +48,45 @@ async function dotnetCandidates(): Promise { ); } -/** One group per solution (a leaf per project), standalone projects as roots of their own. */ -export function treeRoots(model: DotnetWorkspace): ProjectViewRootContribution[] { - if (!model.projects.length && !model.solutions.length) return []; +/** + * The placeholder root a discovery state (#5635 item 4) rides on: `.NET` above + * the project folder, the state as grey detail text — a group node, so nothing + * context-menu or selection related fires on it. + */ +const stateRoot = (detail: string): ProjectViewRootContribution => ({ + id: "dotnetDiscovery", + label: ".NET", + icon: ICON, + beforeProject: true, + order: -200, + detail, +}); + +/** + * One group per solution (a leaf per project), standalone projects as roots of + * their own. With the model still empty, the one placeholder root carries the + * discovery state (#5635 item 4) as grey detail text — scanning while the + * shared scan runs, the failure after it failed, so it shows where the + * discovered solutions will live. Idle and empty means no root at all: no + * spinner (none exists in `ui/icons`), no empty-state node — the NuGet window + * stays the explicit empty surface. A failed scan keeps the store's + * retry-on-next-use behaviour: the next scan (a context action, the NuGet + * window, a reopened project) replaces the placeholder. + */ +export function treeRoots({ + model, + busy, + error, +}: { + model: DotnetWorkspace; + busy: boolean; + error: string; +}): ProjectViewRootContribution[] { + if (!model.projects.length && !model.solutions.length) { + if (busy) return [stateRoot(tx`Scanning…`)]; + if (error) return [stateRoot(tx`Scan failed`)]; + return []; + } const projectName = (path: string) => model.projects.find((p) => p.path === path)?.name ?? solutionName(path); const leaf = (path: string) => ({ label: projectName(path), icon: ICON, path, file: true }); const grouped = new Set(model.solutions.flatMap((s) => s.projects)); @@ -91,7 +128,7 @@ export function activateTree(): () => void { prev.reverse().forEach((d) => d()); }; const sync = () => { - const roots = treeRoots(useDotnet.getState().model); + const roots = treeRoots(useDotnet.getState()); const key = JSON.stringify(roots); if (key === shown) return; shown = key; diff --git a/src/platform/locales/text/zh.json b/src/platform/locales/text/zh.json index 780fe48dc4..8226506329 100644 --- a/src/platform/locales/text/zh.json +++ b/src/platform/locales/text/zh.json @@ -8824,6 +8824,8 @@ "As in Visual Studio: the solution file at the top, the project in its own folder.": "与 Visual Studio 相同:解决方案文件在顶层,项目放在单独的文件夹中。", "Solution name:": "解决方案名称:", "Solution '{name}'": "解决方案 '{name}'", + "Scanning…": "正在扫描…", + "Scan failed": "扫描失败", "Creating the solution": "正在创建解决方案", "Adding the project to the solution": "正在将项目添加到解决方案", "An Elixir project from mix new.": "用 mix new 创建的 Elixir 项目。",