Skip to content

Commit 01c5336

Browse files
authored
refactor(build): 删除 KNOWN_RUNTIME_TOOLS,go、node 运行时依赖按工具定义解析 (#69)
构建系统的 runtimeDependencies 原来把 go、node 当作宿主管理的运行时: 计划返回 { kind: runtime } 候选和 Core 自带的版本参数(go version、 node --version),checkToolVersion 用 reported_version 读版本,清单里 不许给它们写 executables。这是 Core 认识具体工具的写死逻辑。 现在 Core 不认识任何具体运行时:没有 executables 的运行时一律是同 ID 工具定义的隐式引用,计划返回 toolchain 候选、version 为 null,版本由 工具定义检查;写了 executables 的按普通运行时校验。 - build:删除 KNOWN_RUNTIME_TOOLS、is_host_managed、宿主运行时校验分支、 host_runtime_version_arguments 和计划里的 hostManaged 字段 - plugin-model:删除只服务于它的 reported_version - 测试:go、node、vm 走同一条路径;自己描述的运行时按自己的 pattern 读版本 - 契约:README、build-plans 与 invalid-manifests fixture、build-systems 参考页和协议更新记录;三处 runtime_tools 注释改成准确描述 Refs 1lck/Lithe-IDEA#1856
1 parent 0edf126 commit 01c5336

13 files changed

Lines changed: 111 additions & 253 deletions

File tree

‎rust/crates/build/src/invocation.rs‎

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use super::manifest::{
1414
use super::BuildManifest;
1515
use lithe_plugin_model::executables::ordered_indices;
1616
use lithe_plugin_model::{
17-
reported_version, validate_minimum_version, version_components, PluginRejection, Validation,
17+
validate_minimum_version, version_components, PluginRejection, Validation,
1818
};
1919
use serde::Deserialize;
2020
use serde_json::{json, Value};
@@ -67,48 +67,27 @@ fn candidates(
6767
}).collect()
6868
}
6969

70-
/// Arguments that make a host-managed runtime print its version and exit.
71-
/// Core owns them so hosts use the same probe, for build runtimes and for
72-
/// plugin launch runtimes alike. Hosts capture stderr together with stdout
73-
/// before checking the declared minimum. A tool definition probes the
74-
/// runtimes it resolves itself, so other IDs have none.
75-
pub(crate) fn host_runtime_version_arguments(id: &str) -> Option<&'static [&'static str]> {
76-
match id {
77-
"go" => Some(&["version"]),
78-
"node" => Some(&["--version"]),
79-
_ => None,
80-
}
81-
}
82-
8370
fn runtime(
8471
runtime: &RuntimeDependency,
8572
root: &str,
8673
platform: Platform,
8774
manifest: &impl BuildManifest,
8875
settings: &BTreeMap<String, Value>,
8976
) -> Validation<Value> {
90-
let version = if runtime.is_host_managed() {
91-
host_runtime_version_arguments(&runtime.id)
92-
.map(|arguments| json!({ "arguments": arguments }))
93-
} else {
94-
runtime
95-
.version
96-
.as_ref()
97-
.map(|probe| json!({ "arguments": probe.arguments }))
98-
};
77+
let version = runtime
78+
.version
79+
.as_ref()
80+
.map(|probe| json!({ "arguments": probe.arguments }));
9981
// An implicit reference is the toolchain candidate of the tool
10082
// definition with the same ID; resolving it checks `minimumVersion`.
10183
let executables = if runtime.names_tool_definition() {
10284
vec![json!({ "kind": "toolchain", "toolchainID": runtime.id, "root": root })]
103-
} else if runtime.is_host_managed() {
104-
vec![json!({"kind":"runtime","runtime":runtime.id})]
10585
} else {
10686
candidates(&runtime.executables, root, platform, manifest, settings)?
10787
};
10888
Ok(json!({
10989
"id": runtime.id,
11090
"displayName": runtime.display_name,
111-
"hostManaged": runtime.is_host_managed(),
11291
"pathVariable":format!("LITHE_{}_PATH",runtime.id.to_ascii_uppercase().replace('-',"_")),
11392
"minimumVersion": runtime.minimum_version,
11493
"executables": executables,
@@ -202,14 +181,10 @@ pub(crate) fn check_version(
202181
),
203182
));
204183
}
205-
let found = if dependency.is_host_managed() {
206-
reported_version(&request.output)
207-
} else {
208-
dependency
209-
.version
210-
.as_ref()
211-
.and_then(|probe: &VersionProbe| probe.version(&request.output))
212-
};
184+
let found = dependency
185+
.version
186+
.as_ref()
187+
.and_then(|probe: &VersionProbe| probe.version(&request.output));
213188
(found, dependency.minimum_version.as_deref())
214189
}
215190
};

‎rust/crates/build/src/manifest.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ pub struct DeclarationContext<'a> {
142142
pub declared_settings: &'a lithe_plugin_model::settings::DeclaredSettings,
143143
/// Language IDs the plugin declares a language server for.
144144
pub language_servers: &'a BTreeSet<String>,
145-
/// Whether tool names are host runtimes or tool-definition IDs.
145+
/// The tool-definition IDs in `requiresTools` that a process may name.
146146
pub runtime_tools: lithe_plugin_model::process::RuntimeTools<'a>,
147147
}
148148

‎rust/crates/build/src/manifest/invocation.rs‎

Lines changed: 16 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,12 @@ pub(crate) struct Invocation {
2121
pub(crate) minimum_version: Option<String>,
2222
}
2323

24-
/// Runtime tools the host discovers and manages itself for build-system
25-
/// runtime dependencies: it exports each as `LITHE_<TOOL>_PATH` and puts its
26-
/// directory on the process's `PATH`. Server processes never use this list;
27-
/// they name tool definitions from `requiresTools`.
28-
pub(crate) const KNOWN_RUNTIME_TOOLS: &[&str] = &["go", "node"];
29-
3024
pub(crate) use lithe_plugin_model::executables::{ExecutableCandidate, ExecutableSource, Platform};
3125

32-
/// A runtime the tool needs. Runtimes the host already manages (`node`,
33-
/// `go`) take only an ID and an optional minimum version and follow the
34-
/// user's runtime settings. Any other runtime either describes how to find
35-
/// and probe it, or lists no executables and names the tool definition with
36-
/// its ID, which finds the executable and checks `minimumVersion`. A
37-
/// plugin is never limited to a host list.
26+
/// A runtime the tool needs. It either describes how to find and probe the
27+
/// executable, or lists no executables and names the tool definition with
28+
/// its ID, which finds the executable and checks `minimumVersion`. Core
29+
/// knows no runtime by name; every runtime comes from a manifest.
3830
#[derive(Debug, Clone, Deserialize, Serialize)]
3931
#[serde(rename_all = "camelCase", deny_unknown_fields)]
4032
pub(crate) struct RuntimeDependency {
@@ -50,31 +42,24 @@ pub(crate) struct RuntimeDependency {
5042
}
5143

5244
impl RuntimeDependency {
53-
/// True when the host discovers this runtime with its own settings.
54-
pub(crate) fn is_host_managed(&self) -> bool {
55-
KNOWN_RUNTIME_TOOLS.contains(&self.id.as_str())
56-
}
57-
5845
/// True when the runtime is the tool definition with the same ID: it
59-
/// lists no executables and the host does not manage it. Plans give it
60-
/// a single toolchain candidate for that ID.
46+
/// lists no executables. Plans give it a single toolchain candidate for
47+
/// that ID.
6148
pub(crate) fn names_tool_definition(&self) -> bool {
62-
self.executables.is_empty() && !self.is_host_managed()
49+
self.executables.is_empty()
6350
}
6451

6552
/// True when the tool definition the runtime resolves through checks
66-
/// `minimumVersion`, so the manifest needs no version probe: a runtime
67-
/// the host does not manage that is an implicit reference or has exactly
68-
/// one toolchain candidate.
53+
/// `minimumVersion`, so the manifest needs no version probe: the runtime
54+
/// is an implicit reference or has exactly one toolchain candidate.
6955
pub(crate) fn checked_by_tool_definition(&self) -> bool {
70-
!self.is_host_managed()
71-
&& matches!(
72-
self.executables.as_slice(),
73-
[] | [ExecutableCandidate {
74-
source: ExecutableSource::Toolchain { .. },
75-
..
76-
}]
77-
)
56+
matches!(
57+
self.executables.as_slice(),
58+
[] | [ExecutableCandidate {
59+
source: ExecutableSource::Toolchain { .. },
60+
..
61+
}]
62+
)
7863
}
7964
}
8065

@@ -137,33 +122,6 @@ impl BuildSystemDeclaration {
137122
if let Some(minimum) = &runtime.minimum_version {
138123
validate_minimum_version(minimum, &format!("{field}.minimumVersion"))?;
139124
}
140-
if runtime.is_host_managed() {
141-
// The host finds these with the user's own runtime settings;
142-
// a plugin must not route around that choice.
143-
let toolchain = runtime.executables.len() == 1
144-
&& matches!(
145-
runtime.executables[0].source,
146-
ExecutableSource::Toolchain { .. }
147-
);
148-
if (!runtime.executables.is_empty() && !toolchain) || runtime.version.is_some() {
149-
return Err(invalid(
150-
field,
151-
format!(
152-
"{} is discovered by the host; declare only its minimumVersion.",
153-
runtime.id
154-
),
155-
));
156-
}
157-
if toolchain {
158-
check_candidate(
159-
&mut runtime.executables[0],
160-
&format!("{field}.executables[0]"),
161-
&invocation.environment_inputs,
162-
&BTreeSet::new(),
163-
)?;
164-
}
165-
continue;
166-
}
167125
if runtime.names_tool_definition() {
168126
// The tool definition finds the executable and checks
169127
// `minimumVersion`; a probe here would have nothing to run.

‎rust/crates/core/src/tests/build_runtime_versions.rs‎

Lines changed: 63 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
//! Host runtimes keep Core's version probe; any other runtime names the tool
2-
//! definition with the same ID, which checks the version itself.
1+
//! A runtime without executables names the tool definition with the same ID,
2+
//! which finds the executable and checks the version itself. Core knows no
3+
//! runtime by name: `go` and `node` follow the same rules as any other ID.
34
45
use crate::build::{build_check_tool_version_command, build_invocation_plan_command};
56
use lithe_plugin_manifest::DeclarativePluginManifest as Manifest;
@@ -31,126 +32,93 @@ fn check(manifest: Value, runtime: &str, output: &str) -> Value {
3132
.expect("version request is valid")
3233
}
3334

35+
/// A published manifest that names a runtime without executables keeps
36+
/// validating; the plan resolves it through the tool definition with that
37+
/// ID. `go` and `node` get no host candidate and no Core probe.
3438
#[test]
35-
fn host_runtime_probe_arguments_are_portable_across_platforms() {
39+
fn runtime_without_executables_becomes_a_toolchain_candidate() {
3640
for platform in ["macos", "linux", "windows"] {
37-
let mut manifest = manifest();
38-
manifest["buildSystems"][0]["invocation"]["runtimeDependencies"] = json!([
39-
{ "id": "node", "minimumVersion": "20" },
40-
{ "id": "go", "minimumVersion": "1.22" }
41-
]);
42-
let result = plan(manifest, platform);
43-
assert_eq!(result["status"], "ok", "{platform}: {result}");
44-
let runtimes = &result["invocation"]["runtimeDependencies"];
45-
for (index, arguments) in [json!(["--version"]), json!(["version"])]
46-
.into_iter()
47-
.enumerate()
48-
{
49-
assert_eq!(runtimes[index]["hostManaged"], true, "{platform}");
50-
let id = if index == 0 { "node" } else { "go" };
51-
assert_eq!(
52-
runtimes[index]["executables"],
53-
json!([{"kind":"runtime","runtime":id}]),
54-
"{platform}"
55-
);
41+
for (id, minimum, path_variable) in [
42+
("vm", "8", "LITHE_VM_PATH"),
43+
("go", "1.22", "LITHE_GO_PATH"),
44+
("node", "20", "LITHE_NODE_PATH"),
45+
] {
46+
let mut manifest = manifest();
47+
manifest["buildSystems"][0]["invocation"]["runtimeDependencies"] =
48+
json!([{ "id": id, "minimumVersion": minimum }]);
49+
let result = plan(manifest, platform);
50+
assert_eq!(result["status"], "ok", "{platform} {id}: {result}");
5651
assert_eq!(
57-
runtimes[index]["pathVariable"],
58-
format!("LITHE_{}_PATH", id.to_ascii_uppercase())
52+
result["invocation"]["runtimeDependencies"][0],
53+
json!({
54+
"id": id,
55+
"displayName": null,
56+
"pathVariable": path_variable,
57+
"executables": [
58+
{ "kind": "toolchain", "toolchainID": id, "root": "." }
59+
],
60+
"version": null,
61+
"minimumVersion": minimum
62+
}),
63+
"{platform} {id}"
5964
);
65+
// The build tool's own probe stays independent of its runtimes.
6066
assert_eq!(
61-
runtimes[index]["version"]["arguments"], arguments,
62-
"{platform}"
67+
result["invocation"]["version"]["arguments"],
68+
json!(["--version"])
6369
);
6470
}
65-
// The build tool's own probe stays independent of its runtimes.
66-
assert_eq!(
67-
result["invocation"]["version"]["arguments"],
68-
json!(["--version"])
69-
);
7071
}
7172
}
7273

73-
/// A published manifest that names `vm` without executables keeps
74-
/// validating; the plan resolves it through the tool definition `vm`.
7574
#[test]
76-
fn runtime_without_executables_becomes_a_toolchain_candidate() {
77-
for platform in ["macos", "linux", "windows"] {
75+
fn runtime_named_by_tool_definition_has_no_core_probe() {
76+
for (id, output) in [
77+
("vm", "21.0.4\n"),
78+
("go", "go version go1.22.3 darwin/arm64\n"),
79+
("node", "v20.11.0\n"),
80+
] {
7881
let mut manifest = manifest();
7982
manifest["buildSystems"][0]["invocation"]["runtimeDependencies"] =
80-
json!([{ "id": "vm", "minimumVersion": "8" }]);
81-
let result = plan(manifest, platform);
82-
assert_eq!(result["status"], "ok", "{platform}: {result}");
83+
json!([{ "id": id, "minimumVersion": "8" }]);
84+
let result = check(manifest, id, output);
8385
assert_eq!(
84-
result["invocation"]["runtimeDependencies"][0],
86+
result,
8587
json!({
86-
"id": "vm",
87-
"displayName": null,
88-
"hostManaged": false,
89-
"pathVariable":"LITHE_VM_PATH",
90-
"executables": [
91-
{ "kind": "toolchain", "toolchainID": "vm", "root": "." }
92-
],
93-
"version": null,
94-
"minimumVersion": "8"
88+
"status": "rejected",
89+
"error": {
90+
"code": "plugin.build.unavailable",
91+
"message": format!(
92+
"Cargo declares no version probe for {id}; its tool definition checks the version."
93+
)
94+
}
9595
}),
96-
"{platform}"
96+
"{id}"
9797
);
9898
}
9999
}
100100

101+
/// A runtime the plugin describes itself reads its version with its own
102+
/// pattern, whatever its ID.
101103
#[test]
102-
fn runtime_named_by_tool_definition_has_no_core_probe() {
103-
let mut manifest = manifest();
104-
manifest["buildSystems"][0]["invocation"]["runtimeDependencies"] =
105-
json!([{ "id": "vm", "minimumVersion": "8" }]);
106-
let result = check(manifest, "vm", "21.0.4\n");
107-
assert_eq!(
108-
result,
109-
json!({
110-
"status": "rejected",
111-
"error": {
112-
"code": "plugin.build.unavailable",
113-
"message": "Cargo declares no version probe for vm; its tool definition checks the version."
114-
}
115-
})
116-
);
117-
}
118-
119-
#[test]
120-
fn host_runtime_output_reads_the_first_dotted_number() {
121-
for (runtime, minimum, output, satisfied, version) in [
122-
("node", "20", "v20.11.0\n", true, "20.11.0"),
123-
(
124-
"node",
125-
"20",
126-
"warning: custom build\nv18.20.4\n",
127-
false,
128-
"18.20.4",
129-
),
130-
(
131-
"go",
132-
"1.22",
133-
"go version go1.22.3 darwin/arm64\n",
134-
true,
135-
"1.22.3",
136-
),
137-
(
138-
"go",
139-
"1.22",
140-
"go version go1.21.9 linux/amd64\n",
141-
false,
142-
"1.21.9",
143-
),
104+
fn described_runtime_reads_its_own_probe() {
105+
for (output, satisfied, version) in [
106+
("go version go1.22.3 darwin/arm64\n", true, "1.22.3"),
107+
("go version go1.21.9 linux/amd64\n", false, "1.21.9"),
144108
] {
145109
let mut manifest = manifest();
146-
manifest["buildSystems"][0]["invocation"]["runtimeDependencies"] =
147-
json!([{ "id": runtime, "minimumVersion": minimum }]);
148-
let result = check(manifest, runtime, output);
110+
manifest["buildSystems"][0]["invocation"]["runtimeDependencies"] = json!([{
111+
"id": "go",
112+
"minimumVersion": "1.22",
113+
"executables": [{ "kind": "command", "command": "go" }],
114+
"version": { "arguments": ["version"], "pattern": "go(\\d+\\.\\d+(?:\\.\\d+)?)" }
115+
}]);
116+
let result = check(manifest, "go", output);
149117
assert_eq!(result["status"], "ok", "{result}");
150118
assert_eq!(
151119
result["version"],
152120
json!({ "satisfied": satisfied, "version": version }),
153-
"{runtime} {output}"
121+
"{output}"
154122
);
155123
}
156124
}

‎rust/crates/debug/src/adapters.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ pub struct DeclarationContext<'a> {
204204
pub declared_settings: &'a DeclaredSettings,
205205
/// Language IDs of the plugin's `languageServers[]`.
206206
pub language_servers: &'a BTreeSet<String>,
207-
/// Whether tool names are host runtimes or tool-definition IDs.
207+
/// The tool-definition IDs in `requiresTools` that a process may name.
208208
pub runtime_tools: lithe_plugin_model::process::RuntimeTools<'a>,
209209
}
210210

0 commit comments

Comments
 (0)