дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-11-27 13:06:07 +02:00
feat(run): run and debug a .NET project file from the project view (#5969)
The Project view context menu on a .csproj / .fsproj / .vbproj offers Run '<name>' / Debug '<name>' / More Run/Debug. It produces a temporary dotnet configuration (`dotnet run --project <file> --no-launch-profile`, built first by the dotnetBuild before-launch step, debugged through netcoredbg), so it launches and edits like a saved one. Solutions keep only Build / Restore / Clean; launch profiles stay on the launchSettings.json gutter. The run feature recognises project files itself instead of importing the dotnet feature. Refs #5635 Co-authored-by: Inf1mum <[email protected]>
Цей коміт міститься в:
1 джерело
89a3359aaf
коміт
3d534b447d
5 files changed
+87
-1
No files matched your search
@@ -115,6 +115,20 @@ describe("run context menu group", () => {
|
||||
expect(contextMenuItems("projectView", { paths: [`${ROOT}/src/components`], dirs: [true] })).toEqual([]);
|
||||
});
|
||||
|
||||
it("project view: Run / Debug '<project>' on a .NET project file (#5635)", () => {
|
||||
const items = contextMenuItems("projectView", { paths: [`${ROOT}/src/App/App.csproj`], dirs: [false] });
|
||||
expect(items[0]).toMatchObject({
|
||||
action: "run.runContext",
|
||||
label: "Run 'App'",
|
||||
icon: "run",
|
||||
arg: { path: `${ROOT}/src/App/App.csproj`, dir: false },
|
||||
});
|
||||
expect(items[1]).toMatchObject({ action: "run.debugContext", label: "Debug 'App'", icon: "debug" });
|
||||
// A solution or a shared props file gets no Run / Debug entries.
|
||||
expect(contextMenuItems("projectView", { paths: [`${ROOT}/src/App/App.sln`], dirs: [false] })).toEqual([]);
|
||||
expect(contextMenuItems("projectView", { paths: [`${ROOT}/Directory.Build.props`], dirs: [false] })).toEqual([]);
|
||||
});
|
||||
|
||||
it("routes an attached Spring Boot main and its tests through the member's Maven build", () => {
|
||||
const member = "/work/spring";
|
||||
const project = useProject.getState().project!;
|
||||
|
||||
@@ -3,7 +3,7 @@ import { fireEvent, render, screen } from "@testing-library/react";
|
||||
import { commands } from "@/platform/ipc";
|
||||
import type { RunConfig } from "@/platform/ipc";
|
||||
import { useProject } from "@/platform/project";
|
||||
import { dotnetProjectFile, dotnetProjectType, dotnetTestType } from "./dotnetTypes";
|
||||
import { dotnetProjectFile, dotnetProjectProduction, dotnetProjectType, dotnetTestType } from "./dotnetTypes";
|
||||
import { ConfigForm } from "./ConfigForm";
|
||||
import { validateConfig } from "./configs";
|
||||
import { formParams, newConfigOfType, registerBuiltinTypes, withParams } from "./types";
|
||||
@@ -99,6 +99,28 @@ describe(".NET configurations", () => {
|
||||
expect(formParams({ ...typed, args: ["build", "A"] }, dotnetProjectType)).toBeNull();
|
||||
});
|
||||
|
||||
it("produces a context run configuration for a project file (#5635)", () => {
|
||||
const p = dotnetProjectProduction("src/App/App.csproj");
|
||||
expect(p).toMatchObject({
|
||||
id: "context:dotnet:src/App/App.csproj",
|
||||
name: "App",
|
||||
kind: "dotnet",
|
||||
command: "dotnet",
|
||||
args: ["run", "--project", "src/App/App.csproj", "--no-launch-profile"],
|
||||
debugAdapter: "netcoredbg",
|
||||
detected: true,
|
||||
isTest: false,
|
||||
params: { project: "src/App/App.csproj" },
|
||||
});
|
||||
// Like a configuration from the form, it builds before launching so Debug works unbuilt.
|
||||
expect(p.beforeLaunch).toEqual([{ kind: "dotnetBuild", target: "" }]);
|
||||
// F#, Visual Basic and a project file at the root get the same shape.
|
||||
expect(dotnetProjectProduction("lib/Worker.vbproj").name).toBe("Worker");
|
||||
expect(dotnetProjectProduction("App.fsproj").name).toBe("App");
|
||||
// The form can show it back ("Modify Run Configuration…").
|
||||
expect(formParams(p, dotnetProjectType)).toEqual({ project: "src/App/App.csproj" });
|
||||
});
|
||||
|
||||
it("builds the edited project from the open root instead of a profile cwd", () => {
|
||||
useProject.setState({ project: { root: "/repo" } as never });
|
||||
const c = withParams({ ...config(), cwd: "profile/work" }, { ...params, project: "other/App.csproj" });
|
||||
|
||||
@@ -70,6 +70,31 @@ export function dotnetProjectFile(config: RunConfig): string | null {
|
||||
return root ? `${root}/${project}` : null;
|
||||
}
|
||||
|
||||
/** An MSBuild project file of C#, F# or Visual Basic (not its `.csproj.user`). */
|
||||
export const isDotnetProjectFile = (path: string) => /\.(?:cs|fs|vb)proj$/i.test(path);
|
||||
|
||||
/**
|
||||
* "Run '<name>'" on a project file in the project view (Rider's project node): `dotnet run
|
||||
* --project` without launch profiles — those are the launchSettings.json gutter's entries.
|
||||
* Debugged by netcoredbg like the saved configurations of the type.
|
||||
*/
|
||||
export function dotnetProjectProduction(project: string): RunConfig {
|
||||
return {
|
||||
id: `context:dotnet:${project}`,
|
||||
name: project.replace(/^.*\//, "").replace(/\.(?:cs|fs|vb)proj$/i, ""),
|
||||
kind: "dotnet",
|
||||
command: "dotnet",
|
||||
args: dotnetCommand({ project }).args,
|
||||
cwd: null,
|
||||
env: {},
|
||||
detected: true,
|
||||
isTest: false,
|
||||
debugAdapter: "netcoredbg",
|
||||
beforeLaunch: [{ kind: "dotnetBuild", target: "" }],
|
||||
params: { project },
|
||||
};
|
||||
}
|
||||
|
||||
export const dotnetProjectType: RunConfigTypeContribution = {
|
||||
id: "dotnet",
|
||||
label: ".NET Project",
|
||||
|
||||
@@ -858,6 +858,25 @@ describe("project producers", () => {
|
||||
expect(p.config!.args).toEqual(["run", "test", "--", "src/a.test.ts"]);
|
||||
});
|
||||
|
||||
it("runs a .NET project file with dotnet run --project (#5635)", () => {
|
||||
const p = produceContext({ path: `${ROOT}/src/App/App.csproj`, root: ROOT, configs: [] }, OPTIMISTIC)!;
|
||||
expect(p).toMatchObject({ name: "App", scope: "file" });
|
||||
expect(p.config).toMatchObject({
|
||||
id: "context:dotnet:src/App/App.csproj",
|
||||
kind: "dotnet",
|
||||
command: "dotnet",
|
||||
args: ["run", "--project", "src/App/App.csproj", "--no-launch-profile"],
|
||||
debugAdapter: "netcoredbg",
|
||||
params: { project: "src/App/App.csproj" },
|
||||
});
|
||||
// A `.csproj.user` is not a project, and a source file has no entry-point production.
|
||||
expect(produceContext({ path: `${ROOT}/src/App/App.csproj.user`, root: ROOT, configs: [] }, OPTIMISTIC)).toBeNull();
|
||||
expect(produceContext({ path: `${ROOT}/src/App/Program.cs`, root: ROOT, configs: [] }, OPTIMISTIC)).toBeNull();
|
||||
// Neither is a solution or a shared props file.
|
||||
expect(produceContext({ path: `${ROOT}/src/App/App.sln`, root: ROOT, configs: [] }, OPTIMISTIC)).toBeNull();
|
||||
expect(produceContext({ path: `${ROOT}/Directory.Build.props`, root: ROOT, configs: [] }, OPTIMISTIC)).toBeNull();
|
||||
});
|
||||
|
||||
it("⌃⇧R picks the innermost context: test > describe > file", () => {
|
||||
const src = [
|
||||
"describe('math', () => {",
|
||||
|
||||
@@ -28,6 +28,7 @@ import {
|
||||
relToCwd as relativeToCwd,
|
||||
} from "./context";
|
||||
import { djangoLabel, djangoTestsOf, hasDjangoTests } from "./djangoTypes";
|
||||
import { dotnetProjectProduction, isDotnetProjectFile } from "./dotnetTypes";
|
||||
import { firstTopLevelType, scanJvmTargets, simpleClassName } from "./jvmTargets";
|
||||
import { isWindows } from "./jvmTypes";
|
||||
import { inheritedRunTargets } from "./inheritedMain";
|
||||
@@ -819,6 +820,11 @@ export function produceFile(input: ContextInput, env: ToolEnv): Produced | null
|
||||
const rel = s.idPath;
|
||||
|
||||
if (s.inProject) {
|
||||
// #5635: Rider's "Run '<name>'" on a project file, Debug through its netcoredbg adapter.
|
||||
if (isDotnetProjectFile(rel)) {
|
||||
const config = dotnetProjectProduction(rel);
|
||||
return { name: config.name, scope: "file", config };
|
||||
}
|
||||
if (lang === "c" || lang === "cpp") {
|
||||
const target = cmakeTargets(input)[0];
|
||||
if (target) return { name: target.name, scope: "file", config: target };
|
||||
|
||||
Reference in new issue
Заблокувати користувача