diff --git a/rust/contracts/rust-core-api.md b/rust/contracts/rust-core-api.md index 41326456..983f4cde 100644 --- a/rust/contracts/rust-core-api.md +++ b/rust/contracts/rust-core-api.md @@ -4132,11 +4132,13 @@ containing `target.path` when the configuration binds it to `target.directory` (an adapter such as Delve that builds a package; a path without a directory is `debug.target.invalid` with `field: "target.path"`); or from `target.executable` (an absolute path the host found) when the configuration -binds it to `target.executable`. Each `adapterArguments` path is filled the +binds it to `target.executable`. `cwd` is filled from `target.workingDirectory`, +or from the directory containing `target.path` when the configuration binds it +to `target.directory`. Each `adapterArguments` path is filled the same way, from `target.path`, the directory containing it (`target.directory`) or `target.workingDirectory`, after `env`, so `env.` adds a variable to the bound environment and leaves one the target sets; a target without the -fact is +fact a `cwd` or `adapterArguments` binding reads is `debug.target.invalid` with `field: "target.path"` or `"target.workingDirectory"`. Refusals use the `rejected` shape with `debug.provider.stale`, `debug.request.unsupported`, `debug.runtime.stale`, or diff --git a/rust/crates/core/src/tests/declarative_plugins.rs b/rust/crates/core/src/tests/declarative_plugins.rs index 3a153314..0659afb5 100644 --- a/rust/crates/core/src/tests/declarative_plugins.rs +++ b/rust/crates/core/src/tests/declarative_plugins.rs @@ -2181,10 +2181,12 @@ fn debug_start_arguments_fill_adapter_arguments_from_path_facts() { ("/work", "/work/cmd/app/main.go", "/work/cmd/app") }; // Delve's shape: it builds in `dlvCwd`, not in its own working directory, - // and runs the program there when `cwd` is left out. + // and runs the program in `cwd`, which the debug engine sets to the + // workspace root when nothing binds it. let mut manifest = fixture("debug-adapter.plugin.json"); manifest["debugAdapters"][0]["configurations"]["launch"]["targetBindings"] = json!({ "program": "target.directory", + "cwd": "target.directory", "adapterArguments": { "dlvCwd": "target.directory", "file": "target.path", @@ -2210,6 +2212,7 @@ fn debug_start_arguments_fill_adapter_arguments_from_path_facts() { json!({ "stopOnEntry": false, "program": directory, + "cwd": directory, "dlvCwd": directory, "file": path, "root": root, @@ -2229,6 +2232,61 @@ fn debug_start_arguments_fill_adapter_arguments_from_path_facts() { ); } +#[test] +fn debug_start_arguments_bind_cwd_to_the_directory_of_the_target() { + let (root, path, directory) = if cfg!(windows) { + (r"C:\work", r"C:\work\lab\main.go", r"C:\work\lab") + } else { + ("/work", "/work/lab/main.go", "/work/lab") + }; + let start = |cwd: &str, target: Value| { + let mut manifest = fixture("debug-adapter.plugin.json"); + manifest["debugAdapters"][0]["configurations"]["launch"]["targetBindings"] = + json!({ "cwd": cwd }); + lithe_plugin_manifest::debug_start_arguments_command(json!({ + "manifest": manifest, + "adapterID": "example", + "request": "launch", + "facts": { + "registration": { "generation": 3, "currentGeneration": 3 }, + "target": target, + }, + })) + .expect("payload is well formed") + }; + let target = json!({ "kind": "file", "path": path, "workingDirectory": root }); + for (cwd, expected) in [ + ("target.directory", directory), + ("target.workingDirectory", root), + ] { + let launch = start(cwd, target.clone()); + assert_eq!(launch["status"], "ok", "{launch}"); + assert_eq!(launch["arguments"]["cwd"], expected, "{cwd}: {launch}"); + } + + // A bare file name has no directory to run in, and a target without a + // working directory has none either; both are refused before the start. + for (cwd, target, field) in [ + ( + "target.directory", + json!({ "kind": "file", "path": "main.go", "workingDirectory": root }), + "target.path", + ), + ( + "target.workingDirectory", + json!({ "kind": "file", "path": path }), + "target.workingDirectory", + ), + ] { + let refused = start(cwd, target); + assert_eq!( + refused["error"]["code"], "debug.target.invalid", + "{refused}" + ); + assert_eq!(refused["error"]["field"], field, "{refused}"); + } +} + #[test] fn debug_start_arguments_add_an_adapter_argument_to_the_environment() { let (root, path, directory) = if cfg!(windows) { diff --git a/rust/crates/debug/src/adapters/declaration.rs b/rust/crates/debug/src/adapters/declaration.rs index 78eeface..e3a61e47 100644 --- a/rust/crates/debug/src/adapters/declaration.rs +++ b/rust/crates/debug/src/adapters/declaration.rs @@ -152,7 +152,9 @@ pub struct DebugTargetBindings { /// Source of the `processId` argument: only `target.processID`. Attach only. #[serde(default, skip_serializing_if = "Option::is_none")] pub process_id: Option, - /// Source of the `cwd` argument: only `target.workingDirectory`. + /// Source of the `cwd` argument: `target.workingDirectory`, or + /// `target.directory` (the directory containing `target.path`) for an + /// adapter whose program runs where its package is, such as Delve. #[serde(default, skip_serializing_if = "Option::is_none")] pub cwd: Option, /// Where a remote `host:port` goes. Attach only. diff --git a/rust/crates/debug/src/adapters/plan.rs b/rust/crates/debug/src/adapters/plan.rs index 8742b9f4..5621309c 100644 --- a/rust/crates/debug/src/adapters/plan.rs +++ b/rust/crates/debug/src/adapters/plan.rs @@ -147,15 +147,12 @@ pub fn plan( if bindings.process_id.is_some() && target.process_id.is_none() { return Err(missing("target.processID", "process ID")); } - if bindings.cwd.is_some() - && target - .working_directory - .as_deref() - .is_none_or(str::is_empty) + // `cwd` and the adapter's own arguments all read path facts. + for fact in bindings + .cwd + .iter() + .chain(bindings.adapter_arguments.iter().flat_map(BTreeMap::values)) { - return Err(missing("target.workingDirectory", "working directory")); - } - for fact in bindings.adapter_arguments.iter().flat_map(BTreeMap::values) { if path_fact(target, fact).is_some() { continue; } diff --git a/rust/crates/debug/src/adapters/start.rs b/rust/crates/debug/src/adapters/start.rs index 1aab0b36..c94f489b 100644 --- a/rust/crates/debug/src/adapters/start.rs +++ b/rust/crates/debug/src/adapters/start.rs @@ -167,7 +167,11 @@ fn bound_arguments( bind( "cwd", &bindings.cwd, - target.working_directory.clone().map(Value::from), + bindings + .cwd + .as_deref() + .and_then(|fact| path_fact(target, fact)) + .map(Value::from), ); bind( "args", @@ -205,8 +209,8 @@ pub(crate) fn target_directory(path: &str) -> Option<&str> { .filter(|directory| !directory.is_empty()) } -/// The value of a path fact an `adapterArguments` binding reads, or `None` -/// when the target does not carry it. +/// The value of a path fact a `cwd` or `adapterArguments` binding reads, or +/// `None` when the target does not carry it. pub(crate) fn path_fact<'a>(target: &'a TargetFacts, fact: &str) -> Option<&'a str> { let present = |value: &'a Option| value.as_deref().filter(|value| !value.is_empty()); match fact { diff --git a/rust/crates/debug/src/adapters/validate_configuration.rs b/rust/crates/debug/src/adapters/validate_configuration.rs index c4f082bf..66722bc2 100644 --- a/rust/crates/debug/src/adapters/validate_configuration.rs +++ b/rust/crates/debug/src/adapters/validate_configuration.rs @@ -73,7 +73,11 @@ impl DebugConfiguration { &["target.path", TARGET_DIRECTORY, TARGET_EXECUTABLE][..], ), ("processId", &bindings.process_id, &["target.processID"][..]), - ("cwd", &bindings.cwd, &["target.workingDirectory"][..]), + ( + "cwd", + &bindings.cwd, + &["target.workingDirectory", TARGET_DIRECTORY][..], + ), ("args", &bindings.args, &["target.arguments"][..]), ("env", &bindings.env, &["target.environment"][..]), ] { diff --git a/shared/plugins/contract/v1/README.md b/shared/plugins/contract/v1/README.md index b56dc442..700d6f99 100644 --- a/shared/plugins/contract/v1/README.md +++ b/shared/plugins/contract/v1/README.md @@ -2350,8 +2350,8 @@ adapter serves `attach`), and one `onDebug:` activation event per adapter. | `requests` | `launch` (default) and/or `attach`. | | `selectors[]` | Optional automatic matching by `targetKinds` and `languageIDs`; absent means explicit selection only. | | `configurationTypes` | Imported `launch.json` `type` values the adapter answers to. | -| `configurations.launch/attach` | Default DAP `arguments`, a packaged `parametersSchema`, and `targetBindings` (`program` ← `target.path`, or ← `target.directory`, the directory containing `target.path`, for an adapter that debugs a package such as Delve, `processId` ← `target.processID`, `cwd` ← `target.workingDirectory`, and for `attach` only `connection` ← `target.host`, `target.port`, `target.pathMappings`; also bounded `args` ← `target.arguments` and `env` ← `target.environment`; see [Remote attach](#remote-attach)). A configuration for an undeclared request is refused. | -| `targetBindings.adapterArguments` | Up to 8 DAP arguments only this adapter defines, as `{"": ""}` with the fact `target.path`, `target.directory` or `target.workingDirectory`. A path is dotted like a `connection` destination: up to 4 names, each a letter or `_` followed by up to 63 letters, digits, `_` or `-`, and objects on the way are created. For example Delve builds the program in `dlvCwd`, not in its own working directory, which the host sets to the workspace root, and `go build` reads the directory from `PWD`, which Delve leaves at that root; so a Go plugin binds `{"dlvCwd": "target.directory", "env.PWD": "target.directory"}`. Inside `env` a path names one variable and adds it to the environment the configuration or the `env` binding gives; elsewhere a path may not start at `program`, `processId`, `cwd`, `args` or `env`, which have their own bindings, or at `noDebug` or a `__` name, which belong to the host. Two paths may not overlap, nor a path and a `connection` destination, and a path may not land on or under a value the configuration's own `arguments` set, which the binding could never fill. Like every binding it fills the argument only when nothing holds it, so a variable the target's environment sets stays, and a target without the fact is refused with `debug.target.invalid`. | +| `configurations.launch/attach` | Default DAP `arguments`, a packaged `parametersSchema`, and `targetBindings` (`program` ← `target.path`, or ← `target.directory`, the directory containing `target.path`, for an adapter that debugs a package such as Delve, `processId` ← `target.processID`, `cwd` ← `target.workingDirectory`, or ← `target.directory` for an adapter whose program runs where its package is, and for `attach` only `connection` ← `target.host`, `target.port`, `target.pathMappings`; also bounded `args` ← `target.arguments` and `env` ← `target.environment`; see [Remote attach](#remote-attach)). A configuration for an undeclared request is refused. | +| `targetBindings.adapterArguments` | Up to 8 DAP arguments only this adapter defines, as `{"": ""}` with the fact `target.path`, `target.directory` or `target.workingDirectory`. A path is dotted like a `connection` destination: up to 4 names, each a letter or `_` followed by up to 63 letters, digits, `_` or `-`, and objects on the way are created. For example Delve builds the program in `dlvCwd`, not in its own working directory, which the host sets to the workspace root, and `go build` reads the directory from `PWD`, which Delve leaves at that root; so a Go plugin binds `{"dlvCwd": "target.directory", "env.PWD": "target.directory"}` here, and `cwd` ← `target.directory` so the program also runs in its package directory rather than in the workspace root the debug engine gives a launch without `cwd`. Inside `env` a path names one variable and adds it to the environment the configuration or the `env` binding gives; elsewhere a path may not start at `program`, `processId`, `cwd`, `args` or `env`, which have their own bindings, or at `noDebug` or a `__` name, which belong to the host. Two paths may not overlap, nor a path and a `connection` destination, and a path may not land on or under a value the configuration's own `arguments` set, which the binding could never fill. Like every binding it fills the argument only when nothing holds it, so a variable the target's environment sets stays, and a target without the fact is refused with `debug.target.invalid`. | | `configurations.launch.executable` | For a target that is a source file the adapter cannot debug directly (C, C++, Swift): `setting` names a `file` setting of the plugin, `candidates[]` (up to 8) are the paths a host looks for when the user chose nothing. Each candidate starts with `${workspaceFolder}/` or `${fileDirectory}/`, may use `${fileBasenameNoExtension}`, and has no `..`. Declare it together with `targetBindings.program: "target.executable"` and neither without the other; a launch fills `program` with the path the host settled on. The user's setting always wins: a chosen path that is not a runnable file is an error, not a reason to try the candidates. The host shows the path it found in that setting, and the setting's `description` is where the plugin teaches how to produce the program. | | `capabilities.disabled` | Standard DAP `supports*` names or `exceptionBreakpointFilters` the host treats as absent. | | `features` | Adapter-specific DAP extensions the adapter implements; see [Adapter features and defaults](#adapter-features-and-defaults). | diff --git a/shared/plugins/contract/v1/fixtures/debug-adapters/debug-adapter-rejections.json b/shared/plugins/contract/v1/fixtures/debug-adapters/debug-adapter-rejections.json index ac9b2cfb..b9d986ea 100644 --- a/shared/plugins/contract/v1/fixtures/debug-adapters/debug-adapter-rejections.json +++ b/shared/plugins/contract/v1/fixtures/debug-adapters/debug-adapter-rejections.json @@ -81,6 +81,12 @@ "edits": [{"op": "set", "path": "/block/debugAdapters/0/configurations", "value": {"launch": {"targetBindings": {"program": "target.processID"}}}}], "expected": {"code": "plugin.manifest.invalid", "field": "debugAdapters[0].configurations.launch.targetBindings.program"} }, + { + "id": "cwd-from-target-path", + "layer": "schema", + "edits": [{"op": "set", "path": "/block/debugAdapters/0/configurations", "value": {"launch": {"targetBindings": {"cwd": "target.path"}}}}], + "expected": {"code": "plugin.manifest.invalid", "field": "debugAdapters[0].configurations.launch.targetBindings.cwd"} + }, { "id": "function-for-step-back", "layer": "schema", diff --git a/shared/plugins/contract/v1/plugin-manifest.schema.json b/shared/plugins/contract/v1/plugin-manifest.schema.json index 40e68447..4b00c597 100644 --- a/shared/plugins/contract/v1/plugin-manifest.schema.json +++ b/shared/plugins/contract/v1/plugin-manifest.schema.json @@ -698,7 +698,8 @@ "const": "target.processID" }, "cwd": { - "const": "target.workingDirectory" + "description": "`target.workingDirectory` is the working directory. `target.directory` is the directory containing `target.path`, for adapters whose program runs where its package is.", + "enum": ["target.workingDirectory", "target.directory"] }, "args": { "const": "target.arguments" }, "env": { "const": "target.environment" }, diff --git a/shared/plugins/guides/debug-adapter-plugin.md b/shared/plugins/guides/debug-adapter-plugin.md index e64574db..c9adbf61 100644 --- a/shared/plugins/guides/debug-adapter-plugin.md +++ b/shared/plugins/guides/debug-adapter-plugin.md @@ -72,7 +72,7 @@ - `selectors` 决定 Lithe 在哪些目标上自动选这个适配器:`targetKinds` 是目标种类,`languageIDs` 是语言。不写 `selectors` 表示只能被用户显式选择。 - `languages[]` 声明适配器服务的语言。如果这个语言已经由别的插件提供(例如 Rust),你的声明只会给它增加“可以调试”的能力,并并入你声明的文件扩展名;语言名、语言标识和语言服务器不变,装上调试器也不会重启正在运行的语言服务器。 - `targetBindings` 把调试目标的事实填进适配器的启动参数:`program` ← 目标路径(`target.path`),或目标所在目录(`target.directory`,Delve 这类按包构建再调试的适配器用它),`cwd` ← 工作目录,`processId` ← 进程 ID。只填 `arguments` 里没写的字段,不会覆盖你显式写出的默认值。目标缺少绑定要读的事实时,Lithe 会拒绝这次启动并说明缺什么。 -- 适配器自己定义的参数用 `targetBindings.adapterArguments`,键是参数路径,写法和 `connection` 的目标一样用点分隔,值是 `target.path`、`target.directory` 或 `target.workingDirectory`。例如 Delve 在 `dlvCwd` 里编译程序,而不是在它自己的工作目录(宿主设为工作区根目录)里编译;`go build` 又从 `PWD` 读当前目录,Delve 切换目录后不会改它。所以 Go 插件写 `"adapterArguments": { "dlvCwd": "target.directory", "env.PWD": "target.directory" }`,工作区根目录没有 `go.mod`、一个工作区里放了好几个模块、路径经过符号链接时,都在包所在的目录里编译。`env.<变量名>` 只往环境里加一个变量,`arguments` 的 `env` 和 `env` 绑定给的变量都保留,目标环境自己设了同名变量时以目标的为准。最多 8 个参数;路径不能从 `program`、`processId`、`cwd`、`args`、`env` 本身开始(它们有自己的绑定),不能从 `noDebug` 或 `__` 开头的名字开始(归宿主所有),路径之间、路径和 `connection` 的目标之间不能重叠,也不能落在 `arguments` 已经写了的值上或它的下面。 +- 适配器自己定义的参数用 `targetBindings.adapterArguments`,键是参数路径,写法和 `connection` 的目标一样用点分隔,值是 `target.path`、`target.directory` 或 `target.workingDirectory`。例如 Delve 在 `dlvCwd` 里编译程序,而不是在它自己的工作目录(宿主设为工作区根目录)里编译;`go build` 又从 `PWD` 读当前目录,Delve 切换目录后不会改它。所以 Go 插件写 `"adapterArguments": { "dlvCwd": "target.directory", "env.PWD": "target.directory" }`,工作区根目录没有 `go.mod`、一个工作区里放了好几个模块、路径经过符号链接时,都在包所在的目录里编译。被调程序在 `cwd` 里运行;launch 没有 `cwd` 时调试引擎填工作区根目录,所以 Go 插件同时写 `"cwd": "target.directory"`,程序按相对路径读的文件从包目录算起。`env.<变量名>` 只往环境里加一个变量,`arguments` 的 `env` 和 `env` 绑定给的变量都保留,目标环境自己设了同名变量时以目标的为准。最多 8 个参数;路径不能从 `program`、`processId`、`cwd`、`args`、`env` 本身开始(它们有自己的绑定),不能从 `noDebug` 或 `__` 开头的名字开始(归宿主所有),路径之间、路径和 `connection` 的目标之间不能重叠,也不能落在 `arguments` 已经写了的值上或它的下面。 - `configurationTypes` 声明适配器对应的 `launch.json` `type`,用于导入用户已有的 VS Code 风格配置。 ### 3. 怎么启动适配器 @@ -270,7 +270,7 @@ Key points: - `selectors` decide on which targets Lithe picks this adapter automatically: `targetKinds` are target kinds and `languageIDs` are languages. Without `selectors`, the adapter can only be chosen explicitly by the user. - `languages[]` declares the languages the adapter serves. If another plugin already provides the language (for example Rust), your declaration only adds the ability to debug it and merges in the file extensions you declare; the language name, language ID, and language server stay the same, and installing the debugger does not restart a running language server. - `targetBindings` fills facts about the debug target into the adapter's launch arguments: `program` ← the target path (`target.path`) or the directory containing it (`target.directory`, for an adapter such as Delve that builds and debugs a package), `cwd` ← the working directory, `processId` ← the process ID. Only fields missing from `arguments` are filled; defaults you wrote explicitly are never overwritten. When the target lacks a fact a binding reads, Lithe refuses the launch and says what is missing. -- Arguments the adapter defines itself go in `targetBindings.adapterArguments`: each key is an argument path, dotted like a `connection` destination, and each value is `target.path`, `target.directory` or `target.workingDirectory`. Delve, for example, builds the program in `dlvCwd`, not in its own working directory (which the host sets to the workspace root), and `go build` reads the current directory from `PWD`, which Delve leaves unchanged when it switches. So a Go plugin writes `"adapterArguments": { "dlvCwd": "target.directory", "env.PWD": "target.directory" }`, and the build runs in the package's directory when the workspace root has no `go.mod`, when one workspace holds several modules, and when the path passes a symbolic link. `env.` adds one variable: those from the `env` in `arguments` and from the `env` binding stay, and a variable the target's environment sets itself keeps the target's value. Up to 8 arguments; a path may not start at `program`, `processId`, `cwd`, `args` or `env` itself (they have their own bindings) or at `noDebug` or a `__` name (they belong to the host), may not overlap another path or a `connection` destination, and may not land on or under a value already in `arguments`. +- Arguments the adapter defines itself go in `targetBindings.adapterArguments`: each key is an argument path, dotted like a `connection` destination, and each value is `target.path`, `target.directory` or `target.workingDirectory`. Delve, for example, builds the program in `dlvCwd`, not in its own working directory (which the host sets to the workspace root), and `go build` reads the current directory from `PWD`, which Delve leaves unchanged when it switches. So a Go plugin writes `"adapterArguments": { "dlvCwd": "target.directory", "env.PWD": "target.directory" }`, and the build runs in the package's directory when the workspace root has no `go.mod`, when one workspace holds several modules, and when the path passes a symbolic link. The program runs in `cwd`, which the debug engine sets to the workspace root for a launch without one, so the Go plugin also writes `"cwd": "target.directory"` and paths the program opens relative to its directory resolve from the package directory. `env.` adds one variable: those from the `env` in `arguments` and from the `env` binding stay, and a variable the target's environment sets itself keeps the target's value. Up to 8 arguments; a path may not start at `program`, `processId`, `cwd`, `args` or `env` itself (they have their own bindings) or at `noDebug` or a `__` name (they belong to the host), may not overlap another path or a `connection` destination, and may not land on or under a value already in `arguments`. - `configurationTypes` declares the `launch.json` `type` values the adapter matches, used to import the user's existing VS Code-style configurations. ### 3. Launching the adapter diff --git a/shared/plugins/reference/domains/debug-adapters.md b/shared/plugins/reference/domains/debug-adapters.md index 796d394d..796a2d82 100644 --- a/shared/plugins/reference/domains/debug-adapters.md +++ b/shared/plugins/reference/domains/debug-adapters.md @@ -54,8 +54,8 @@ | 声明 | 说明 | | --- | --- | -| `configurations.launch`、`configurations.attach` | 默认 DAP `arguments`、包内的 `parametersSchema` 和 `targetBindings`:`program` ← `target.path`(或 ← `target.directory`,即 `target.path` 所在目录,供 Delve 这类按包调试的适配器使用)、`processId` ← `target.processID`、`cwd` ← `target.workingDirectory`,以及有界的 `args` ← `target.arguments`、`env` ← `target.environment`;只有 `attach` 能绑定 `connection`。为未声明的请求写配置会被拒绝 | -| `targetBindings.adapterArguments` | 最多 8 个只有这个适配器才有的 DAP 参数,写成 `{"<参数路径>": "<事实>"}`,事实是 `target.path`、`target.directory` 或 `target.workingDirectory`。路径和 `connection` 的目标一样用点分隔,最多 4 段,每段以字母或 `_` 开头,其余是字母、数字、`_` 或 `-`,最长 64 个字符,途经的对象会自动创建。例如 Delve 在 `dlvCwd` 里编译程序、`go build` 从 `PWD` 读当前目录,Go 插件绑定 `{"dlvCwd": "target.directory", "env.PWD": "target.directory"}`。`env.<变量名>` 只往环境里加一个变量;其他路径不能从 `program`、`processId`、`cwd`、`args`、`env` 本身开始(有自己的绑定),不能从 `noDebug` 或 `__` 开头的名字开始(归宿主所有)。路径之间、路径和 `connection` 的目标之间不能重叠,也不能落在 `arguments` 已经写了的值上或它的下面。只在没有值时填入,目标环境自己设的同名变量保留;目标缺少要读的事实时以 `debug.target.invalid` 拒绝 | +| `configurations.launch`、`configurations.attach` | 默认 DAP `arguments`、包内的 `parametersSchema` 和 `targetBindings`:`program` ← `target.path`(或 ← `target.directory`,即 `target.path` 所在目录,供 Delve 这类按包调试的适配器使用)、`processId` ← `target.processID`、`cwd` ← `target.workingDirectory`(或 ← `target.directory`,供程序要在包所在目录运行的适配器使用),以及有界的 `args` ← `target.arguments`、`env` ← `target.environment`;只有 `attach` 能绑定 `connection`。为未声明的请求写配置会被拒绝 | +| `targetBindings.adapterArguments` | 最多 8 个只有这个适配器才有的 DAP 参数,写成 `{"<参数路径>": "<事实>"}`,事实是 `target.path`、`target.directory` 或 `target.workingDirectory`。路径和 `connection` 的目标一样用点分隔,最多 4 段,每段以字母或 `_` 开头,其余是字母、数字、`_` 或 `-`,最长 64 个字符,途经的对象会自动创建。例如 Delve 在 `dlvCwd` 里编译程序、`go build` 从 `PWD` 读当前目录,Go 插件绑定 `{"dlvCwd": "target.directory", "env.PWD": "target.directory"}`,再把 `cwd` 绑到 `target.directory`,程序也在包目录运行。`env.<变量名>` 只往环境里加一个变量;其他路径不能从 `program`、`processId`、`cwd`、`args`、`env` 本身开始(有自己的绑定),不能从 `noDebug` 或 `__` 开头的名字开始(归宿主所有)。路径之间、路径和 `connection` 的目标之间不能重叠,也不能落在 `arguments` 已经写了的值上或它的下面。只在没有值时填入,目标环境自己设的同名变量保留;目标缺少要读的事实时以 `debug.target.invalid` 拒绝 | | `configurations.launch.executable` | 目标是适配器不能直接调试的源文件(C、C++、Swift)时:`setting` 指向插件的 `file` 设置,最多 8 个 `candidates[]`(以 `${workspaceFolder}/` 或 `${fileDirectory}/` 开头,不含 `..`)是用户没选时宿主查找的路径。必须与 `targetBindings.program: "target.executable"` 一起声明。用户在设置里选的路径永远优先,不是可运行文件就报错,不会改试候选 | | `capabilities.disabled` | 宿主视为不存在的标准 DAP `supports*` 名称或 `exceptionBreakpointFilters` | | `console.commandPrefix` | 1–8 个字符、不含空格的文本(lldb-dap 用反引号),适配器控制台把它读作“后面是调试器命令”;宿主只在请求补全时把它放在输入行前面,并把适配器的回答移回来,用户看不到 | @@ -193,8 +193,8 @@ Names (`request`, `event`, fields, `argument`) are a letter followed by up to 63 | Declaration | Notes | | --- | --- | -| `configurations.launch`, `configurations.attach` | Default DAP `arguments`, a packaged `parametersSchema`, and `targetBindings`: `program` ← `target.path` (or ← `target.directory`, the directory containing `target.path`, for an adapter that debugs a package such as Delve), `processId` ← `target.processID`, `cwd` ← `target.workingDirectory`, plus bounded `args` ← `target.arguments` and `env` ← `target.environment`; only `attach` may bind `connection`. A configuration for an undeclared request is refused | -| `targetBindings.adapterArguments` | Up to 8 DAP arguments only this adapter defines, as `{"": ""}` with the fact `target.path`, `target.directory` or `target.workingDirectory`. A path is dotted like a `connection` destination, up to 4 names, each a letter or `_` followed by up to 63 letters, digits, `_` or `-`, and objects on the way are created. Delve, for example, builds the program in `dlvCwd` and `go build` reads the current directory from `PWD`, so a Go plugin binds `{"dlvCwd": "target.directory", "env.PWD": "target.directory"}`. `env.` adds one variable to the environment; any other path may not start at `program`, `processId`, `cwd`, `args` or `env` itself (they have their own bindings) or at `noDebug` or a `__` name (they belong to the host). Two paths may not overlap, nor a path and a `connection` destination, and a path may not land on or under a value already in `arguments`. It is filled only when nothing holds it, so a variable the target's environment sets stays; a target without the fact is refused with `debug.target.invalid` | +| `configurations.launch`, `configurations.attach` | Default DAP `arguments`, a packaged `parametersSchema`, and `targetBindings`: `program` ← `target.path` (or ← `target.directory`, the directory containing `target.path`, for an adapter that debugs a package such as Delve), `processId` ← `target.processID`, `cwd` ← `target.workingDirectory` (or ← `target.directory`, for an adapter whose program runs where its package is), plus bounded `args` ← `target.arguments` and `env` ← `target.environment`; only `attach` may bind `connection`. A configuration for an undeclared request is refused | +| `targetBindings.adapterArguments` | Up to 8 DAP arguments only this adapter defines, as `{"": ""}` with the fact `target.path`, `target.directory` or `target.workingDirectory`. A path is dotted like a `connection` destination, up to 4 names, each a letter or `_` followed by up to 63 letters, digits, `_` or `-`, and objects on the way are created. Delve, for example, builds the program in `dlvCwd` and `go build` reads the current directory from `PWD`, so a Go plugin binds `{"dlvCwd": "target.directory", "env.PWD": "target.directory"}`, and `cwd` ← `target.directory` so the program runs there too. `env.` adds one variable to the environment; any other path may not start at `program`, `processId`, `cwd`, `args` or `env` itself (they have their own bindings) or at `noDebug` or a `__` name (they belong to the host). Two paths may not overlap, nor a path and a `connection` destination, and a path may not land on or under a value already in `arguments`. It is filled only when nothing holds it, so a variable the target's environment sets stays; a target without the fact is refused with `debug.target.invalid` | | `configurations.launch.executable` | For a target that is a source file the adapter cannot debug directly (C, C++, Swift): `setting` names a `file` setting of the plugin, and up to 8 `candidates[]` (starting with `${workspaceFolder}/` or `${fileDirectory}/`, no `..`) are the paths the host looks for when the user chose nothing. Declare it together with `targetBindings.program: "target.executable"`. The path the user chose in the setting always wins: if it is not a runnable file that is an error, and the candidates are not tried instead | | `capabilities.disabled` | Standard DAP `supports*` names or `exceptionBreakpointFilters` the host treats as absent | | `console.commandPrefix` | Text of 1–8 characters without spaces (a backtick for lldb-dap) that the adapter's console reads as "what follows is a debugger command"; the host puts it before the typed line only when asking for completions and moves the adapter's answer back, so the user never sees it | diff --git a/shared/plugins/reference/protocol-changelog.md b/shared/plugins/reference/protocol-changelog.md index 4abf621f..0d20e4d7 100644 --- a/shared/plugins/reference/protocol-changelog.md +++ b/shared/plugins/reference/protocol-changelog.md @@ -134,6 +134,7 @@ | PR | 修改人 | API 编号 | 协议 / 能力 | 改了什么 | | --- | --- | --- | --- | --- | +| [#56](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/56) | [@xiaoyumuxi](https://github.com/xiaoyumuxi) | API-30 | `debugAdapters` 0 内的补充 | `targetBindings.cwd` 除了 `target.workingDirectory`,也可以绑到 `target.directory`(源文件所在目录)。调试引擎在 launch 参数缺 `cwd` 时会填工作区根目录;Go 插件绑定 `cwd` ← `target.directory` 后,被调程序在包目录运行,按包目录写的相对路径能读到。其他值以 `plugin.manifest.invalid`(字段 `targetBindings.cwd`)拒绝;目标路径是裸文件名、取不出目录时以 `debug.target.invalid`(字段 `target.path`)拒绝。只是可选取值,不需要新能力版本。 | | [#55](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/55) | [@xiaoyumuxi](https://github.com/xiaoyumuxi) | API-30 | `debugAdapters` 0 内的补充 | `targetBindings` 新增 `adapterArguments`:最多 8 个只有这个适配器才有的 DAP 参数,`{"<参数路径>": "<事实>"}`,路径和 `connection` 的目标一样用点分隔、最多 4 段,事实只能是 `target.path`、`target.directory` 或 `target.workingDirectory`,和其他绑定一样只在没有值时填入。`env.<变量名>` 往环境里加一个变量,`arguments` 和 `env` 绑定给的变量都保留。例如 Delve 在 `dlvCwd` 里编译程序,不在宿主给它的工作目录(工作区根目录)里编译,`go build` 又从 `PWD` 读当前目录;Go 插件绑定 `dlvCwd` 和 `env.PWD` ← `target.directory` 后,工作区根目录没有 `go.mod`、一个工作区放了多个模块、路径经过符号链接时都能调试。路径不能从 `program`、`processId`、`cwd`、`args`、`env` 本身、`noDebug`、`__` 开头的名字开始,路径之间、路径和 `connection` 的目标之间不能重叠,也不能落在 `arguments` 已有的值上或它的下面,违反时以 `plugin.manifest.invalid`(字段 `targetBindings.adapterArguments[.<参数路径>]`)拒绝;目标缺少事实时以 `debug.target.invalid`(字段 `target.path` 或 `target.workingDirectory`)拒绝。只是可选字段,不需要新能力版本。 | | [#53](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/53) | [@xiaoyumuxi](https://github.com/xiaoyumuxi) | API-23 | **`commandInstallers` 0** | 新能力 `commandInstallers` 和权限 `commands.install`:清单顶层 `commandInstallers[]` 声明怎样用插件已依赖的工具(`requiresTools`)安装 `systemCommand` 启动缺的裸命令,例如用 `go install` 装 `dlv`。每个安装声明 `commands`、`tool`、`minimumVersion?`、字面量 `arguments`、`mayUseNetwork`、`timeoutSeconds?`(1–3600,默认 600)和至少一个目标:`managed` 装进宿主为插件管理的目录,参数或环境变量必须用唯一的模板变量 `${installDirectory}`,`commandDirectory` 指命令所在的子目录;`toolDefault` 装到工具默认位置,`directory` 最多 4 个探针,按顺序运行同一工具,从输出读目录(`pathList`、`append`)。新增宿主命令 `plugins.commandInstallers.requirements`、`plan`、`defaultDirectory` 和错误码 `plugin.commandInstaller.unknown`、`targetUndeclared`、`directoryInvalid`、`probeOutputsInvalid`(Core),以及宿主报告的 `plugin.command.missing`、`plugin.commandInstaller.failed`、`timedOut`、`commandsMissing`。安装声明进入安装审查(`kind: "commandInstaller"`)。宿主只在用户确认命令行、网络和目标后安装,每次安装用 `diagnostics.recordPluginOperation` 记一条 `commandInstaller/install`(命令执行生命周期,安装后命令仍缺记 `decode`)。 | | [#52](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/52) | [@xiaoyumuxi](https://github.com/xiaoyumuxi) | API-23 | `toolDefinitions` 0 内的补充 | 工具定义的版本探针 `version.arguments` 第一个参数可以是子命令(如 Go 的 `go version` 写 `["version"]`),之后的参数仍然只能是选项,第一个之后出现裸词以 `plugin.manifest.invalid`(字段 `version.arguments`)拒绝;清单 schema 改用 `prefixItems` 并补上 `uniqueItems`。不需要新能力版本。 |