mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 16:04:21 +00:00
With the Run notification group set to not show balloons (Settings › Notifications, or Don't Show Again on a Run notification), clicking Profile '…' / Allocations / Live Objects or Run with Coverage looked like it did nothing: the reason the run could not start (async-profiler or the coverage tool is not installed, the configuration is not supported, preparing it failed) went only to the Notifications list. These notifications answer a command the user just ran, so they are now `userInitiated` and always show as a balloon, like a manual update check.
146 lines
4.4 KiB
TypeScript
146 lines
4.4 KiB
TypeScript
/**
|
|
* The "Run with Coverage" executor: the backend rewrites the configuration for
|
|
* the runtime's coverage tool; after the run the report becomes a suite.
|
|
*/
|
|
import { executeAction } from "@/platform/actions";
|
|
import { call, commands, isTauri, type InstallCommand, type RunConfig } from "@/platform/ipc";
|
|
import {
|
|
notifications,
|
|
toolWindowService,
|
|
type ExecutorLaunch,
|
|
type RunExecutorContribution,
|
|
} from "@/workbench/contributions";
|
|
import { coverageSupports, formatPercent } from "./model";
|
|
import { addSuite, captureCoverageProject } from "./store";
|
|
import { tx } from "@/platform/i18n";
|
|
|
|
const errorText = (e: unknown) => (e instanceof Error ? e.message : String(e));
|
|
|
|
/** A one-off configuration that runs an install command in the Run tool window. */
|
|
export function installConfig(tool: string, install: InstallCommand): RunConfig {
|
|
return {
|
|
id: `install:${tool}`,
|
|
name: `Install ${tool}`,
|
|
kind: "shell",
|
|
command: install.command,
|
|
args: install.args,
|
|
cwd: install.cwd,
|
|
env: {},
|
|
detected: true,
|
|
isTest: false,
|
|
debugAdapter: null,
|
|
};
|
|
}
|
|
|
|
/** "<tool> is not installed" with an Install button running the install command. */
|
|
export function notifyMissingTool(
|
|
group: string,
|
|
missing: { tool: string; message: string; install: InstallCommand | null; homepage?: string | null },
|
|
) {
|
|
const { tool, install } = missing;
|
|
const line = install ? [install.command, ...install.args].join(" ") : null;
|
|
const actions = [];
|
|
if (install)
|
|
actions.push({ label: "Install", run: () => void executeAction("run.runConfig", installConfig(tool, install)) });
|
|
if (missing.homepage) {
|
|
const url = missing.homepage;
|
|
actions.push({
|
|
label: "Download…",
|
|
run: () => void import("@tauri-apps/plugin-opener").then((o) => o.openUrl(url)).catch(() => undefined),
|
|
});
|
|
}
|
|
notifications().notify({
|
|
group,
|
|
level: "warning",
|
|
key: `${group}-missing-${tool}`,
|
|
title: `${tool} is not installed`,
|
|
body: line
|
|
? tx`${missing.message} Install it with: ${line}`
|
|
: missing.homepage
|
|
? `${missing.message} ${missing.homepage}`
|
|
: missing.message,
|
|
sticky: true,
|
|
userInitiated: true,
|
|
actions,
|
|
});
|
|
}
|
|
|
|
async function prepare(config: RunConfig): Promise<ExecutorLaunch | null> {
|
|
if (!isTauri()) {
|
|
notifications().notify({
|
|
group: "run",
|
|
level: "warning",
|
|
title: "Coverage needs the desktop app",
|
|
userInitiated: true,
|
|
});
|
|
return null;
|
|
}
|
|
const project = captureCoverageProject();
|
|
if (!project) return null;
|
|
const plan = await call(commands.coveragePrepare(config)).catch((e: unknown) => {
|
|
if (project.isCurrent()) throw e;
|
|
return null;
|
|
});
|
|
if (!plan || !project.isCurrent()) return null;
|
|
if (plan.status === "unsupported") {
|
|
notifications().notify({
|
|
group: "run",
|
|
level: "info",
|
|
key: "coverage-unsupported",
|
|
title: `Cannot run '${config.name}' with coverage`,
|
|
body: plan.reason,
|
|
userInitiated: true,
|
|
});
|
|
return null;
|
|
}
|
|
if (plan.status === "missingTool") {
|
|
notifyMissingTool("run", plan);
|
|
return null;
|
|
}
|
|
const report = plan.report;
|
|
return {
|
|
launch: plan.launch,
|
|
finished: ({ stopped }) => {
|
|
if (stopped || !project.isCurrent()) return;
|
|
void (async () => {
|
|
try {
|
|
const data = await call(commands.coverageCollect(report));
|
|
if (!project.isCurrent()) return;
|
|
const suite = addSuite(config.name, data);
|
|
const totals = data.files.reduce((a, f) => [a[0]! + f.linesCovered, a[1]! + f.linesTotal], [0, 0]);
|
|
try {
|
|
toolWindowService().show("coverage");
|
|
} catch {
|
|
/* no workbench (tests) */
|
|
}
|
|
notifications().notify({
|
|
group: "run",
|
|
level: "info",
|
|
key: "coverage-done",
|
|
title: `Coverage of '${suite.name}': ${formatPercent(totals[0]!, totals[1]!)} lines`,
|
|
});
|
|
} catch (e) {
|
|
if (!project.isCurrent()) return;
|
|
notifications().notify({
|
|
group: "run",
|
|
level: "error",
|
|
key: "coverage-done",
|
|
title: `No coverage data for '${config.name}'`,
|
|
body: errorText(e),
|
|
});
|
|
}
|
|
})();
|
|
},
|
|
};
|
|
}
|
|
|
|
export const coverageExecutor: RunExecutorContribution = {
|
|
id: "coverage",
|
|
label: (name) => tx`Run '${name}' with Coverage`,
|
|
icon: "run-coverage",
|
|
action: "run.coverage",
|
|
order: 10,
|
|
supports: coverageSupports,
|
|
prepare,
|
|
};
|