дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-05 09:41:34 +02:00
feat(run): offer the debug adapters of language definitions in run configurations (#7823)
* feat(run): offer the debug adapters of language definitions in run configurations The Debug adapter field of a run configuration listed only the built-in adapters. A language definition's `[debugger] adapter`, including one a plugin contributes, showed as "(no launch template)" when typed in by hand. `LanguageInfo` now carries the adapter, and the form offers it after the built-in ones. * fix(run): mark language debug adapter options verbatim and trim adapter ids --------- Co-authored-by: l0ng-ai <[email protected]>
Цей коміт міститься в:
1 джерело
2d3f81cf54
коміт
63ce54dc1e
4 files changed
+123
-5
No files matched your search
@@ -344,6 +344,10 @@ pub struct LanguageInfo {
|
||||
#[serde(default)]
|
||||
#[specta(optional)]
|
||||
pub debuggable: bool,
|
||||
/// The configured debug adapter (`[debugger] adapter`), offered for run configurations.
|
||||
#[serde(default)]
|
||||
#[specta(optional)]
|
||||
pub debug_adapter: Option<String>,
|
||||
/// Names of the configured language servers (Settings › Inspections).
|
||||
#[serde(default)]
|
||||
#[specta(optional)]
|
||||
@@ -377,6 +381,7 @@ impl From<&LanguageConfig> for LanguageInfo {
|
||||
block_comment: c.block_comment.clone(),
|
||||
indent: c.indent,
|
||||
debuggable: c.debugger.is_some(),
|
||||
debug_adapter: c.debugger.as_ref().map(|d| d.adapter.clone()),
|
||||
language_servers: c.language_servers.iter().map(|s| s.name.clone()).collect(),
|
||||
filenames: c.filenames.clone(),
|
||||
first_line: c.first_line.clone(),
|
||||
|
||||
@@ -12314,6 +12314,8 @@ export type LanguageInfo_Deserialize = {
|
||||
indent: IndentConfig_Deserialize | null,
|
||||
/** A debug adapter is configured (breakpoints make sense in these files). */
|
||||
debuggable?: boolean,
|
||||
/** The configured debug adapter (`[debugger] adapter`), offered for run configurations. */
|
||||
debugAdapter?: string | null,
|
||||
/** Names of the configured language servers (Settings › Inspections). */
|
||||
languageServers?: string[],
|
||||
/** Exact file names and file-name patterns of the definition (Settings › File Types). */
|
||||
@@ -12337,6 +12339,8 @@ export type LanguageInfo_Serialize = {
|
||||
indent: IndentConfig_Serialize | null,
|
||||
/** A debug adapter is configured (breakpoints make sense in these files). */
|
||||
debuggable?: boolean,
|
||||
/** The configured debug adapter (`[debugger] adapter`), offered for run configurations. */
|
||||
debugAdapter?: string | null,
|
||||
/** Names of the configured language servers (Settings › Inspections). */
|
||||
languageServers?: string[],
|
||||
/** Exact file names and file-name patterns of the definition (Settings › File Types). */
|
||||
|
||||
@@ -8,7 +8,7 @@ import { isJvmApplication, parseJavaArgs } from "@/platform/javaLaunch";
|
||||
import { useRunTargets } from "@/platform/pluginRunTargets";
|
||||
import { useEffect, useMemo, useRef, useState, type KeyboardEvent, type ReactNode, type RefObject } from "react";
|
||||
import clsx from "clsx";
|
||||
import { isTauri, type BuildPolicy, type RunConfig } from "@/platform/ipc";
|
||||
import { commands, isTauri, type BuildPolicy, type RunConfig } from "@/platform/ipc";
|
||||
import { useWorkflowSettings } from "@/platform/workflowSettings";
|
||||
import { relativePath, useProject } from "@/platform/project";
|
||||
import { isRemoteWindow } from "@/platform/remote";
|
||||
@@ -59,9 +59,9 @@ import styles from "./Run.module.css";
|
||||
|
||||
/**
|
||||
* Debug adapters with a real launch template (`debugger/launch.ts`, `debugger/java.ts`),
|
||||
* verified against small programs. Others (dart, …) only got
|
||||
* generic launch arguments and are left out until they have one; a configuration that
|
||||
* already names one keeps it.
|
||||
* verified against small programs. Other language-configured adapters are appended by
|
||||
* `useLanguageAdapters()` with generic launch arguments; a configuration that names
|
||||
* an unlisted adapter keeps it as "(no launch template)".
|
||||
*/
|
||||
const ADAPTERS: ReadonlyArray<{ id: string; label: string }> = [
|
||||
{ id: "netcoredbg", label: "netcoredbg (.NET)" },
|
||||
@@ -78,6 +78,36 @@ const ADAPTERS: ReadonlyArray<{ id: string; label: string }> = [
|
||||
{ id: "bun-dap", label: "bun-dap (Bun)" },
|
||||
];
|
||||
|
||||
/**
|
||||
* Adapters that other language definitions configure (`[debugger]`, including
|
||||
* languages plugins contribute), offered after `ADAPTERS`. They get generic launch
|
||||
* arguments: the adapter itself must make sense of them.
|
||||
*/
|
||||
function useLanguageAdapters(): ReadonlyArray<{ id: string; label: string }> {
|
||||
const [adapters, setAdapters] = useState<ReadonlyArray<{ id: string; label: string }>>([]);
|
||||
useEffect(() => {
|
||||
let live = true;
|
||||
Promise.resolve()
|
||||
.then(() => commands.languages())
|
||||
.then((languages) => {
|
||||
const seen = new Set(ADAPTERS.map((a) => a.id));
|
||||
const found: { id: string; label: string }[] = [];
|
||||
for (const l of languages) {
|
||||
const id = l.debugAdapter?.trim();
|
||||
if (!id || seen.has(id)) continue;
|
||||
seen.add(id);
|
||||
found.push({ id, label: `${id} (${l.name})` });
|
||||
}
|
||||
if (live) setAdapters(found);
|
||||
})
|
||||
.catch(() => {});
|
||||
return () => {
|
||||
live = false;
|
||||
};
|
||||
}, []);
|
||||
return adapters;
|
||||
}
|
||||
|
||||
/** Options "Modify options" adds to the form: value fields (shown once added) and flags (chips). */
|
||||
export type OptionId =
|
||||
| "allowParallel"
|
||||
@@ -327,6 +357,7 @@ export function ConfigForm({
|
||||
}: ConfigFormProps) {
|
||||
const openByDefault = useWorkflowSettings((s) => s.run.showOnStart);
|
||||
const runTargets = useRunTargets();
|
||||
const languageAdapters = useLanguageAdapters();
|
||||
const tx = useTx();
|
||||
const txTemplate = useTxTemplate();
|
||||
const root = useProject((s) => s.project?.root ?? null);
|
||||
@@ -419,8 +450,13 @@ export function ConfigForm({
|
||||
const adapterOptions: SelectOption[] = [
|
||||
{ value: "", label: "None" },
|
||||
...ADAPTERS.map((a) => ({ value: a.id, label: tx(a.label) })),
|
||||
...languageAdapters.map((a) => ({ value: a.id, label: a.label, verbatim: true })),
|
||||
];
|
||||
if (config.debugAdapter && !ADAPTERS.some((a) => a.id === config.debugAdapter))
|
||||
if (
|
||||
config.debugAdapter &&
|
||||
!ADAPTERS.some((a) => a.id === config.debugAdapter) &&
|
||||
!languageAdapters.some((a) => a.id === config.debugAdapter)
|
||||
)
|
||||
adapterOptions.push({
|
||||
value: config.debugAdapter,
|
||||
label: txTemplate(`${config.debugAdapter} (no launch template)`),
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { fireEvent, render, screen, within } from "@testing-library/react";
|
||||
import type { LanguageInfo, RunConfig } from "@/platform/ipc";
|
||||
|
||||
const languages = vi.hoisted(() => {
|
||||
const lang = (id: string, name: string, debugAdapter?: string): LanguageInfo => ({
|
||||
id,
|
||||
name,
|
||||
extensions: [],
|
||||
uiMode: null,
|
||||
lineComment: null,
|
||||
blockComment: null,
|
||||
indent: null,
|
||||
debuggable: !!debugAdapter,
|
||||
debugAdapter,
|
||||
});
|
||||
return vi.fn(async () => [
|
||||
lang("csharp", "C#", "netcoredbg"),
|
||||
lang("dotnet-mobile", ".NET Mobile", "mono-dap"),
|
||||
lang("toy", "Toy"),
|
||||
]);
|
||||
});
|
||||
|
||||
vi.mock("@/platform/ipc", async (importOriginal) => {
|
||||
const real = await importOriginal<typeof import("@/platform/ipc")>();
|
||||
return { ...real, commands: { ...real.commands, languages } };
|
||||
});
|
||||
|
||||
import { ConfigForm } from "./ConfigForm";
|
||||
|
||||
const cfg = (extra: Partial<RunConfig> = {}): RunConfig => ({
|
||||
id: "app",
|
||||
name: "app",
|
||||
kind: "shell",
|
||||
command: "x",
|
||||
args: [],
|
||||
cwd: null,
|
||||
env: {},
|
||||
detected: false,
|
||||
isTest: false,
|
||||
debugAdapter: null,
|
||||
...extra,
|
||||
});
|
||||
|
||||
describe("Debug adapter of the configuration form", () => {
|
||||
it("offers the adapters language definitions configure", async () => {
|
||||
const onChange = vi.fn();
|
||||
render(<ConfigForm config={cfg()} all={[]} type={undefined} errors={{}} onChange={onChange} modifyRequest={0} />);
|
||||
fireEvent.click(screen.getByRole("button", { name: "Debug adapter" }));
|
||||
const list = screen.getByRole("listbox");
|
||||
const mono = await within(list).findByRole("option", { name: "mono-dap (.NET Mobile)" });
|
||||
// Built-in adapters keep their own label, once.
|
||||
expect(within(list).getAllByRole("option", { name: /^netcoredbg/ })).toHaveLength(1);
|
||||
fireEvent.click(mono);
|
||||
expect(onChange).toHaveBeenCalledWith(expect.objectContaining({ debugAdapter: "mono-dap" }));
|
||||
});
|
||||
|
||||
it("names a configured language adapter instead of flagging it as unknown", async () => {
|
||||
render(
|
||||
<ConfigForm
|
||||
config={cfg({ debugAdapter: "mono-dap" })}
|
||||
all={[]}
|
||||
type={undefined}
|
||||
errors={{}}
|
||||
onChange={vi.fn()}
|
||||
modifyRequest={0}
|
||||
/>,
|
||||
);
|
||||
const select = screen.getByRole("button", { name: "Debug adapter" });
|
||||
await vi.waitFor(() => expect(select.textContent).toContain("mono-dap (.NET Mobile)"));
|
||||
expect(select.textContent).not.toContain("no launch template");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Заблокувати користувача