diff --git a/rust/crates/core/src/tests/declarative_plugins.rs b/rust/crates/core/src/tests/declarative_plugins.rs index 134b61ab..89bd1f6c 100644 --- a/rust/crates/core/src/tests/declarative_plugins.rs +++ b/rust/crates/core/src/tests/declarative_plugins.rs @@ -1364,6 +1364,55 @@ fn debug_adapter_launch_plan_carries_the_process_and_the_descriptor() { ); } +#[test] +fn debug_adapter_launch_plan_reads_only_its_global_executable_setting() { + let manifest: Value = serde_json::from_str(contract_file!( + "fixtures/debug-adapters/debug-adapter-executable-setting.plugin.json" + )) + .unwrap(); + let plan = |settings: Value| { + language_server_launch_plan_command(json!({ + "manifest": manifest, + "debugAdapterID": "example", + "request": { + "pluginDirectory": "/plugins/example", "stateDirectory": "/state/example", + "architecture": "arm64", "settings": settings, + "projectSettings": { "debuggerPath": "/project/untrusted" } + }, + })) + .expect("payload is well formed") + }; + for settings in [json!({}), json!({ "debuggerPath": "" })] { + let result = plan(settings); + assert_eq!(result["status"], "ok", "{result}"); + assert_eq!( + result["plan"]["launch"], + json!({ "kind": "systemCommand", "commands": ["example-dap"] }) + ); + } + for path in ["/tools/my debugger", r"C:\Tools\my debugger.exe"] { + let result = plan(json!({ "debuggerPath": path })); + assert_eq!(result["status"], "ok", "{result}"); + assert_eq!(result["plan"]["launch"]["configuredExecutable"], path); + } + let result = plan(json!({ "debuggerPath": "relative/adapter" })); + assert_eq!( + result["error"]["code"], "plugin.launch.invalidRequest", + "{result}" + ); + assert_eq!(result["error"]["field"], "settings.debuggerPath"); + + for (field, value) in [("scope", json!("project")), ("effect", json!("restart"))] { + let mut invalid = manifest.clone(); + invalid["settings"][0][field] = value; + let result = validate_command(json!({ "manifest": invalid })).unwrap(); + assert_eq!( + result["error"]["field"], "debugAdapters[0].launch.executableSetting", + "{result}" + ); + } +} + #[test] fn debug_adapter_launch_plan_refuses_unknown_adapters_and_mixed_selectors() { let request = json!({ diff --git a/rust/crates/debug/src/adapters/process.rs b/rust/crates/debug/src/adapters/process.rs index d7f84c2c..d9815f2c 100644 --- a/rust/crates/debug/src/adapters/process.rs +++ b/rust/crates/debug/src/adapters/process.rs @@ -19,6 +19,9 @@ pub struct DebugLaunch { /// own. #[serde(default, skip_serializing_if = "Option::is_none")] pub process: Option, + /// Global file setting that can override a bare system command at launch. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub executable_setting: Option, pub(crate) transport: DebugTransport, /// Required by, and only allowed for, the TCP transports. #[serde(default, skip_serializing_if = "Option::is_none")] diff --git a/rust/crates/debug/src/adapters/validate_adapter.rs b/rust/crates/debug/src/adapters/validate_adapter.rs index 9dbfcf77..239ff756 100644 --- a/rust/crates/debug/src/adapters/validate_adapter.rs +++ b/rust/crates/debug/src/adapters/validate_adapter.rs @@ -199,6 +199,9 @@ pub fn programs(adapter: &DebugAdapterDeclaration) -> Vec { program["debugAdapter"] = json!(adapter.id); program["transport"] = json!(adapter.launch.transport); program["endpoint"] = json!(adapter.launch.endpoint); + if let Some(setting) = &adapter.launch.executable_setting { + program["executableSetting"] = json!(setting); + } let mut programs = vec![program]; if let Some(DebugProcess::Server(process)) = &adapter.launch.process { programs.extend(process.runtime_programs()); diff --git a/rust/crates/debug/src/adapters/validate_launch.rs b/rust/crates/debug/src/adapters/validate_launch.rs index c4cd02f7..8a5996fb 100644 --- a/rust/crates/debug/src/adapters/validate_launch.rs +++ b/rust/crates/debug/src/adapters/validate_launch.rs @@ -117,6 +117,21 @@ impl DebugLaunch { )); } } + if let Some(setting) = &self.executable_setting { + use lithe_plugin_model::process::LanguageServerLaunch; + let setting_field = format!("{field}.executableSetting"); + if !matches!(&self.process, Some(DebugProcess::Server(process)) + if matches!(process.launch, LanguageServerLaunch::SystemCommand { .. })) + { + return Err(invalid( + setting_field, + "Only a systemCommand debug process can select its executable from a setting.", + )); + } + if !context.declared_settings.is_executable(setting) { + return Err(invalid(setting_field, "The executable setting must be a global file setting with an empty default and effect reload or nextRun.")); + } + } match (self.transport, &self.endpoint) { (DebugTransport::Stdio, None) => Ok(()), (DebugTransport::Stdio, Some(_)) => Err(invalid( diff --git a/rust/crates/plugin-manifest/src/launch.rs b/rust/crates/plugin-manifest/src/launch.rs index 5afe8bcf..b0500a08 100644 --- a/rust/crates/plugin-manifest/src/launch.rs +++ b/rust/crates/plugin-manifest/src/launch.rs @@ -59,7 +59,7 @@ impl LanguageServerLaunchPlanRequest { Ok(()) } - fn layers(&self) -> SettingLayers<'_> { + pub(crate) fn layers(&self) -> SettingLayers<'_> { SettingLayers { global: &self.settings, project: &self.project_settings, diff --git a/rust/crates/plugin-manifest/src/provider_launch.rs b/rust/crates/plugin-manifest/src/provider_launch.rs index 25553456..286d6a17 100644 --- a/rust/crates/plugin-manifest/src/provider_launch.rs +++ b/rust/crates/plugin-manifest/src/provider_launch.rs @@ -142,6 +142,27 @@ pub(crate) fn debug_adapter_launch_plan( hosting_language_server_plan(manifest, language_id, request)? } }; + if let Some(id) = &adapter.launch.executable_setting { + let setting = manifest + .settings + .iter() + .find(|setting| setting.id == *id) + .ok_or_else(|| { + PluginRejection::new( + "plugin.launch.unavailable", + format!("The debug adapter {adapter_id} references an undeclared executable setting."), + ) + })?; + let path = setting + .executable_value(request.layers().global.get(id)) + .map_err(|error| PluginRejection { + code: "plugin.launch.invalidRequest", + ..error + })?; + if let Some(path) = path { + plan["launch"]["configuredExecutable"] = json!(path); + } + } plan["debugAdapter"] = adapter.plan_descriptor(&manifest.id); Ok(plan) } diff --git a/rust/crates/plugin-model/src/settings.rs b/rust/crates/plugin-model/src/settings.rs index 01c36671..7d77c21b 100644 --- a/rust/crates/plugin-model/src/settings.rs +++ b/rust/crates/plugin-model/src/settings.rs @@ -360,7 +360,7 @@ struct SettingOption { /// Setting IDs a template may name, with the restrictions their kinds carry. #[derive(Debug, Clone, Default)] pub struct DeclaredSettings { - /// Global paths that may explicitly select a build executable. + /// Global paths that may explicitly select an executable. executables: BTreeSet, /// Settings a launch reads when it starts. launch: BTreeSet, @@ -374,7 +374,7 @@ pub struct DeclaredSettings { } impl DeclaredSettings { - /// Whether the global file setting may select the build executable. + /// Whether the global file setting may select an executable. pub fn is_executable(&self, id: &str) -> bool { self.executables.contains(id) } diff --git a/shared/plugins/contract/v1/README.md b/shared/plugins/contract/v1/README.md index e77a1ed0..5b8a7db1 100644 --- a/shared/plugins/contract/v1/README.md +++ b/shared/plugins/contract/v1/README.md @@ -3368,6 +3368,26 @@ adapter serves `attach`), and one `onDebug:` activation event per adapter. | `launch.endpoint` for `tcpAnnounced` | The host reads the adapter's `stream` line by line. The first line that contains `prefix` is the announcement: the rest of that line after the prefix, without surrounding whitespace, is a port from 1 to 65535 (`port`, on `127.0.0.1`) or `host:port` with a loopback host, IPv6 in brackets (`hostPort`, for example Delve's `DAP server listening at: 127.0.0.1:54321`). Any other announcement fails the start, and so does no announcement within 10 seconds. The adapter's other output goes to the Debug Console. | | `launch.endpoint` for `tcpLanguageServer` | For an adapter that lives inside a language server and has no process of its own (the Java Debug Server runs in JDT LS). `languageID` names a `languageServers[]` entry of the same plugin; `command` (1–128 characters of letters, digits, `.`, `_`, `:`, `-`) is the `workspace/executeCommand` the host sends to that server for each session. The server answers with the loopback port to connect to, as an integer or a numeric string from 1 to 65535. The host starts the language server for the workspace first, as it does for editing. The command is part of what the user reviews at install and update, and changing it asks again. | +### Adapter executable setting + +`launch.executableSetting` can name a global `file` setting of the plugin +with an empty default and effect `reload` or `nextRun`. It is valid for a +`systemCommand` adapter process. See the +[executable setting fixture](fixtures/debug-adapters/debug-adapter-executable-setting.plugin.json). + +Core reads the user settings layer and adds `launch.configuredExecutable` to +the system-command plan for a nonempty absolute path. An invalid stored value +returns `plugin.launch.invalidRequest` on `settings.`. The host checks that +the file is executable on its platform. An unusable path fails the start. +Omitting the field or leaving the setting empty preserves the declared command +lookup and command installers. The process uses the same arguments and +lifecycle. The setting is included in install and update review under +`debug.launch`. + +The setting selects the adapter process on the machine that starts it. Remote +attach keeps the debuggee's separate endpoint and confirmation rules. Hosts +that predate this declaration reject the manifest. + ### Adapter features and defaults A host never recognizes an adapter by its ID. What is specific to an adapter diff --git a/shared/plugins/contract/v1/fixtures/debug-adapters/debug-adapter-executable-setting.plugin.json b/shared/plugins/contract/v1/fixtures/debug-adapters/debug-adapter-executable-setting.plugin.json new file mode 100644 index 00000000..959be246 --- /dev/null +++ b/shared/plugins/contract/v1/fixtures/debug-adapters/debug-adapter-executable-setting.plugin.json @@ -0,0 +1,37 @@ +{ + "schemaVersion": 0, + "id": "dev.lithe.fixture.debug-adapter-executable-setting", + "displayName": "Debug Adapter Executable Setting Fixture", + "version": "0.1.0", + "pluginAPIVersion": 0, + "requires": { "debugAdapters": 0, "settings": 0 }, + "vendor": { + "id": "org.example", + "displayName": "Example", + "signatureRequirement": "publisherPackage" + }, + "permissions": ["debug.launch"], + "activationEvents": ["onDebug:example"], + "settings": [ + { + "id": "debuggerPath", + "type": "file", + "title": "Debugger", + "default": "", + "effect": "nextRun" + } + ], + "debugAdapters": [ + { + "id": "example", + "displayName": "Example Debugger", + "launch": { + "executableSetting": "debuggerPath", + "process": { + "launch": { "kind": "systemCommand", "commands": ["example-dap"] } + }, + "transport": "stdio" + } + } + ] +} diff --git a/shared/plugins/contract/v1/plugin-manifest.schema.json b/shared/plugins/contract/v1/plugin-manifest.schema.json index 59fca3bf..679257d1 100644 --- a/shared/plugins/contract/v1/plugin-manifest.schema.json +++ b/shared/plugins/contract/v1/plugin-manifest.schema.json @@ -573,6 +573,30 @@ "properties": { "process": { "$ref": "#/$defs/debugProcess" + }, + "executableSetting": { + "description": "A global file setting with an empty default and effect reload or nextRun. Only for a systemCommand adapter process.", + "type": "string", + "minLength": 1 + } + }, + "if": { + "required": ["executableSetting"] + }, + "then": { + "required": ["process"], + "properties": { + "process": { + "required": ["launch"], + "properties": { + "launch": { + "required": ["kind"], + "properties": { + "kind": { "const": "systemCommand" } + } + } + } + } } }, "oneOf": [ diff --git a/shared/plugins/reference/domains/debug-adapters.md b/shared/plugins/reference/domains/debug-adapters.md index eaed3a77..6f4e57e5 100644 --- a/shared/plugins/reference/domains/debug-adapters.md +++ b/shared/plugins/reference/domains/debug-adapters.md @@ -116,6 +116,7 @@ Core 只把 `localhost`、`127.0.0.0/8`、`::1` 判为本机;其他主机都 | [Remote attach](../../contract/v1/README.md#remote-attach) | `connection` 绑定、四种路径映射、目标格式、本机判定、拒绝层次 | | [Native debug preparation](../../contract/v1/README.md#native-debug-preparation) | 构建提供者准备原生调试目标 | | [Registry connection debugging](../../contract/v1/README.md#registry-connection-debugging) | 服务运行按配置类型选择 attach 适配器 | +| [适配器程序路径](../../contract/v1/README.md#adapter-executable-setting) | `launch.executableSetting` 指向用户全局文件设置,选择本机命令型调试适配器 | | [Permissions and activation](../../contract/v1/README.md#permissions-and-activation) | `debug.launch`、`debug.attach`、`debug.start`、`onDebug:` | ### 示例与用例 @@ -255,6 +256,7 @@ The other rules of `run/start`, `run/stop`, and `run/didExit` are in [Plugin bac | [Remote attach](../../contract/v1/README.md#remote-attach) | The `connection` binding, the four mapping shapes, the target format, local detection, refusal layers | | [Native debug preparation](../../contract/v1/README.md#native-debug-preparation) | Build providers preparing native debug targets | | [Registry connection debugging](../../contract/v1/README.md#registry-connection-debugging) | Service runs choosing an attach adapter by configuration type | +| [Adapter executable setting](../../contract/v1/README.md#adapter-executable-setting) | `launch.executableSetting` selects a local system-command adapter through a global file setting | | [Permissions and activation](../../contract/v1/README.md#permissions-and-activation) | `debug.launch`, `debug.attach`, `debug.start`, `onDebug:` | ### Examples and cases diff --git a/shared/plugins/reference/protocol-changelog.md b/shared/plugins/reference/protocol-changelog.md index b267f554..8dd915f5 100644 --- a/shared/plugins/reference/protocol-changelog.md +++ b/shared/plugins/reference/protocol-changelog.md @@ -14,6 +14,8 @@ ## 待合入 +- [#207](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/207)(待合入),[@1lck](https://github.com/1lck),`debugAdapters` 0(API-30)增加可选 `launch.executableSetting`。命令型适配器可读取用户全局文件路径,留空沿用原命令查找;旧宿主会拒绝包含该声明的清单。无新增方法、通知或能力版本。 + - [#198](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/198)(2026-11-24),[@1lck](https://github.com/1lck),`pluginAPIVersion` 0 / `litheFunctions` 0 内补充(API-27):`editor/registerActions` 的 `services.editor.options.actionIcons` 新增四个通用行首导航图标 token:`navigate-implemented`(接口/契约有子实现,向下)、`navigate-implementing`(实现接口/契约,向上)、`navigate-overridden`(父类/方法被覆写,向下)、`navigate-overriding`(覆写父类声明,向上),保留已有 `navigate-super` 与 `navigate-implementations` 向后兼容。`plugins.editorActions.decode` 仍由宿主声明的 `actionIcons` 列表动态校验,插件通过 `getCapabilities` 发现是否支持新 token,在旧宿主上回退到原有图标;契约 README、领域参考与 `fixtures/editor/editor-actions.json` 同步更新。没有新增能力版本、协议版本、宿主方法、通知或 SDK 版本。 - [#196](https://github.com/Lithe-IDEA/Lithe-core-rust/pull/196)(合入日期待合并时填写),[@xiaoyumuxi](https://github.com/xiaoyumuxi),`runConfigurationTypes` 0 内的补充(API-29):`buildSystems[].run[]` 新增可选字段 `configurationType`(引用同一构建系统的 `runConfigurationTypes[].id`)和 `values`(按字段 ID 填写初始值,字符串与 `arguments` 列表项支持 `${root}`、`${project.*}`、`${target.*}` 模板展开),必须配合 `fromTargets` 使用,与 `source: "provider"`、`debug`、`entrypoints`、`fromTasks`、`arguments`、`extension`、`execution` 互斥;清单继续写 `requires.runConfigurationTypes: 0`(旧宿主 Core 因 `deny_unknown_fields` 会直接以 `plugin.manifest.invalid` 拒绝,不会静默忽略)。`build.decodeModel` 展开模板并在 `model.run[]` 中输出 `provider: "build.run-type"` 与 `runType: {pluginID, buildSystemID, type, values}`;`runConfig.generate` 的 `providerRuns` 快照支持物化为确定性 ID(`generated:run-type:`)的 `build.run-type` 生成层配置,与手动创建的同类型配置共用分组、图标、编辑器表单和 `build.runConfigurationPlan` 启动计划;`runConfig.editorForm` 和 `runConfig.saveConfiguration` 支持直接读取并覆盖生成层的 `build.run-type` 配置,且在层合并时整体替换 `extensions.build` 以免被清空的可选字段回渗。没有新增能力版本、宿主方法、通知或 SDK 版本。