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
30 changes: 22 additions & 8 deletions rust/contracts/run-configuration-v2.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
},
"runTypeReference": {
"type": "object",
"description": "A configuration of a run configuration type a build system declares (buildSystems[].runConfigurationTypes).",
"description": "A configuration of a run configuration type a build system declares (buildSystems[].runConfigurationTypes), or a before-launch task step of a task it declares (buildSystems[].beforeLaunchTasks).",
"required": ["pluginID", "buildSystemID", "type"],
"properties": {
"pluginID": { "$ref": "#/$defs/runTypeIdentifier" },
Expand Down Expand Up @@ -258,14 +258,28 @@
"beforeLaunch": {
"type": "array",
"maxItems": 16,
"description": "Built-in process runs started in order before this one; each must exit with 0 first. A layer replaces the whole list.",
"description": "Steps started in order before this one: built-in process runs and tasks installed plugins declare; each must exit with 0 first. A layer replaces the whole list.",
"items": {
"type": "object",
"required": ["configuration"],
"properties": {
"configuration": { "type": "string", "minLength": 1, "maxLength": 256 }
},
"additionalProperties": false
"oneOf": [
{
"type": "object",
"description": "A built-in process run of the same project to start first.",
"required": ["configuration"],
"properties": {
"configuration": { "type": "string", "minLength": 1, "maxLength": 256 }
},
"additionalProperties": false
},
{
"type": "object",
"description": "A task a plugin declares, run in this configuration's working directory.",
"required": ["task"],
"properties": {
"task": { "$ref": "#/$defs/runTypeReference" }
},
"additionalProperties": false
}
]
}
},
"disabled": { "type": "boolean" },
Expand Down
135 changes: 99 additions & 36 deletions rust/contracts/rust-core-api.md

Large diffs are not rendered by default.

38 changes: 37 additions & 1 deletion rust/crates/build/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use super::outputs::{
DecodeTestResultsRequest, SyncFingerprintRequest,
};
use super::plans::{self, OutputPlanRequest, TaskPlanRequest, TestPlanRequest};
use super::run_types::{self, RunConfigurationPlanRequest};
use super::run_types::{self, BeforeLaunchTaskPlanRequest, RunConfigurationPlanRequest};
use super::test_discovery::{self, DecodeTestDiscoveryRequest};
use super::tree::{self, ModelTreeRequest};
use super::BuildManifest;
Expand Down Expand Up @@ -147,6 +147,42 @@ pub fn build_run_configuration_plan_command<M: BuildManifest>(
)))
}

/// `build.beforeLaunchTaskPlan`: the argv plan of a before-launch task step
/// as `runConfig.beforeLaunch` returned it, in `workspaceRoot`, which it
/// requires. A task the build system no longer declares, a working directory
/// outside the project, or values the task cannot run fail the call.
pub fn build_before_launch_task_plan_command<M: BuildManifest>(
payload: Value,
) -> Result<Value, CoreError> {
let command = "build.beforeLaunchTaskPlan";
let payload: BuildPayload<BeforeLaunchTaskPlanRequest> = decode_payload(payload, command)?;
let workspace_root = payload.workspace_root.as_deref().ok_or_else(|| {
CoreError::new(
ErrorCode::InvalidRequest,
"build.beforeLaunchTaskPlan needs workspaceRoot",
)
})?;
let request = &payload.request;
let launch = lithe_execution::declared_task_launch(
workspace_root,
request.task.clone(),
&request.working_directory,
)?;
Ok(outcome(M::validate(payload.manifest).and_then(
|manifest| {
let build_system = find_build_system(&manifest, &payload.build_system_id)?;
run_types::before_launch_task_plan(
manifest.id(),
build_system,
&launch,
request,
&launch.root,
)
.map(|plan| ("plan", plan))
},
)))
}

/// `build.detect`: build-system instances of a workspace, with the models
/// that need no process.
pub fn build_detect_command<M: BuildManifest>(payload: Value) -> Result<Value, CoreError> {
Expand Down
6 changes: 6 additions & 0 deletions rust/crates/build/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ pub struct BuildSystemDeclaration {
/// Configurations dialog; `runConfigurationTypes` 0.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub(crate) run_configuration_types: Vec<RunTypeDeclaration>,
/// Kinds of step a configuration runs before it starts, offered in the
/// "Add New Task" menu of its Before Launch list; `beforeLaunchTasks` 0.
/// They are declared like run configuration types, without an execution
/// or program arguments.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub(crate) before_launch_tasks: Vec<RunTypeDeclaration>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub(crate) test: Option<TestDeclaration>,
#[serde(default, skip_serializing_if = "Option::is_none")]
Expand Down
23 changes: 23 additions & 0 deletions rust/crates/build/src/manifest/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,26 @@ fn program(build_system: &BuildSystemDeclaration) -> Value {
})
})
.collect();
// A task's command line runs like a run configuration's, so it is
// reviewed the same way; it has no execution.
let before_launch_tasks: Vec<Value> = build_system
.before_launch_tasks
.iter()
.map(|task| {
json!({
"id": task.id,
"arguments": task.arguments,
"fields": task.fields.iter().map(|field| json!({
"id": field.id,
"kind": field.kind,
"default": field.default,
"choices": field.choices.iter().map(|choice| &choice.value).collect::<Vec<_>>(),
"visibleWhen": field.visible_when,
"arguments": field.arguments,
})).collect::<Vec<_>>(),
})
})
.collect();
let mut program = json!({
"kind": "buildSystem",
"buildSystemID": build_system.id,
Expand All @@ -111,6 +131,9 @@ fn program(build_system: &BuildSystemDeclaration) -> Value {
if !run_types.is_empty() {
program["runConfigurationTypes"] = json!(run_types);
}
if !before_launch_tasks.is_empty() {
program["beforeLaunchTasks"] = json!(before_launch_tasks);
}
// Build requests reaching a language server change what that process
// is asked to do, so the shared form is part of this entry.
if let Some(ProviderDeclaration::LanguageServer(shared)) = &build_system.provider {
Expand Down
6 changes: 6 additions & 0 deletions rust/crates/build/src/manifest/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,12 @@ impl BuildSystemDeclaration {
&run_type.arguments,
));
}
for (index, task) in self.before_launch_tasks.iter().enumerate() {
lists.push((
format!("{field}.beforeLaunchTasks[{index}].arguments"),
&task.arguments,
));
}
if let Some(test) = &self.test {
lists.push((format!("{field}.test.arguments"), &test.arguments));
}
Expand Down
114 changes: 89 additions & 25 deletions rust/crates/build/src/manifest/run_types.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
//! `runConfigurationTypes`: kinds of run configuration a build system adds to
//! the Run/Debug Configurations dialog.
//! the Run/Debug Configurations dialog, and `beforeLaunchTasks`: kinds of step
//! a configuration runs before it starts.
//!
//! A type is data only: the fields its editor shows and the argv template
//! those fields fill. The host draws the fields Core describes, Core checks
//! and stores the values, and a run expands the template with them, so a
//! plugin adds a configuration kind such as `Go Build` without a backend.
//! A before-launch task is declared the same way; it runs to completion in
//! the owning configuration's working directory and takes no program
//! arguments, so it has neither an `execution` nor `${userArguments}`.

use super::*;

Expand All @@ -14,7 +18,8 @@ const MAX_FIELD_ARGUMENTS: usize = 8;
/// Longest description of a type or a field.
const MAX_DESCRIPTION: usize = 512;

/// One kind of run configuration the user can create.
/// One kind of run configuration the user can create, or one kind of
/// before-launch task.
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub(crate) struct RunTypeDeclaration {
Expand Down Expand Up @@ -91,6 +96,25 @@ pub(crate) enum RunFieldKind {
Arguments,
}

/// Which list of a build system a declaration belongs to.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum RunTypeRole {
/// `runConfigurationTypes`: a configuration the user creates and runs.
Configuration,
/// `beforeLaunchTasks`: a step of another configuration's Before Launch list.
BeforeLaunchTask,
}

impl RunTypeRole {
/// The manifest key of the list.
pub(crate) fn key(self) -> &'static str {
match self {
Self::Configuration => "runConfigurationTypes",
Self::BeforeLaunchTask => "beforeLaunchTasks",
}
}
}

impl RunFieldKind {
/// Whether another field can be shown depending on this one's value.
fn controls_visibility(self) -> bool {
Expand All @@ -113,9 +137,23 @@ impl BuildSystemDeclaration {
!self.run_configuration_types.is_empty()
}

/// The run configuration type `id`.
pub(crate) fn run_type(&self, id: &str) -> Option<&RunTypeDeclaration> {
self.run_configuration_types
/// Whether the build system adds before-launch tasks, which
/// `beforeLaunchTasks` introduced.
pub fn has_before_launch_tasks(&self) -> bool {
!self.before_launch_tasks.is_empty()
}

/// The declarations of one list.
pub(crate) fn run_types(&self, role: RunTypeRole) -> &[RunTypeDeclaration] {
match role {
RunTypeRole::Configuration => &self.run_configuration_types,
RunTypeRole::BeforeLaunchTask => &self.before_launch_tasks,
}
}

/// The declaration `id` of one list.
pub(crate) fn run_type(&self, role: RunTypeRole, id: &str) -> Option<&RunTypeDeclaration> {
self.run_types(role)
.iter()
.find(|run_type| run_type.id == id)
}
Expand All @@ -125,22 +163,32 @@ impl BuildSystemDeclaration {
field: &str,
options: &BTreeSet<String>,
) -> Validation<()> {
if self.run_configuration_types.len() > MAX_RUN_TYPES {
return Err(invalid(
format!("{field}.runConfigurationTypes"),
"Too many run configuration types.",
));
}
let mut ids = BTreeSet::new();
for (index, run_type) in self.run_configuration_types.iter().enumerate() {
let field = format!("{field}.runConfigurationTypes[{index}]");
if !is_entry_identifier(&run_type.id) || !ids.insert(run_type.id.clone()) {
for role in [RunTypeRole::Configuration, RunTypeRole::BeforeLaunchTask] {
let list = format!("{field}.{}", role.key());
let declarations = self.run_types(role);
if declarations.len() > MAX_RUN_TYPES {
return Err(invalid(
format!("{field}.id"),
"Run configuration type IDs are unique identifiers that start with a letter.",
list,
match role {
RunTypeRole::Configuration => "Too many run configuration types.",
RunTypeRole::BeforeLaunchTask => "Too many before-launch tasks.",
},
));
}
run_type.validate(&field, options)?;
let mut ids = BTreeSet::new();
for (index, run_type) in declarations.iter().enumerate() {
let field = format!("{list}[{index}]");
if !is_entry_identifier(&run_type.id) || !ids.insert(run_type.id.clone()) {
return Err(invalid(
format!("{field}.id"),
match role {
RunTypeRole::Configuration => "Run configuration type IDs are unique identifiers that start with a letter.",
RunTypeRole::BeforeLaunchTask => "Before-launch task IDs are unique identifiers that start with a letter.",
},
));
}
run_type.validate(&field, options, role)?;
}
}
Ok(())
}
Expand All @@ -157,7 +205,12 @@ impl RunTypeDeclaration {
template::user_argument_references(&self.arguments) == 1
}

fn validate(&self, field: &str, options: &BTreeSet<String>) -> Validation<()> {
fn validate(
&self,
field: &str,
options: &BTreeSet<String>,
role: RunTypeRole,
) -> Validation<()> {
check_text(
&self.display_name,
&format!("{field}.displayName"),
Expand All @@ -169,11 +222,20 @@ impl RunTypeDeclaration {
if let Some(icon) = &self.icon {
icon.validate_at(&format!("{field}.icon"))?;
}
if self.execution == Some(BuildExecution::Service) {
return Err(invalid(
format!("{field}.execution"),
"A run configuration type runs an application or a task.",
));
match role {
RunTypeRole::Configuration if self.execution == Some(BuildExecution::Service) => {
return Err(invalid(
format!("{field}.execution"),
"A run configuration type runs an application or a task.",
));
}
RunTypeRole::BeforeLaunchTask if self.execution.is_some() => {
return Err(invalid(
format!("{field}.execution"),
"A before-launch task always runs to completion; it declares no execution.",
));
}
_ => {}
}
if self.fields.len() > MAX_RUN_FIELDS {
return Err(invalid(format!("{field}.fields"), "Too many fields."));
Expand All @@ -191,9 +253,11 @@ impl RunTypeDeclaration {
}
let arguments_field = format!("{field}.arguments");
check_argument_count(&self.arguments, &arguments_field)?;
// A before-launch task has no program arguments field, so its
// command line cannot name them.
let allowed = Allowed {
root: true,
user_arguments: true,
user_arguments: role == RunTypeRole::Configuration,
options: Some(options),
fields: Some(&ids),
..Allowed::none()
Expand Down
Loading
Loading