diff --git a/e2e/dotnetDependencies.spec.ts b/e2e/dotnetDependencies.spec.ts
index 38ce4e75e8..f4466e2af4 100644
--- a/e2e/dotnetDependencies.spec.ts
+++ b/e2e/dotnetDependencies.spec.ts
@@ -67,7 +67,11 @@ test("a project lists its packages, projects, frameworks and analyzers under Dep
// Core has no dependencies: no node.
await expect(tree.getByRole("treeitem", { name: "Dependencies" })).toHaveCount(1);
if (SHOTS) await page.screenshot({ path: `${SHOTS}/b2-dependencies.png`, animations: "disabled" });
+ // The project node lists the project's folder; its project file opens from the context menu.
const editorTabs = page.getByRole("tablist", { name: "Editor tabs" }).getByRole("tab");
+ await expect(editorTabs).toHaveCount(0);
+ await app.click({ button: "right" });
+ await page.getByRole("menuitem", { name: "Edit 'App.csproj'" }).click();
await expect(editorTabs).toHaveText(["App.csproj"]);
await tree.getByRole("treeitem", { name: /Newtonsoft\.Json/ }).dblclick();
await expect(editorTabs).toHaveText(["App.csproj"]);
diff --git a/src/features/dotnet/edit.test.ts b/src/features/dotnet/edit.test.ts
index ed4bf11450..c0990ca080 100644
--- a/src/features/dotnet/edit.test.ts
+++ b/src/features/dotnet/edit.test.ts
@@ -292,9 +292,12 @@ describe("Project view menu items", () => {
expect(items).toContainEqual(expect.objectContaining({ action: "dotnet.project.addReference" }));
});
- it("a project without references or solutions offers only Add Project Reference", () => {
+ it("a project without references or solutions offers only Edit and Add Project Reference", () => {
const items = editItems("/s/B/B.csproj");
expect(items.some((i) => "submenu" in i)).toBe(false);
- expect(items.filter((i) => "action" in i)).toHaveLength(1);
+ expect(items.flatMap((i) => ("action" in i ? [i.action] : []))).toEqual([
+ "dotnet.project.editFile",
+ "dotnet.project.addReference",
+ ]);
});
});
diff --git a/src/features/dotnet/edit.ts b/src/features/dotnet/edit.ts
index af7cf68d4b..7c14deb046 100644
--- a/src/features/dotnet/edit.ts
+++ b/src/features/dotnet/edit.ts
@@ -169,6 +169,14 @@ export function editItems(path: string): MenuItem[] {
const references = model.projects.find((p) => p.path === path)?.references ?? [];
return [
{ kind: "separator" },
+ // The project node lists the project's folder: its project file opens from here.
+ {
+ kind: "action",
+ action: "dotnet.project.editFile",
+ arg: path,
+ label: tx`Edit '${basename(path)}'`,
+ verbatim: true,
+ },
{ kind: "action", action: "dotnet.project.addReference", arg: { project: path }, label: "Add Project Reference…" },
...(references.length
? [
diff --git a/src/features/dotnet/index.ts b/src/features/dotnet/index.ts
index d0f239d6c2..6f12294799 100644
--- a/src/features/dotnet/index.ts
+++ b/src/features/dotnet/index.ts
@@ -2,7 +2,12 @@ import { executeAction, registerActions } from "@/platform/actions";
import { useProject } from "@/platform/project";
import { lazyComponent } from "@/ui";
import type { MenuItem } from "@/ui/Menu";
-import { registerMenuGroup, registerToolWindow, toolWindowService } from "@/workbench/contributions";
+import {
+ maybeEditorService,
+ registerMenuGroup,
+ registerToolWindow,
+ toolWindowService,
+} from "@/workbench/contributions";
import {
useDotnet,
buildDotnet,
@@ -89,6 +94,15 @@ export function activate() {
return removeProjectFromSolution(a.solution, a.project);
},
},
+ {
+ id: "dotnet.project.editFile",
+ title: "Edit Project File",
+ category: "File",
+ hidden: true,
+ run: async ({ arg }) => {
+ if (typeof arg === "string") await maybeEditorService()?.openFile(arg, { focus: true });
+ },
+ },
{
id: "dotnet.project.addReference",
title: "Add Project Reference",
diff --git a/src/features/dotnet/tree.test.ts b/src/features/dotnet/tree.test.ts
index 94cf5cf708..70db0b8b72 100644
--- a/src/features/dotnet/tree.test.ts
+++ b/src/features/dotnet/tree.test.ts
@@ -75,7 +75,7 @@ describe("the .NET solution tree", () => {
const dotnetRoots = () =>
rootIds().filter((id) => id.startsWith("dotnetSolution:") || id.startsWith("dotnetProject:"));
- it("registers one solution group per solution with a leaf per project", async () => {
+ it("registers one solution group per solution with a project folder node per project", async () => {
indexed(["/repo/App.sln"]);
const scan = vi.spyOn(platform, "dotnetWorkspace").mockResolvedValue({
projects: [
@@ -95,9 +95,9 @@ describe("the .NET solution tree", () => {
expect(scan).toHaveBeenCalledTimes(1);
const solution = useProjectViewRoots.getState().roots.get("dotnetSolution:/repo/App.sln")!;
expect([solution.label, solution.icon, solution.beforeProject]).toEqual(["Solution 'App'", "project-dotnet", true]);
- expect(solution.children?.map((c) => [c.label, c.path, c.file])).toEqual([
- ["App", "/repo/src/App/App.csproj", true],
- ["App.Tests", "/repo/tests/App.Tests/App.Tests.csproj", true],
+ expect(solution.children?.map((c) => [c.label, c.path, c.menuPath, c.file, c.excludeNames])).toEqual([
+ ["App", "/repo/src/App", "/repo/src/App/App.csproj", undefined, ["bin", "obj"]],
+ ["App.Tests", "/repo/tests/App.Tests", "/repo/tests/App.Tests/App.Tests.csproj", undefined, ["bin", "obj"]],
]);
// The group node's context menu is its `.sln`'s (#7421).
expect(solution.menuPath).toBe("/repo/App.sln");
@@ -150,20 +150,20 @@ describe("the .NET solution tree", () => {
});
dispose = activateTree();
await vi.waitFor(() => expect(dotnetRoots()).toHaveLength(1));
- type Shape = { label: string; file?: boolean; children?: readonly Shape[] };
+ type Shape = { label: string; file?: boolean; path?: string; children?: readonly Shape[] };
const shape = (e: Shape): unknown =>
- e.children ? [e.label, e.children.map(shape)] : [e.label, e.file ? "file" : "node"];
+ e.children ? [e.label, e.children.map(shape)] : [e.label, e.file ? "file" : e.path ? "dir" : "node"];
const solution = useProjectViewRoots.getState().roots.get("dotnetSolution:/repo/App.sln")!;
expect(solution.children!.map(shape)).toEqual([
[
"src",
[
- ["libs", [["Core", "file"]]],
+ ["libs", [["Core", "dir"]]],
["README.md", "file"],
],
],
["empty", []],
- ["App", "file"],
+ ["App", "dir"],
]);
});
@@ -191,7 +191,7 @@ describe("the .NET solution tree", () => {
expect(useProjectViewRoots.getState().roots.get("dotnetSolution:/repo/App.sln")!.label).toBe("解决方案 'App'");
});
- it("registers standalone projects as file roots of their own", async () => {
+ it("registers standalone projects as project folder roots of their own", async () => {
indexed(["/repo/App.csproj"]);
vi.spyOn(platform, "dotnetWorkspace").mockResolvedValue({
projects: [project("/repo/App.csproj", "App")],
@@ -200,7 +200,14 @@ describe("the .NET solution tree", () => {
dispose = activateTree();
await vi.waitFor(() => expect(rootIds()).toContain("dotnetProject:/repo/App.csproj"));
const alone = useProjectViewRoots.getState().roots.get("dotnetProject:/repo/App.csproj")!;
- expect([alone.label, alone.path, alone.file, alone.beforeProject]).toEqual(["App", "/repo/App.csproj", true, true]);
+ expect([alone.label, alone.path, alone.menuPath, alone.file, alone.beforeProject, alone.excludeNames]).toEqual([
+ "App",
+ "/repo",
+ "/repo/App.csproj",
+ undefined,
+ true,
+ ["bin", "obj"],
+ ]);
expect(alone.children).toBeUndefined();
});
diff --git a/src/features/dotnet/tree.ts b/src/features/dotnet/tree.ts
index a402cc36ab..1b3cea4f3b 100644
--- a/src/features/dotnet/tree.ts
+++ b/src/features/dotnet/tree.ts
@@ -25,6 +25,7 @@ import { ensureDotnetModel, useDotnet } from "./store";
import { isDotnetProjectPath, isDotnetSolutionPath } from "./target";
const ICON = "project-dotnet";
+const PROJECT_EXCLUDED_DIRS = ["bin", "obj"];
const solutionId = (path: string) => `dotnetSolution:${path}`;
const projectId = (path: string) => `dotnetProject:${path}`;
@@ -205,12 +206,20 @@ export function treeRoots(
// node above the folder. Nested ones (a .NET part of a larger repository) stay in their folders.
const topLevel = (path: string) => contentRoots.includes(dirname(path));
const projectName = (path: string) => model.projects.find((p) => p.path === path)?.name ?? solutionName(path);
- const leaf = (path: string): ProjectViewRootEntry => {
+ const projectEntry = (path: string): ProjectViewRootEntry => {
const children = dependencies(
model.projects.find((p) => p.path === path),
projectName,
);
- return { label: projectName(path), icon: ICON, path, file: true, ...(children.length && { children }) };
+ return {
+ id: projectId(path),
+ label: projectName(path),
+ icon: ICON,
+ path: dirname(path),
+ menuPath: path,
+ excludeNames: PROJECT_EXCLUDED_DIRS,
+ ...(children.length && { children }),
+ };
};
const grouped = new Set(model.solutions.flatMap((s) => s.projects));
const roots: ProjectViewRootContribution[] = [];
@@ -222,7 +231,7 @@ export function treeRoots(
icon: ICON,
menuPath: solution.path,
beforeProject: true,
- children: solutionChildren(solution, leaf),
+ children: solutionChildren(solution, projectEntry),
});
}
for (const project of model.projects)
@@ -230,7 +239,7 @@ export function treeRoots(
roots.push({
id: projectId(project.path),
beforeProject: true,
- ...leaf(project.path),
+ ...projectEntry(project.path),
});
return roots.map((root, i) => ({ ...root, order: -200 + i }));
}
diff --git a/src/features/dotnet/window.test.ts b/src/features/dotnet/window.test.ts
index a285f33d5f..9ca2f72932 100644
--- a/src/features/dotnet/window.test.ts
+++ b/src/features/dotnet/window.test.ts
@@ -74,6 +74,7 @@ describe("standalone .NET tool window removal", () => {
"dotnet.format /repo/src/App/App.csproj",
"dotnet.formatVerify /repo/src/App/App.csproj",
"separator",
+ "dotnet.project.editFile /repo/src/App/App.csproj",
"dotnet.project.addReference [object Object]",
"separator",
]);
diff --git a/src/features/project-tree/ProjectView.test.tsx b/src/features/project-tree/ProjectView.test.tsx
index e6062d4681..042c32e62c 100644
--- a/src/features/project-tree/ProjectView.test.tsx
+++ b/src/features/project-tree/ProjectView.test.tsx
@@ -1573,6 +1573,79 @@ it("sorts workspace member roots by the folder names shown in the tree", async (
);
});
+it("expands a .NET solution project node to show Dependencies and files (without bin/obj) and opens files from it", async () => {
+ act(() => setViewOption("showMembers", false));
+ fs = new MemoryFs(
+ {
+ "/w/acme/App.sln": "",
+ "/w/acme/App/App.csproj": "",
+ "/w/acme/App/Program.cs": "class Program {}",
+ "/w/acme/App/Models/Order.cs": "class Order {}",
+ "/w/acme/App/bin/Debug/App.dll": "",
+ "/w/acme/App/obj/project.assets.json": "",
+ },
+ ROOT,
+ );
+ setProjectFsForTests(fs, ROOT);
+ initProjectTree(ROOT, "acme");
+ const disposeRoot = registerProjectViewRoot({
+ id: "dotnetSolution:/w/acme/App.sln",
+ label: "Solution 'App'",
+ icon: "project-dotnet",
+ menuPath: "/w/acme/App.sln",
+ beforeProject: true,
+ children: [
+ {
+ id: "dotnetProject:/w/acme/App/App.csproj",
+ label: "App",
+ icon: "project-dotnet",
+ path: "/w/acme/App",
+ menuPath: "/w/acme/App/App.csproj",
+ excludeNames: ["bin", "obj"],
+ children: [
+ {
+ id: "dependencies",
+ label: "Dependencies",
+ icon: "library",
+ children: [
+ {
+ id: "packages",
+ label: "Packages",
+ icon: "package",
+ children: [{ label: "Serilog", detail: "4.0.0", icon: "package", leaf: true }],
+ },
+ ],
+ },
+ ],
+ },
+ ],
+ });
+ try {
+ const { row, rows } = setup();
+ await waitFor(() => expect(rows()).toContain("Solution 'App'"));
+ fireEvent.doubleClick(row("Solution 'App'"));
+ await waitFor(() => expect(rows()).toContain("App"));
+ // Clicking/double-clicking the project node expands it rather than opening App.csproj.
+ fireEvent.doubleClick(row("App"));
+ await waitFor(() => expect(rows()).toContain("Program.cs"));
+ expect(openFile).not.toHaveBeenCalled();
+ const visible = rows();
+ const depsIdx = visible.indexOf("Dependencies");
+ const modelsIdx = visible.indexOf("Models");
+ const programIdx = visible.indexOf("Program.cs");
+ expect(depsIdx).toBeGreaterThan(-1);
+ expect(modelsIdx).toBeGreaterThan(depsIdx);
+ expect(programIdx).toBeGreaterThan(modelsIdx);
+ expect(visible).not.toContain("bin");
+ expect(visible).not.toContain("obj");
+
+ fireEvent.doubleClick(row("Program.cs"));
+ expect(openFile).toHaveBeenCalledWith("/w/acme/App/Program.cs", expect.objectContaining({ focus: true }));
+ } finally {
+ disposeRoot();
+ }
+});
+
it("hides the path beside workspace roots when Show Root Paths is off, keeping it on hover", async () => {
fs = new MemoryFs({
"/a/service/one.txt": "",
diff --git a/src/features/project-tree/ProjectView.tsx b/src/features/project-tree/ProjectView.tsx
index 29adf63fdc..d0d037e1a0 100644
--- a/src/features/project-tree/ProjectView.tsx
+++ b/src/features/project-tree/ProjectView.tsx
@@ -751,6 +751,7 @@ export function ProjectView() {
const labels = new Map(children.map((child) => [child, decoratedLabel(child)]));
return [...children].sort((a, b) => {
if (!!a.placeholder !== !!b.placeholder) return a.placeholder ? -1 : 1;
+ if (!!a.group !== !!b.group) return a.group ? -1 : 1;
if (options.foldersFirst && a.dir !== b.dir) return a.dir ? -1 : 1;
return compareNames(labels.get(a)!, labels.get(b)!);
});
@@ -800,7 +801,7 @@ export function ProjectView() {
}
const nodes = [...sel].map((k) => m.byKey.get(k)).filter((n): n is ProjectNode => !!n && !n.placeholder);
const target = nodes.length ? nodes : [node];
- const menuPath = target.length === 1 ? target[0]!.menuPath : undefined;
+ const menuPath = target.length === 1 && target[0]!.group ? target[0]!.menuPath : undefined;
if (menuPath) {
// A solution group: only the contributed items of its `.sln` (Build, Add Existing Project…).
const items = menuGroupItems("projectView", { paths: [menuPath], dirs: [false] });
diff --git a/src/features/project-tree/contextMenu.ts b/src/features/project-tree/contextMenu.ts
index b51e3396fa..8c89b0234b 100644
--- a/src/features/project-tree/contextMenu.ts
+++ b/src/features/project-tree/contextMenu.ts
@@ -615,5 +615,8 @@ function copyPathItem(nodes: ProjectNode[], at: MenuPoint, library: boolean): En
/** What contributed menu groups see: the selected (non-placeholder) paths. */
export function menuGroupContext(nodes: ProjectNode[]): MenuGroupContext {
const real = nodes.filter((n) => !n.placeholder);
- return { paths: real.map((n) => n.path), dirs: real.map((n) => n.dir) };
+ return {
+ paths: real.map((n) => n.menuPath ?? n.path),
+ dirs: real.map((n) => (n.menuPath ? false : n.dir)),
+ };
}
diff --git a/src/features/project-tree/extraRoots.test.ts b/src/features/project-tree/extraRoots.test.ts
index 9fb9855a33..a037f0703d 100644
--- a/src/features/project-tree/extraRoots.test.ts
+++ b/src/features/project-tree/extraRoots.test.ts
@@ -16,7 +16,8 @@ vi.mock("@/editor/refactor", () => ({
const { MemoryFs, setProjectFsForTests } = await import("./fs");
const { DEFAULT_TREE_OPTIONS, buildModel, isLibKey, pathOfKey, visibleInfo, withExtraRoots } = await import("./model");
const { menuGroupContext } = await import("./contextMenu");
-const { currentModel, initProjectTree, loadDir, revealPath, useProjectTree } = await import("./store");
+const { currentModel, initProjectTree, isReadOnlyPath, loadDir, revealPath, setViewMode, useProjectTree } =
+ await import("./store");
const { beginRename, commitEditing, deleteSelection } = await import("./operations");
const entry = (path: string, kind: "file" | "dir" = "file"): FileEntry => ({
@@ -429,3 +430,164 @@ describe("project view with a solution group of file leaves", () => {
expect(model.keyOfPath.get("/p/src/App.csproj")).toBe("/p/src/App.csproj");
});
});
+
+describe("solution project folders with Dependencies, bin/obj exclusion, and Select Opened File", () => {
+ let unregister = () => {};
+ const deps = {
+ id: "dependencies",
+ label: "Dependencies",
+ icon: "library",
+ children: [
+ {
+ id: "packages",
+ label: "Packages",
+ icon: "package",
+ children: [{ label: "Serilog", detail: "4.0.0", icon: "package", leaf: true }],
+ },
+ ],
+ };
+
+ beforeEach(() => {
+ localStorage.clear();
+ const fs = new MemoryFs(
+ {
+ "/p/App.sln": "x",
+ "/p/README.md": "readme",
+ "/p/src/App/App.csproj": "",
+ "/p/src/App/Program.cs": "class Program {}",
+ "/p/src/App/Models/Order.cs": "class Order {}",
+ "/p/src/App/bin/Debug/App.dll": "bin",
+ "/p/src/App/obj/project.assets.json": "obj",
+ },
+ "/p",
+ );
+ setProjectFsForTests(fs, "/p");
+ initProjectTree("/p", "proj");
+ unregister = registerProjectViewRoot({
+ id: "dotnetSolution:/p/App.sln",
+ label: "Solution 'App'",
+ icon: "project-dotnet",
+ menuPath: "/p/App.sln",
+ beforeProject: true,
+ children: [
+ {
+ id: "folder:Services",
+ label: "Services",
+ icon: "folder",
+ children: [
+ {
+ id: "dotnetProject:/p/src/App/App.csproj",
+ label: "App",
+ icon: "project-dotnet",
+ path: "/p/src/App",
+ menuPath: "/p/src/App/App.csproj",
+ excludeNames: ["bin", "obj"],
+ children: [deps],
+ },
+ { label: "README.md", icon: "file", path: "/p/README.md", file: true },
+ ],
+ },
+ ],
+ });
+ });
+
+ afterEach(() => {
+ setViewMode("project");
+ unregister();
+ setProjectFsForTests(null);
+ initProjectTree(null);
+ });
+
+ it("defers loading until expanded, then shows Dependencies first and omits bin and obj", async () => {
+ const initial = currentModel();
+ const sln = initial.roots[0]!;
+ const folder = initial.children.get(sln.key)![0]!;
+ const app = initial.children.get(folder.key)![0]!;
+ expect([app.label, app.dir, app.path, app.readOnly]).toEqual(["App", true, "/p/src/App", undefined]);
+ expect(isLibKey(app.key)).toBe(true);
+ expect(pathOfKey(app.key)).toBe("/p/src/App");
+ expect(menuGroupContext([app])).toEqual({ paths: ["/p/src/App/App.csproj"], dirs: [false] });
+ // Before /p/src/App is loaded, expanding App marks it pending so the folder listing loads.
+ expect(initial.children.get(app.key)).toBeUndefined();
+ const infoBefore = visibleInfo(initial, new Set([sln.key, folder.key, app.key]));
+ expect(infoBefore.pending).toContain("/p/src/App");
+
+ await loadDir("/p");
+ await loadDir("/p/src");
+ await loadDir("/p/src/App");
+ const loaded = currentModel();
+ const kids = loaded.children.get(app.key)!;
+ expect(kids.map((k) => k.label)).toEqual(["Dependencies", "Models", "App.csproj", "Program.cs"]);
+ expect(kids[0]!.group).toBe(true);
+ const program = kids.find((k) => k.label === "Program.cs")!;
+ expect([program.dir, program.path, program.readOnly]).toEqual([false, "/p/src/App/Program.cs", undefined]);
+ expect(isReadOnlyPath(program.key)).toBe(false);
+ expect(isReadOnlyPath(program.path)).toBe(false);
+ // The plain folder tree below (where `src/App` compacts under key `/p/src`) still lists bin and obj.
+ expect(loaded.children.get("/p/src")!.map((k) => k.label)).toContain("bin");
+ expect(loaded.children.get("/p/src")!.map((k) => k.label)).toContain("obj");
+ });
+
+ it("reveals an opened file inside the solution tree via Select Opened File", async () => {
+ expect(revealPath("/p/src/App/Models/Order.cs")).toBe(true);
+ await vi.waitFor(() => {
+ const model = currentModel();
+ const key = model.keyOfPath.get("/p/src/App/Models/Order.cs");
+ expect(key).toBeDefined();
+ expect(isLibKey(key!)).toBe(true);
+ expect(pathOfKey(key!)).toBe("/p/src/App/Models/Order.cs");
+ expect(visibleInfo(model, useProjectTree.getState().expanded).visible.has(key!)).toBe(true);
+ });
+ });
+
+ it("falls back to the folder tree for excluded bin/obj files, non-project files, and Project Files mode", async () => {
+ expect(revealPath("/p/src/App/bin/Debug/App.dll")).toBe(true);
+ await vi.waitFor(() => {
+ const model = currentModel();
+ const key = model.keyOfPath.get("/p/src/App/bin/Debug/App.dll");
+ expect(key).toBe("/p/src/App/bin/Debug/App.dll");
+ expect(visibleInfo(model, useProjectTree.getState().expanded).visible.has(key!)).toBe(true);
+ });
+
+ expect(revealPath("/p/README.md")).toBe(true);
+ await vi.waitFor(() => {
+ const model = currentModel();
+ const key = model.keyOfPath.get("/p/README.md");
+ expect(key).toBe("/p/README.md");
+ expect(visibleInfo(model, useProjectTree.getState().expanded).visible.has(key!)).toBe(true);
+ });
+
+ setViewMode("projectFiles");
+ expect(revealPath("/p/src/App/Models/Order.cs")).toBe(true);
+ await vi.waitFor(() => {
+ const model = currentModel();
+ const key = model.keyOfPath.get("/p/src/App/Models/Order.cs");
+ expect(key).toBe("/p/src/App/Models/Order.cs");
+ expect(visibleInfo(model, useProjectTree.getState().expanded).visible.has(key!)).toBe(true);
+ });
+ });
+
+ it("reveals files inside a standalone project sitting at the repository root", async () => {
+ unregister();
+ const fs = new MemoryFs({ "/p/App.csproj": "", "/p/Program.cs": "class P {}" }, "/p");
+ setProjectFsForTests(fs, "/p");
+ initProjectTree("/p", "proj");
+ unregister = registerProjectViewRoot({
+ id: "dotnetProject:/p/App.csproj",
+ label: "App",
+ icon: "project-dotnet",
+ path: "/p",
+ menuPath: "/p/App.csproj",
+ beforeProject: true,
+ excludeNames: ["bin", "obj"],
+ });
+ expect(revealPath("/p/Program.cs")).toBe(true);
+ await vi.waitFor(() => {
+ const model = currentModel();
+ const key = model.keyOfPath.get("/p/Program.cs");
+ expect(key).toBeDefined();
+ expect(isLibKey(key!)).toBe(true);
+ expect(visibleInfo(model, useProjectTree.getState().expanded).visible.has(key!)).toBe(true);
+ });
+ });
+});
diff --git a/src/features/project-tree/model.ts b/src/features/project-tree/model.ts
index 30efe272da..9f693d69c8 100644
--- a/src/features/project-tree/model.ts
+++ b/src/features/project-tree/model.ts
@@ -184,6 +184,7 @@ export function buildModel(
listings: Listings,
opts: TreeOptions,
placeholder?: Placeholder | null,
+ excludeRootNames?: ReadonlySet,
): TreeModel {
const children = new Map();
const byKey = new Map();
@@ -256,7 +257,11 @@ export function buildModel(
const fill = (node: ProjectNode) => {
const listing = listings.get(node.path);
if (!listing) return;
- const kids = visibleEntries(listing, opts).map(makeNode);
+ const entries =
+ excludeRootNames && node === rootNode
+ ? listing.filter((e) => !excludeRootNames.has(e.name.toLowerCase()))
+ : listing;
+ const kids = visibleEntries(entries, opts).map(makeNode);
if (placeholder && placeholder.parent === node.path) {
const ph: ProjectNode = {
key: node.path + PLACEHOLDER_SUFFIX,
@@ -293,9 +298,11 @@ export interface ExtraRoot {
icon: string;
/** Folder listed by the node; omitted for a group node of `children`. */
path?: string;
- /** `path` is a file: shown as a leaf (a project file under a solution group), not a folder listing. */
+ /** `path` is a file: shown as a leaf (a solution item under a solution folder), not a folder listing. */
file?: boolean;
children?: readonly ExtraRoot[];
+ /** Direct child names omitted from this folder's listing (case-insensitive, e.g. `bin`, `obj`). */
+ excludeNames?: readonly string[];
detail?: string;
note?: string;
/** A virtual row with no file or folder behind it (a package of a project's Dependencies): a childless group node. */
@@ -400,8 +407,18 @@ export function withExtraRoots(
byKey: new Map(model.byKey),
keyOfPath: new Map(model.keyOfPath),
};
- const add = (extra: ExtraRoot, parentKey: string | null, readOnly: boolean, nesting = 0): ProjectNode | null => {
+ // `beforeProject` folder roots sit above the project folder and win `keyOfPath` over it,
+ // with deeper (innermost) project folders winning over shallower ones.
+ const preferredDepth = new Map();
+ const add = (
+ extra: ExtraRoot,
+ parentKey: string | null,
+ readOnly: boolean,
+ beforeProject: boolean,
+ nesting = 0,
+ ): ProjectNode | null => {
const ro = readOnly || !!extra.readOnly;
+ const before = beforeProject || !!extra.beforeProject;
if (extra.file && extra.path !== undefined) {
// A file leaf is keyed in its group's namespace (like a library folder): the
// same file also shows in its own folder below the project, and `pathOfKey`
@@ -427,23 +444,34 @@ export function withExtraRoots(
if (ro) node.readOnly = true;
out.byKey.set(key, node);
if (extra.children) {
- const built = extra.children.map((child) => add(child, key, ro)).filter((node): node is ProjectNode => !!node);
+ const built = extra.children
+ .map((child) => add(child, key, ro, before))
+ .filter((node): node is ProjectNode => !!node);
out.children.set(key, built);
}
return node;
}
- if (extra.path !== undefined && !extra.children) {
+ if (extra.path !== undefined) {
const path = extra.path;
- // Library folders of a group are keyed in their own namespace; other
- // folders (scratches) by path, so ones inside the project stay under it.
- // A root inside a sibling root (a venv's `Lib` and its `Lib/site-packages`) lists in a
+ // Library folders of a group and `beforeProject` project folders are keyed in their own
+ // namespace; other folders (scratches) by path, so ones inside the project stay under it.
+ // A library root inside a sibling root (a venv's `Lib` and its `Lib/site-packages`) lists in a
// namespace of its own: the sibling's listing holds the same folder, and one key on two
// rows overlaps them in the virtual list (#7444).
- const ns = ro && parentKey ? parentKey.slice(GROUP_PREFIX.length) + NESTED_NS.repeat(nesting) : null;
+ const ns = before
+ ? parentKey
+ ? `${parentKey.slice(GROUP_PREFIX.length)}/${extra.id ?? extra.label}`
+ : (extra.id ?? extra.label)
+ : ro && parentKey
+ ? parentKey.slice(GROUP_PREFIX.length) + NESTED_NS.repeat(nesting)
+ : null;
const rekey = (k: string) => (ns === null ? k : libKey(ns, k));
if (out.byKey.has(rekey(path))) return null;
if (ns === null && model.roots.some((r) => !r.group && isSameOrInside(path, r.path))) return null;
- const sub = buildModel({ path, name: extra.label }, listings, opts, ro ? null : placeholder);
+ const excludeRootNames = extra.excludeNames?.length
+ ? new Set(extra.excludeNames.map((n) => n.toLowerCase()))
+ : undefined;
+ const sub = buildModel({ path, name: extra.label }, listings, opts, ro ? null : placeholder, excludeRootNames);
const subRoot = sub.roots[0]!;
const rootNode: ProjectNode = {
...subRoot,
@@ -452,6 +480,7 @@ export function withExtraRoots(
icon: extra.icon,
detail: extra.detail,
note: extra.note,
+ ...(extra.menuPath ? { menuPath: extra.menuPath } : {}),
};
if (ro) rootNode.readOnly = true;
const nodes = new Map();
@@ -466,7 +495,26 @@ export function withExtraRoots(
rekey(k),
v.map((n) => nodes.get(n.key) ?? n),
);
- for (const [p, k] of sub.keyOfPath) if (!out.keyOfPath.has(p)) out.keyOfPath.set(p, rekey(k));
+ // Prepend leading virtual children (e.g. a .NET project's Dependencies) only once the folder
+ // listing is loaded, so an unloaded folder still triggers `loadDir` on expand and in `visibleInfo`.
+ if (extra.children?.length && out.children.has(rootNode.key)) {
+ const leading = extra.children
+ .map((child) => add(child, rootNode.key, ro, before))
+ .filter((n): n is ProjectNode => !!n);
+ if (leading.length) out.children.set(rootNode.key, [...leading, ...out.children.get(rootNode.key)!]);
+ }
+ const rootDepth = path.split("/").length;
+ for (const [p, k] of sub.keyOfPath) {
+ if (before) {
+ const prev = preferredDepth.get(p);
+ if (prev === undefined || rootDepth > prev) {
+ preferredDepth.set(p, rootDepth);
+ out.keyOfPath.set(p, rekey(k));
+ }
+ } else if (!out.keyOfPath.has(p)) {
+ out.keyOfPath.set(p, rekey(k));
+ }
+ }
return rootNode;
}
const key = `${parentKey ? `${parentKey}/` : GROUP_PREFIX}${extra.id ?? extra.label}`;
@@ -516,7 +564,7 @@ export function withExtraRoots(
const depth = (c: ExtraRoot) => c.path?.split("/").length ?? 0;
const built: (ProjectNode | null)[] = [];
for (const i of children.map((_, i) => i).sort((a, b) => depth(children[b]!) - depth(children[a]!)))
- built[i] = add(children[i]!, key, ro, nestingDepth(children, children[i]!));
+ built[i] = add(children[i]!, key, ro, before, nestingDepth(children, children[i]!));
out.children.set(
key,
built.filter((n): n is ProjectNode => !!n),
@@ -525,7 +573,7 @@ export function withExtraRoots(
};
let before = 0;
for (const extra of extras) {
- const node = add(extra, null, false);
+ const node = add(extra, null, false, false);
if (node && extra.beforeProject) out.roots.splice(before++, 0, node);
else if (node) out.roots.push(node);
}
@@ -556,12 +604,14 @@ export function withReadOnlyFolders(model: TreeModel, folders: readonly string[]
}
/** Folder roots of contributed entries (groups flattened, file leaves left out), in display order. */
-export function extraFolders(extras: readonly ExtraRoot[], readOnly = false): ExtraRoot[] {
- return extras.flatMap((e) =>
- e.path !== undefined && !e.children && !e.file
- ? [{ ...e, readOnly: readOnly || !!e.readOnly }]
- : extraFolders(e.children ?? [], readOnly || !!e.readOnly),
- );
+export function extraFolders(extras: readonly ExtraRoot[], readOnly = false, beforeProject = false): ExtraRoot[] {
+ return extras.flatMap((e) => {
+ const ro = readOnly || !!e.readOnly;
+ const before = beforeProject || !!e.beforeProject;
+ return e.path !== undefined && !e.file
+ ? [{ ...e, readOnly: ro, beforeProject: before }]
+ : extraFolders(e.children ?? [], ro, before);
+ });
}
/**
diff --git a/src/features/project-tree/store.ts b/src/features/project-tree/store.ts
index 946113bff3..7d71ef6f1c 100644
--- a/src/features/project-tree/store.ts
+++ b/src/features/project-tree/store.ts
@@ -322,7 +322,10 @@ export function selectModel(s: ProjectTreeState): TreeModel {
);
else if (files)
model = buildPathsModel(
- [...(memberRoots ?? [{ path: s.root, label: s.name, icon: "" }]), ...extraFolders(contributed)],
+ [
+ ...(memberRoots ?? [{ path: s.root, label: s.name, icon: "" }]),
+ ...extraFolders(contributed).filter((r) => !r.beforeProject),
+ ],
files,
s.options.foldersFirst,
);
@@ -1055,24 +1058,47 @@ export function dropOutlines(paths: readonly string[]) {
let revealSeq = 0;
-function resolveRevealTarget(requested: string): { path: string; root: string } | null {
- const project = get().root;
+function excludedInFolder(path: string, folder: { path?: string; excludeNames?: readonly string[] }): boolean {
+ if (!folder.excludeNames?.length || !folder.path || path === folder.path) return false;
+ const first = path
+ .slice(folder.path.length + 1)
+ .split("/")[0]
+ ?.toLowerCase();
+ return !!first && folder.excludeNames.some((n) => n.toLowerCase() === first);
+}
+
+function resolveRevealTarget(requested: string): { path: string; root: string; beforeProject?: boolean } | null {
+ const state = get();
+ const project = state.root;
if (!project) return null;
+ const folders = extraFolders(projectViewRoots(useProjectViewRoots.getState().roots));
+ const usesBeforeProject = state.mode === "project" || state.mode === "unity" || state.mode === "unreal";
+ const beforeFolders = usesBeforeProject ? folders.filter((r) => r.beforeProject && r.path !== undefined) : [];
// Registered archive roots by their `/`-separated form, which candidate paths use.
const archiveRoots = new Map(
- extraFolders(projectViewRoots(useProjectViewRoots.getState().roots)).flatMap((r) =>
- r.path?.endsWith("!") ? [[ipcPath(r.path), r.path] as const] : [],
- ),
+ folders.flatMap((r) => (r.path?.endsWith("!") ? [[ipcPath(r.path), r.path] as const] : [])),
);
const archives = [...archiveRoots.keys()];
- const rootOf = (p: string) => {
+ const rootOf = (p: string): { root: string; beforeProject?: boolean } | null => {
const archive = p.indexOf("!/");
- if (archive !== -1) return archiveRoots.get(ipcPath(p.slice(0, archive + 1))) ?? null;
- return memberRootOf(p) ?? (isSameOrInside(p, project) ? project : extraRootOf(p));
+ if (archive !== -1) {
+ const root = archiveRoots.get(ipcPath(p.slice(0, archive + 1))) ?? null;
+ return root ? { root } : null;
+ }
+ let best: string | null = null;
+ for (const r of beforeFolders)
+ if (isSameOrInside(p, r.path!) && !excludedInFolder(p, r) && (!best || r.path!.length > best.length))
+ best = r.path!;
+ if (best) return { root: best, beforeProject: true };
+ const fallback = memberRootOf(p) ?? (isSameOrInside(p, project) ? project : extraRootOf(p));
+ return fallback ? { root: fallback } : null;
};
// Library documents (`jdt://`, `jar:` URIs) are shown as entries of their archive under External Libraries.
- const path = [requested, ...libraryEntryPaths(requested, archives)].find((p) => rootOf(p) !== null);
- return path ? { path, root: rootOf(path)! } : null;
+ for (const p of [requested, ...libraryEntryPaths(requested, archives)]) {
+ const target = rootOf(p);
+ if (target) return { path: p, ...target };
+ }
+ return null;
}
/** Whether `requested` lies inside any root the Project tree can show. */
@@ -1084,12 +1110,12 @@ export function canRevealInProjectTree(requested: string): boolean {
export function revealPath(requested: string, focus = false, explain = false, expand = false) {
const resolved = resolveRevealTarget(requested);
if (!resolved) return false;
- const { path, root } = resolved;
+ const { path, root, beforeProject } = resolved;
const { expanded } = get();
const project = get().root!;
- // Library folders sit below group nodes (External Libraries › SDK), keyed in their own namespace.
+ // Library folders and `beforeProject` project folders sit in their own key namespace.
const model = currentModel();
- const rootKey = root === project ? root : (model.keyOfPath.get(root) ?? root);
+ const rootKey = beforeProject || root !== project ? (model.keyOfPath.get(root) ?? root) : root;
const baseFolders = ancestorsWithin(root, path);
const folders = expand && !baseFolders.includes(path) ? [...baseFolders, path] : baseFolders;
const ancestors = [...groupAncestors(model, rootKey), ...folders.map((a) => keyLike(rootKey, a))];
@@ -1160,7 +1186,11 @@ export function modeShows(path: string, mode = get().mode): boolean {
/** Whether `path` lies in read-only library sources or an unavailable root. */
export function isReadOnlyPath(path: string): boolean {
- if (isGroupKey(path) || isLibKey(path)) return true;
+ if (isGroupKey(path)) return true;
+ if (isLibKey(path)) {
+ const node = currentModel().byKey.get(path);
+ return node ? !!node.readOnly : true;
+ }
if (isPathUnavailable(path, get().unavailableRoots)) return true;
return extraFolders(projectViewRoots(useProjectViewRoots.getState().roots)).some(
(r) => r.readOnly && r.path !== undefined && isSameOrInside(path, r.path),
diff --git a/src/platform/locales/text/zh.json b/src/platform/locales/text/zh.json
index 09ffa20caf..4a7292efac 100644
--- a/src/platform/locales/text/zh.json
+++ b/src/platform/locales/text/zh.json
@@ -12508,5 +12508,7 @@
"Starting loopback port for the built-in server (falls back to consecutive ports if already in use).": "内置服务器的起始回环端口(若端口已被占用则顺延尝试后续端口)。",
"Open File Request": "打开文件请求",
"An external request from {source} wants to open:": "来自 {source} 的外部请求想要打开:",
- "Allow opening files from this source?": "是否允许此来源打开文件?"
+ "Allow opening files from this source?": "是否允许此来源打开文件?",
+ "Edit Project File": "编辑项目文件",
+ "Edit '{name}'": "编辑 '{name}'"
}
diff --git a/src/workbench/contributions.ts b/src/workbench/contributions.ts
index da8b5ea4b6..9b05f53ba7 100644
--- a/src/workbench/contributions.ts
+++ b/src/workbench/contributions.ts
@@ -1536,19 +1536,21 @@ export interface ProjectViewRootEntry {
label: string;
/** Icon name from `ui/icons`. */
icon: string;
- /** Folder whose contents the node lists (outside the project); omitted for a group of `children`. */
+ /** Folder whose contents the node lists (outside the project, or a `beforeProject` project folder); omitted for a group of `children`. */
path?: string;
- /** `path` is a file: shown as a leaf (a project file under a solution group), not a folder listing. */
+ /** `path` is a file: shown as a leaf (a solution item under a solution folder), not a folder listing. */
file?: boolean;
- /** Child nodes of a group node (one per SDK, then its library folders). */
+ /** Child nodes of a group node (one per SDK, then its library folders), or leading virtual nodes of a folder entry (a project's Dependencies). */
children?: readonly ProjectViewRootEntry[];
+ /** Direct child names omitted from this folder's listing (case-insensitive, e.g. `bin` and `obj`). */
+ excludeNames?: readonly string[];
/** Grey text after the label ("library root"). */
detail?: string;
/** Untranslated text after `detail` (the parent folder of a same-named library root). */
note?: string;
/** A virtual row with no file or folder behind it (a package of a project's Dependencies). */
leaf?: boolean;
- /** A group node: the file whose Project view context-menu groups the node shows (a solution's `.sln`). */
+ /** File whose Project view context-menu groups the node shows (a solution's `.sln`, or a project folder's `.csproj`). */
menuPath?: string;
/** Library sources: shown read-only (no new / rename / move / delete). */
readOnly?: boolean;