diff --git a/crates/ide-language/src/lib.rs b/crates/ide-language/src/lib.rs index 5e1987b5ac..9cb4945ccb 100644 --- a/crates/ide-language/src/lib.rs +++ b/crates/ide-language/src/lib.rs @@ -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, /// 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(), diff --git a/src/bindings.ts b/src/bindings.ts index 291df8e168..45bbd9cf31 100644 --- a/src/bindings.ts +++ b/src/bindings.ts @@ -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). */ diff --git a/src/features/run/ConfigForm.tsx b/src/features/run/ConfigForm.tsx index 3b3aababc9..0786d238c4 100644 --- a/src/features/run/ConfigForm.tsx +++ b/src/features/run/ConfigForm.tsx @@ -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>([]); + 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)`), diff --git a/src/features/run/languageAdapters.test.tsx b/src/features/run/languageAdapters.test.tsx new file mode 100644 index 0000000000..7dbb76d3e8 --- /dev/null +++ b/src/features/run/languageAdapters.test.tsx @@ -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(); + return { ...real, commands: { ...real.commands, languages } }; +}); + +import { ConfigForm } from "./ConfigForm"; + +const cfg = (extra: Partial = {}): 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(); + 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( + , + ); + 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"); + }); +});