Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions rust/contracts/rust-core-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,9 @@ or removing a command fails until the table changes in the same commit.
| `plugins.declarative.languageServerLaunchPlan` | Expand a declarative plugin's language-server, build-provider, VCS-provider, backend, or debug-adapter launch with host directories and architecture |
| `plugins.languageServers.decodeLaunch` | Bound the answer of a plugin backend that resolved a language server's launch and return the plan the host starts |
| `plugins.languageServers.stateRetention` | Choose which inactive per-workspace state directories of a plugin language server the host deletes |
| `plugins.commandInstallers.requirements` | List each `systemCommand` launch of a plugin with its commands and the installer that provides each |
| `plugins.commandInstallers.plan` | Expand one command installer for the target the user chose |
| `plugins.commandInstallers.defaultDirectory` | Read where a `toolDefault` installation puts its commands from the output of its directory probes |
| `plugins.contentProviders.decode` | Bound the answer of a plugin content provider function and return the document text |
| `debug.adapters.startArguments` | Check one debug start against a plugin's `debugAdapters[]` entry and return its DAP launch arguments |
| `debug.validateAdapterEndpoint` | Validate an IDE-to-DAP TCP endpoint and classify whether remote consent is required; performs no DNS or network I/O |
Expand Down Expand Up @@ -4040,6 +4043,34 @@ those older than `maxAgeDays` and those beyond the newest that fit are listed.
The host lists and deletes only directories under its own state storage, never
inside an app bundle or installation directory.

The `plugins.commandInstallers.*` commands implement
[Command installers](../../shared/plugins/contract/v1/README.md#command-installers).
They revalidate the manifest, read nothing and start nothing.
`plugins.commandInstallers.requirements` accepts `{ manifest }` and returns
`requirements: { consumers: [{ kind, id, commands: [{ command, installer }] }],
installers: [{ id, commands, tool, minimumVersion, mayUseNetwork, targets }] }`.
`kind` is `languageServer`, `buildProvider`, `vcsProvider`, `debugAdapter` or
`backend`; `id` is the language, build system, VCS or adapter ID, `null` for
the backend; `installer` is `null` for a command no installer provides.
`plugins.commandInstallers.plan` accepts `{ manifest, installerID, target:
"managed" | "toolDefault", installDirectory? }` and returns `plan: { installer,
target, commands, tool, minimumVersion, mayUseNetwork, timeoutMilliseconds,
arguments, environment, commandDirectory, directoryProbes: [{ arguments }] }`.
A `managed` plan needs the absolute directory the host made and expands
`${installDirectory}` in it; `commandDirectory` is that directory or the
declared path below it, and `directoryProbes` is empty. A `toolDefault` plan
takes no `installDirectory`, has a `null` `commandDirectory` and lists the
probes. `plugins.commandInstallers.defaultDirectory` accepts `{ manifest,
installerID, outputs }`, one standard output per probe in plan order (`null`
for a probe that failed), and returns `directory`: the first probe output that
names an absolute directory, its first path-list entry for a `pathList` probe,
with `append` joined; `null` when none does. Paths follow the platform Core
runs on. Refusals are `plugin.commandInstaller.unknown`,
`plugin.commandInstaller.targetUndeclared`,
`plugin.commandInstaller.directoryInvalid` and
`plugin.commandInstaller.probeOutputsInvalid`; the golden cases are
`shared/plugins/contract/v1/fixtures/command-installers/command-installer-plans.json`.

`plugins.contentProviders.decode` accepts `{ result }`, the value a plugin
function returned for a document of its content scheme, and returns
`{ content }`. `result` is a string, or an object whose only member is
Expand Down Expand Up @@ -5995,6 +6026,7 @@ a code has one meaning across every contribution with that lifecycle:
| `debugAdapter/start` | `debugAdapters[]` | process start |
| `lithe/build/model` | `buildSystems[].model` command source | command run |
| `lithe/build/dependencies` | `buildSystems[].dependencies` command source | command run |
| `commandInstaller/install` | `commandInstallers[]` installation the user confirmed; `decode` when a provided command is missing after a successful exit | command run |

| `stage` | Process start | Command run |
| --- | --- | --- |
Expand Down
6 changes: 3 additions & 3 deletions rust/crates/build/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ use super::template::{self, Allowed, Availability, BuildArgument, Variable};
use lithe_plugin_model::process::{ServerProcess, ServerRole};
use lithe_plugin_model::settings::is_setting_identifier;
use lithe_plugin_model::{
invalid, invalid_template as template_error, is_bare_command, is_identifier,
is_safe_relative_path, sorted_unique, validate_minimum_version, PluginRejection, UIIcon,
Validation,
invalid, invalid_template as template_error, is_bare_command, is_environment_name,
is_identifier, is_safe_relative_path, sorted_unique, validate_minimum_version, PluginRejection,
UIIcon, Validation,
};
use regex::Regex;
use serde::{Deserialize, Deserializer, Serialize};
Expand Down
12 changes: 0 additions & 12 deletions rust/crates/build/src/manifest/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,6 @@ pub(crate) fn is_tag(value: &str) -> bool {
is_identifier(value) && value.len() <= MAX_IDENTIFIER
}

pub(crate) fn is_environment_name(value: &str) -> bool {
!value.is_empty()
&& value.len() <= MAX_IDENTIFIER
&& value
.chars()
.next()
.is_some_and(|first| first.is_ascii_uppercase() || first == '_')
&& value.chars().all(|character| {
character.is_ascii_uppercase() || character.is_ascii_digit() || character == '_'
})
}

/// A file name with no directory part.
pub(crate) fn is_file_name(value: &str) -> bool {
is_safe_relative_path(value) && !value.contains('/') && value != "."
Expand Down
2 changes: 1 addition & 1 deletion rust/crates/build/src/plans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ pub(crate) fn provider_hints(request: &OutputPlanRequest) -> Validation<Map<Stri
params.insert("tool".to_string(), json!({ "executable": executable }));
if tool.environment.len() > 64
|| tool.environment.iter().any(|(key, value)| {
!super::manifest::is_environment_name(key)
!lithe_plugin_model::is_environment_name(key)
|| value.len() > 32768
|| value.contains('\0')
})
Expand Down
18 changes: 18 additions & 0 deletions rust/crates/core/src/protocol/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,12 @@ pub enum PluginsCommand {
LanguageServersDecodeLaunch,
/// Picks the stored language-server state the host may delete (`plugins.languageServers.stateRetention`).
LanguageServersStateRetention,
/// Lists the bare commands a plugin's launches need and their installers (`plugins.commandInstallers.requirements`).
CommandInstallersRequirements,
/// Expands a command installer for the target the user chose (`plugins.commandInstallers.plan`).
CommandInstallersPlan,
/// Reads where a `toolDefault` installation puts its commands (`plugins.commandInstallers.defaultDirectory`).
CommandInstallersDefaultDirectory,
/// Checks a plugin content provider's answer (`plugins.contentProviders.decode`).
ContentProvidersDecode,
/// Merges a plugin's stored setting layers into effective values (`plugins.declarative.resolveSettings`).
Expand Down Expand Up @@ -994,6 +1000,15 @@ impl CoreCommand {
"plugins.languageServers.stateRetention" => {
Some(Self::Plugins(PluginsCommand::LanguageServersStateRetention))
}
"plugins.commandInstallers.requirements" => {
Some(Self::Plugins(PluginsCommand::CommandInstallersRequirements))
}
"plugins.commandInstallers.plan" => {
Some(Self::Plugins(PluginsCommand::CommandInstallersPlan))
}
"plugins.commandInstallers.defaultDirectory" => Some(Self::Plugins(
PluginsCommand::CommandInstallersDefaultDirectory,
)),
"plugins.contentProviders.decode" => {
Some(Self::Plugins(PluginsCommand::ContentProvidersDecode))
}
Expand Down Expand Up @@ -1601,6 +1616,9 @@ mod tests {
"lsp.pluginServerNotify",
"plugins.languageServers.decodeLaunch",
"plugins.languageServers.stateRetention",
"plugins.commandInstallers.requirements",
"plugins.commandInstallers.plan",
"plugins.commandInstallers.defaultDirectory",
"plugins.contentProviders.decode",
"lsp.cancelOperation",
"lsp.pollEvents",
Expand Down
15 changes: 15 additions & 0 deletions rust/crates/core/src/runtime/dispatcher/plugins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,21 @@ pub(super) fn dispatch(
payload,
lithe_plugin_language_servers::state_retention_command,
),
PluginsCommand::CommandInstallersRequirements => plugin_response(
id,
payload,
lithe_plugin_manifest::command_installer_requirements_command,
),
PluginsCommand::CommandInstallersPlan => plugin_response(
id,
payload,
lithe_plugin_manifest::command_installer_plan_command,
),
PluginsCommand::CommandInstallersDefaultDirectory => plugin_response(
id,
payload,
lithe_plugin_manifest::command_installer_default_directory_command,
),
PluginsCommand::ContentProvidersDecode => plugin_response(
id,
payload,
Expand Down
99 changes: 97 additions & 2 deletions rust/crates/core/src/tests/declarative_plugins.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use lithe_plugin_manifest::{
discover_tests_command, language_server_launch_plan_command, resolve_settings_command,
run_plan_command, test_plan_command, validate_command, workspace_configuration_command,
command_installer_default_directory_command, command_installer_plan_command,
command_installer_requirements_command, discover_tests_command,
language_server_launch_plan_command, resolve_settings_command, run_plan_command,
test_plan_command, validate_command, workspace_configuration_command,
};
use serde_json::{json, Value};

Expand Down Expand Up @@ -63,6 +65,10 @@ const PROJECT_GENERATOR_FIXTURE: &str =
contract_file!("fixtures/project-generators/project-generator.plugin.json");
const PROJECT_GENERATOR_TOOL_FIXTURE: &str =
contract_file!("fixtures/project-generators/project-generator-tool-field.plugin.json");
const COMMAND_INSTALLER_FIXTURE: &str =
contract_file!("fixtures/command-installers/command-installer.plugin.json");
const COMMAND_INSTALLER_PLANS: &str =
contract_file!("fixtures/command-installers/command-installer-plans.json");
const INVALID_MANIFESTS: &str = contract_file!("fixtures/manifest/invalid-manifests.json");
const COMMAND_PLANS: &str = contract_file!("fixtures/languages/command-plans.json");

Expand Down Expand Up @@ -95,6 +101,7 @@ fn fixture(name: &str) -> Value {
"editor-providers.plugin.json" => EDITOR_PROVIDERS_FIXTURE,
"project-generator.plugin.json" => PROJECT_GENERATOR_FIXTURE,
"project-generator-tool-field.plugin.json" => PROJECT_GENERATOR_TOOL_FIXTURE,
"command-installer.plugin.json" => COMMAND_INSTALLER_FIXTURE,
other => panic!("unknown fixture {other}"),
};
serde_json::from_str(source).expect("fixture manifest is JSON")
Expand Down Expand Up @@ -126,6 +133,7 @@ fn contract_fixtures_and_official_plugins_validate() {
LANGUAGE_SERVER_BACKEND_FIXTURE,
EDITOR_PROVIDERS_FIXTURE,
PROJECT_GENERATOR_TOOL_FIXTURE,
COMMAND_INSTALLER_FIXTURE,
] {
let outcome = validate(serde_json::from_str(source).unwrap());
assert_eq!(outcome["status"], "ok", "{outcome}");
Expand Down Expand Up @@ -253,6 +261,93 @@ fn invalid_manifest_fixtures_report_their_stable_codes() {
}
}

/// The command-installer commands answer the golden cases for this host's
/// platform; `lithe-plugin-manifest` checks the same cases for every
/// platform.
#[test]
fn command_installer_fixtures_match_on_this_host() {
let plans: Value = serde_json::from_str(COMMAND_INSTALLER_PLANS).unwrap();
let platform = if cfg!(windows) { "windows" } else { "unix" };
for case in plans["cases"].as_array().unwrap() {
let name = case["name"].as_str().unwrap();
let specific = &case["platforms"][platform];
let mut payload = json!({ "manifest": fixture("command-installer.plugin.json") });
for source in [&case["payload"], &specific["payload"]] {
for (field, value) in source.as_object().into_iter().flatten() {
payload[field] = value.clone();
}
}
for edit in case["manifestEdits"].as_array().into_iter().flatten() {
let pointer = edit["path"].as_str().unwrap();
*payload["manifest"].pointer_mut(pointer).unwrap() = edit["value"].clone();
}
let outcome = match case["operation"].as_str().unwrap() {
"requirements" => command_installer_requirements_command(payload),
"plan" => command_installer_plan_command(payload),
"defaultDirectory" => command_installer_default_directory_command(payload),
other => panic!("unknown operation {other}"),
}
.expect("payload is well formed");
let expected = if specific.get("expected").is_some() {
&specific["expected"]
} else {
&case["expected"]
};
if expected["status"] == "rejected" {
assert_eq!(outcome["status"], "rejected", "{name}: {outcome}");
assert_eq!(
outcome["error"]["code"], expected["code"],
"{name}: {outcome}"
);
assert_eq!(
outcome["error"]["field"], expected["field"],
"{name}: {outcome}"
);
} else {
assert_eq!(&outcome, expected, "{name}");
}
}
}

/// The install review shows everything an installer runs, so changing its
/// arguments or targets is a new program the user approves again.
#[test]
fn command_installers_are_reviewed_programs() {
let programs = |manifest: Value| {
let outcome = lithe_plugin_marketplace::install_review_command(json!({
"manifest": manifest,
}))
.expect("payload is well formed");
outcome["review"]["programs"].as_array().unwrap().clone()
};
let manifest = fixture("command-installer.plugin.json");
let before = programs(manifest.clone());
let installers: Vec<&Value> = before
.iter()
.filter(|program| program["kind"] == "commandInstaller")
.collect();
assert_eq!(installers.len(), 2);
assert_eq!(installers[0]["installer"], "sample-dap");
assert_eq!(installers[1]["timeoutSeconds"], 300);
let mut changed = manifest;
changed["commandInstallers"][0]["arguments"] = json!(["install", "example.org/other@latest"]);
assert_ne!(programs(changed), before);
}

/// A malformed request is a Core failure, not a rejection.
#[test]
fn command_installer_requests_decode_strictly() {
let manifest = fixture("command-installer.plugin.json");
assert!(command_installer_plan_command(
json!({ "manifest": manifest, "installerID": "sample-ls", "target": "elsewhere" })
)
.is_err());
assert!(command_installer_default_directory_command(
json!({ "manifest": manifest, "installerID": "sample-ls" })
)
.is_err());
}

#[test]
fn command_plan_fixtures_match_golden_expansions() {
let fixtures: Value = serde_json::from_str(COMMAND_PLANS).unwrap();
Expand Down
10 changes: 10 additions & 0 deletions rust/crates/diagnostics/src/plugin_operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,22 @@ pub static BUILD_DEPENDENCIES: Contribution = Contribution {
lifecycle: Lifecycle::CommandRun,
};

/// `commandInstallers[]`: one installation the user confirmed, from planning the
/// chosen target to finding every provided command in its directory. A command
/// still missing after a successful exit is the `decode` stage.
pub static COMMAND_INSTALLER_INSTALL: Contribution = Contribution {
operation: "commandInstaller/install",
lifecycle: Lifecycle::CommandRun,
};

/// Every contribution kind this ingress accepts. Supporting a new declarative
/// contract means adding its row here and reporting the same token from its owner.
pub static CONTRIBUTIONS: &[&Contribution] = &[
&LANGUAGE_SERVER_START,
&DEBUG_ADAPTER_START,
&BUILD_MODEL,
&BUILD_DEPENDENCIES,
&COMMAND_INSTALLER_INSTALL,
];

impl Contribution {
Expand Down Expand Up @@ -430,6 +439,7 @@ mod tests {
("debugAdapter/start", Lifecycle::ProcessStart),
("lithe/build/model", Lifecycle::CommandRun),
("lithe/build/dependencies", Lifecycle::CommandRun),
("commandInstaller/install", Lifecycle::CommandRun),
];
let rows: Vec<_> = CONTRIBUTIONS
.iter()
Expand Down
Loading
Loading