Skip to content

Commit 9d70e1f

Browse files
committed
feat(plugins): 远程工作区上下文带远端平台,新增 workspace/getHostPaths 和两个失败码(API-40,#2231)
- 远程上下文的 authority 新增 platform { os, arch },本地上下文没有这个字段。 - 新增宿主方法 lithe/host/workspace/getHostPaths:返回远程上下文根目录在远端主机上的绝对 POSIX 路径, 可选 rootIDs(1–256 个不重复的 ID);属于 workspace.metadata 下单独的方法授权,本地上下文返回 authorityUnsupported,未知根目录返回 notFound。 - 新增 plugin.host.remoteDisconnected(-32078)和 plugin.host.platformUnavailable(-32079), 中转与宿主错误表保持一码一义。 - 插件函数中转不再拒绝远程工作区的上下文,Core 不读也不改写参数和结果里的路径。 - 契约 README 写明启动计划的 hostServices 含方法授权,宿主去掉自己没有注册处理器的方法。 - 四个官方 SDK(Node、Go、Rust、Java)新增远端平台、getHostPaths、按来源选择进程路径的辅助方法和两个失败码, path 与 hostPath 是不同类型;新增远程工作区开发指南,更新 API 总表与协议更新记录。
1 parent 66a1476 commit 9d70e1f

44 files changed

Lines changed: 1958 additions & 99 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -910,9 +910,10 @@ fn plugin_backend_is_planned_without_a_workspace_and_names_its_host_services() {
910910

911911
/// A `backend` process starts without a page, its plan names the `backend`
912912
/// version so the host may start it on `onWorkspaceOpen`, and
913-
/// `workspace.metadata` grants the `workspace` host service. A host that does
914-
/// not offer `backend` refuses the manifest instead of starting a process it
915-
/// would misuse.
913+
/// `workspace.metadata` grants the `workspace` host service and the
914+
/// `getHostPaths` method grant; a host that does not serve that method drops
915+
/// the grant when it starts the backend. A host that does not offer `backend`
916+
/// refuses the manifest instead of starting a process it would misuse.
916917
#[test]
917918
fn workspace_backend_is_planned_with_its_version_and_workspace_service() {
918919
let outcome = validate(fixture("backend-workspace.plugin.json"));
@@ -930,7 +931,10 @@ fn workspace_backend_is_planned_with_its_version_and_workspace_service() {
930931
assert_eq!(launch["status"], "ok", "{launch}");
931932
assert_eq!(
932933
launch["plan"]["backend"],
933-
json!({ "hostServices": ["workspace"], "version": 0 })
934+
json!({
935+
"hostServices": ["lithe/host/workspace/getHostPaths", "workspace"],
936+
"version": 0
937+
})
934938
);
935939

936940
let hosted = |host: Value| {

‎rust/crates/lsp-engine/src/function_relay_tests.rs‎

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,31 @@ fn a_declared_exported_call_reaches_the_callee_and_returns_its_value() {
490490
});
491491
}
492492

493+
/// Both backends run on this machine for a remote workspace too, so a call
494+
/// naming a remote context reaches the callee like a local one (API-35).
495+
#[test]
496+
fn a_call_for_a_remote_workspace_reaches_the_callee() {
497+
let fixture = Fixture::new();
498+
let python = fixture.start(Launch::new(PYTHON));
499+
let go = fixture.start(Launch::new(GO).serving(&[FORMAT]));
500+
fixture.configure(snapshot(
501+
vec![
502+
plugin(PYTHON, &[], &[(FORMAT, 1)]),
503+
plugin(GO, &[(FORMAT, 1)], &[]),
504+
],
505+
"remote",
506+
));
507+
508+
python.ask("call-1", INVOKE, call_params(GO, FORMAT));
509+
let (wire_id, received) = go.await_invoke();
510+
assert_eq!(received["context"], workspace_context());
511+
go.answer(&wire_id, json!({ "edits": 1 }));
512+
assert_eq!(
513+
python.reply("call-1")["result"],
514+
json!({ "value": { "edits": 1 } })
515+
);
516+
}
517+
493518
#[test]
494519
fn a_caller_field_in_the_host_request_is_refused() {
495520
let fixture = Fixture::new();
@@ -728,19 +753,6 @@ fn refusals() -> Vec<Refusal> {
728753
code: "plugin.host.contextExpired",
729754
rpc_code: -32011,
730755
},
731-
Refusal {
732-
name: "the workspace is remote",
733-
snapshot: snapshot(
734-
vec![
735-
plugin(PYTHON, &[], &[(FORMAT, 1)]),
736-
plugin(GO, &[(FORMAT, 1)], &[]),
737-
],
738-
"remote",
739-
),
740-
params: call_params(GO, FORMAT),
741-
code: "plugin.host.authorityUnsupported",
742-
rpc_code: -32012,
743-
},
744756
Refusal {
745757
name: "the params are above the relay limit",
746758
snapshot: standard_snapshot(),

‎rust/crates/plugin-function-relay/src/lib.rs‎

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@ pub struct RelayContext {
8484
#[serde(rename = "contextID")]
8585
pub(crate) context_id: String,
8686
pub(crate) generation: u64,
87-
pub(crate) authority: ContextAuthority,
87+
/// Checked as part of the snapshot, but the relay does not depend on it:
88+
/// both backends run on this machine for a remote workspace too, and the
89+
/// callee's host requests are routed by the context's authority (API-35).
90+
#[serde(rename = "authority")]
91+
pub(crate) _authority: ContextAuthority,
8892
}
8993

9094
/// A function an enabled plugin exports.
@@ -639,12 +643,6 @@ impl FunctionRelay {
639643
codes::HOST_CONTEXT_EXPIRED,
640644
"The workspace context is no longer current.",
641645
)),
642-
Some(context) if context.authority == ContextAuthority::Remote => {
643-
Err(RelayFailure::new(
644-
codes::HOST_AUTHORITY_UNSUPPORTED,
645-
"Plugin functions do not run for remote workspaces.",
646-
))
647-
}
648646
Some(_) => Ok(()),
649647
}
650648
}
@@ -924,7 +922,7 @@ mod tests {
924922
RelayContext {
925923
context_id: "workspace-1".to_string(),
926924
generation: 3,
927-
authority: ContextAuthority::Local,
925+
_authority: ContextAuthority::Local,
928926
}
929927
}
930928

@@ -1228,25 +1226,18 @@ mod tests {
12281226
assert_eq!(refusal(&mut relay, unknown), codes::HOST_CONTEXT_EXPIRED);
12291227
}
12301228

1229+
/// Both backends run on this machine for a remote workspace too, so a call
1230+
/// naming a remote context is dispatched like a local one (API-35).
12311231
#[test]
1232-
fn a_remote_workspace_is_refused() {
1233-
let mut relay = relay();
1232+
fn a_remote_workspace_is_relayed() {
1233+
let mut relay = FunctionRelay::default();
12341234
relay
1235-
.configure(RelaySnapshot {
1236-
plugins: vec![
1237-
plugin(PYTHON, &[], &[(FUNCTION, 1)]),
1238-
plugin(GO, &[(FUNCTION, 1)], &[]),
1239-
],
1240-
contexts: vec![RelayContext {
1241-
authority: ContextAuthority::Remote,
1242-
..local_context()
1243-
}],
1244-
})
1235+
.configure(snapshot_with_contexts(vec![RelayContext {
1236+
_authority: ContextAuthority::Remote,
1237+
..local_context()
1238+
}]))
12451239
.unwrap();
1246-
assert_eq!(
1247-
refusal(&mut relay, request("py", PYTHON, GO, 1)),
1248-
codes::HOST_AUTHORITY_UNSUPPORTED
1249-
);
1240+
admitted_call(&mut relay, request("py", PYTHON, GO, 1), Instant::now());
12501241
}
12511242

12521243
#[test]

‎rust/crates/plugin-rpc/src/failures.rs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ pub fn host_rpc_code(code: &str) -> i64 {
4242
// must tell the provider's error from Core's by the number alone.
4343
codes::FAILED => -32070,
4444
codes::INVALID_RESULT => -32071,
45+
// -32072 to -32077 are the toolchain provider protocol's.
46+
codes::HOST_REMOTE_DISCONNECTED => -32078,
47+
codes::HOST_PLATFORM_UNAVAILABLE => -32079,
4548
_ => -32603,
4649
}
4750
}
@@ -86,6 +89,8 @@ pub fn host_failure(code: Option<&str>) -> (&'static str, i64) {
8689
Some(codes::HOST_METHOD_NOT_DECLARED) => codes::HOST_METHOD_NOT_DECLARED,
8790
Some(codes::HOST_TOOL_UNRESOLVED) => codes::HOST_TOOL_UNRESOLVED,
8891
Some(codes::HOST_FOREIGN_CONTRIBUTION) => codes::HOST_FOREIGN_CONTRIBUTION,
92+
Some(codes::HOST_REMOTE_DISCONNECTED) => codes::HOST_REMOTE_DISCONNECTED,
93+
Some(codes::HOST_PLATFORM_UNAVAILABLE) => codes::HOST_PLATFORM_UNAVAILABLE,
8994
// A backend exit is reported to pages, never to the backend itself.
9095
Some(codes::BACKEND_EXITED) => codes::HOST_FAILED,
9196
_ => codes::HOST_FAILED,

‎rust/crates/plugin-rpc/src/host_api.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ mod tests {
9898
method("lithe/host/workspace/readFile")["grant"],
9999
"lithe/host/workspace/readFile"
100100
);
101+
assert_eq!(
102+
method("lithe/host/workspace/getHostPaths")["grant"],
103+
"lithe/host/workspace/getHostPaths"
104+
);
101105
assert!(method("lithe/host/subscriptions/dispose")["grant"].is_null());
102106
assert_eq!(method("lithe/host/functions/invoke")["coreServed"], true);
103107
}

‎rust/crates/plugin-rpc/src/host_params.rs‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ pub(crate) fn check_host_params(
3535
HostParams::Credential { with_secret: false } => &["key"],
3636
HostParams::Subscription => &["subscriptionID"],
3737
HostParams::Context => &["context"],
38+
HostParams::HostPaths => &["context", "rootIDs"],
3839
HostParams::FunctionProviders => &["functionID"],
3940
HostParams::FunctionInvoke => &[
4041
"pluginID",
@@ -117,6 +118,27 @@ pub(crate) fn check_host_params(
117118
return Err(invalid(CONTEXT_REFERENCE_MESSAGE));
118119
}
119120
}
121+
HostParams::HostPaths => {
122+
if !params.get("context").is_some_and(is_context_reference) {
123+
return Err(invalid(CONTEXT_REFERENCE_MESSAGE));
124+
}
125+
if let Some(root_ids) = params.get("rootIDs") {
126+
let root_ids = root_ids
127+
.as_array()
128+
.filter(|ids| !ids.is_empty() && ids.len() <= MAX_HOST_PATH_ROOTS);
129+
let mut seen = BTreeSet::new();
130+
if !root_ids.is_some_and(|ids| {
131+
ids.iter().all(|id| {
132+
id.as_str()
133+
.is_some_and(|id| is_credential_key(id) && seen.insert(id))
134+
})
135+
}) {
136+
return Err(invalid(
137+
"`rootIDs` is 1-256 distinct root IDs of 1-128 ASCII letters, digits, '.', '_', ':' or '-'.",
138+
));
139+
}
140+
}
141+
}
120142
HostParams::FunctionProviders => {
121143
if !params
122144
.get("functionID")

‎rust/crates/plugin-rpc/src/host_requests.rs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ pub(crate) enum HostParams {
4040
Subscription,
4141
/// Exactly `{ context }`, a well-formed context reference.
4242
Context,
43+
/// `{ context, rootIDs? }`: a well-formed context reference and at most
44+
/// 256 distinct root IDs (plan API-40).
45+
HostPaths,
4346
/// Snapshot source listing or one bounded chunk from a selected source.
4447
KeymapSnapshot { chunk: bool },
4548
/// `{ context, serverID, method, params?, timeoutMilliseconds? }`: one
@@ -209,6 +212,12 @@ pub(crate) const HOST_METHODS: &[HostMethod] = &[
209212
permission: None,
210213
params: HostParams::Context,
211214
},
215+
HostMethod {
216+
method: WORKSPACE_GET_HOST_PATHS,
217+
service: HOST_SERVICE_WORKSPACE,
218+
permission: Some("workspace.metadata"),
219+
params: HostParams::HostPaths,
220+
},
212221
HostMethod {
213222
method: "lithe/host/workspace/readDirectory",
214223
service: "workspace",

‎rust/crates/plugin-rpc/src/lib.rs‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,15 @@ const WORKSPACE_GET_CONTEXT: &str = "lithe/host/workspace/getContext";
183183

184184
const WORKSPACE_GET_FOLDERS: &str = "lithe/host/workspace/getFolders";
185185

186+
/// Paths of a remote context's root folders on the remote host (plan
187+
/// API-40). `workspace.metadata` admits it as a grant of its own, not as
188+
/// part of the `workspace` service, so a host that does not serve it leaves
189+
/// it out of the session and adding it widened no existing grant.
190+
const WORKSPACE_GET_HOST_PATHS: &str = "lithe/host/workspace/getHostPaths";
191+
192+
/// Most root IDs one `getHostPaths` request may name.
193+
const MAX_HOST_PATH_ROOTS: usize = 256;
194+
186195
/// Backend request listing the plugins that export a function it may call.
187196
pub const FUNCTIONS_PROVIDERS: &str = "lithe/host/functions/providers";
188197

@@ -291,6 +300,13 @@ pub mod codes {
291300
/// The request names a contribution, such as a language server, that
292301
/// another plugin owns.
293302
pub const HOST_FOREIGN_CONTRIBUTION: &str = "plugin.host.foreignContribution";
303+
/// The connection to the remote workspace host was lost while the
304+
/// operation ran. Whether the operation took effect on the host is
305+
/// unknown; the backend asks again once the context is current.
306+
pub const HOST_REMOTE_DISCONNECTED: &str = "plugin.host.remoteDisconnected";
307+
/// The plugin has no package or managed runtime for the remote host's
308+
/// platform, so the process the request needs cannot run there.
309+
pub const HOST_PLATFORM_UNAVAILABLE: &str = "plugin.host.platformUnavailable";
294310
/// A page's call or a host operation ended because the backend process
295311
/// exited. Reported by hosts to pages, never sent to a backend.
296312
pub const BACKEND_EXITED: &str = "plugin.backend.exited";
@@ -804,6 +820,50 @@ mod tests {
804820
.is_err());
805821
}
806822

823+
/// `workspace.metadata` admits `getHostPaths` as a method grant of its
824+
/// own, and one request names at most 256 root IDs (plan API-40).
825+
#[test]
826+
fn host_paths_are_a_method_grant_with_bounded_root_ids() {
827+
assert_eq!(
828+
methods_for_permission("workspace.metadata"),
829+
[WORKSPACE_GET_HOST_PATHS]
830+
);
831+
assert!(is_host_grant(WORKSPACE_GET_HOST_PATHS));
832+
let granted = BTreeSet::from([
833+
HOST_SERVICE_WORKSPACE.to_string(),
834+
WORKSPACE_GET_HOST_PATHS.to_string(),
835+
]);
836+
let context = json!({ "contextID": "w-3f2a", "generation": 2 });
837+
let root_ids =
838+
|count: usize| -> Vec<String> { (0..count).map(|i| format!("r{i}")).collect() };
839+
let request = |count| {
840+
host_request(
841+
WORKSPACE_GET_HOST_PATHS,
842+
Some(&json!({ "context": context, "rootIDs": root_ids(count) })),
843+
Some(0),
844+
&granted,
845+
)
846+
};
847+
assert_eq!(
848+
request(MAX_HOST_PATH_ROOTS),
849+
Ok(HostRoute::Forward(HOST_SERVICE_WORKSPACE))
850+
);
851+
assert_eq!(
852+
request(MAX_HOST_PATH_ROOTS + 1).unwrap_err().code,
853+
codes::HOST_INVALID_PARAMS
854+
);
855+
// The method is not part of the `workspace` service's methods, so a
856+
// session granted only the service never learns it exists.
857+
let capabilities =
858+
capabilities_answer(0, &BTreeSet::from([HOST_SERVICE_WORKSPACE.to_string()]));
859+
assert!(!capabilities.to_string().contains(WORKSPACE_GET_HOST_PATHS));
860+
let capabilities = capabilities_answer(0, &granted);
861+
assert!(capabilities["services"][HOST_SERVICE_WORKSPACE]["methods"]
862+
.as_array()
863+
.unwrap()
864+
.contains(&json!(WORKSPACE_GET_HOST_PATHS)));
865+
}
866+
807867
/// A message over the bound is cut at a character boundary, never inside
808868
/// a multi-byte character.
809869
#[test]

‎rust/fixtures/plugins/host-api-v1.json‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@
1010
"input": { "method": "lithe/host/workspace/readFile", "service": "workspace", "grants": ["workspace"] },
1111
"expected": { "allowed": false, "code": "plugin.host.permissionDenied" }
1212
},
13+
{
14+
"name": "metadata grant alone does not grant host paths",
15+
"input": { "method": "lithe/host/workspace/getHostPaths", "service": "workspace", "grants": ["workspace"] },
16+
"expected": { "allowed": false, "code": "plugin.host.permissionDenied" }
17+
},
18+
{
19+
"name": "the host-paths grant admits host paths",
20+
"input": { "method": "lithe/host/workspace/getHostPaths", "service": "workspace", "grants": ["workspace", "lithe/host/workspace/getHostPaths"] },
21+
"expected": { "allowed": true }
22+
},
1323
{
1424
"name": "a method cannot be attributed to another service",
1525
"input": { "method": "lithe/host/editor/applyEdits", "service": "workspace", "grants": ["workspace"] },

‎shared/plugins/README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ SDK 与插件后端在构建时下载,并按锁定的 SHA-256(或 Git commit
155155
| [构建、运行与测试接入](guides/build-tool-integration.md) | 执行提供者示例、工程后端边界,以及声明式构建系统的现状和已发布示例 |
156156
| [编写调试适配器插件](guides/debug-adapter-plugin.md) | 从最小清单到启动方式、先编译再调试的 `executable`,以及调试控制台补全 |
157157
| [插件后端:工作区上下文与宿主服务](guides/plugin-backend-workspace.md) | 免页面启动、工作区上下文、纯后端命令、文档/文件/窗口宿主方法、宿主通知、失败码,以及宿主服务只增不改时后端要遵守的规则 |
158+
| [插件后端:远程工作区](guides/plugin-backend-remote-workspaces.md) | 远程上下文的来源与远端平台、单独获取的远端路径 `getHostPaths`、`path` 与 `hostPath` 的区别、断线与平台失败,以及插件函数中转 |
158159
| [插件自有的原生终端](guides/native-terminals.md) | `terminal/*`:创建、显示、关闭、重开和退出通知(本机工作区) |
159160

160161
收录和上架的规则由 Lithe Store 维护:[发布社区插件](https://github.com/Lithe-IDEA/Lithe-store/blob/main/docs/publishing.md)讲怎么打包、提交收录和发布新版本,[版本追踪与更新](https://github.com/Lithe-IDEA/Lithe-store/blob/main/docs/versioning-and-updates.md)讲 Lithe 怎么选择可安装的版本。
@@ -375,6 +376,7 @@ The example plugins are maintained in their own repositories. Before copying one
375376
| [Build, run, and test integration](guides/build-tool-integration.md) | Execution provider examples, the project backend boundary, and the current status and published examples of declarative build systems |
376377
| [Writing a debug adapter plugin](guides/debug-adapter-plugin.md) | From a minimal manifest to launch modes, compile-then-debug `executable`, and debug console completion |
377378
| [Plugin backend: workspace contexts and host services](guides/plugin-backend-workspace.md) | Launching without a page, workspace contexts, backend-only commands, document, file, and window host methods, host notifications, failure codes, and the rules a backend follows while host services only grow |
379+
| [Plugin backend: remote workspaces](guides/plugin-backend-remote-workspaces.md) | A remote context's authority and the remote platform, remote paths fetched on their own with `getHostPaths`, how `path` and `hostPath` differ, disconnect and platform failures, and the function relay |
378380
| [Plugin-owned native terminals](guides/native-terminals.md) | `terminal/*`: create, show, close, reopen, and exit notifications (local workspaces) |
379381

380382
Lithe Store maintains the listing rules: [Publishing community plugins](https://github.com/Lithe-IDEA/Lithe-store/blob/main/docs/publishing.md) covers packaging, submitting a listing, and releasing new versions, and [Version tracking and updates](https://github.com/Lithe-IDEA/Lithe-store/blob/main/docs/versioning-and-updates.md) covers how Lithe chooses an installable version.

0 commit comments

Comments
 (0)