@@ -35,6 +35,17 @@ pub(crate) struct RunDeclaration {
3535 /// project. It applies to no target and is never listed per target.
3636 #[serde(default, skip_serializing_if = "std::ops::Not::not")]
3737 pub(crate) entrypoints: bool,
38+ /// ID of a `runConfigurationTypes` entry in this build system. Each
39+ /// matching target materializes a generated configuration of that declared
40+ /// kind instead of a raw command or provider run, sharing the kind's icon,
41+ /// group and editor form.
42+ #[serde(default, skip_serializing_if = "Option::is_none")]
43+ pub(crate) configuration_type: Option<String>,
44+ /// Initial field values for `configurationType`, keyed by declared field
45+ /// ID. String values and `arguments` list items may reference target and
46+ /// project template variables.
47+ #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
48+ pub(crate) values: BTreeMap<String, Value>,
3849}
3950
4051/// Native launch binds a local adapter; connection attach names a public registry type.
@@ -107,6 +118,71 @@ impl BuildSystemDeclaration {
107118 "Run IDs are unique identifiers that start with a letter.",
108119 ));
109120 }
121+ if !run.values.is_empty() && run.configuration_type.is_none() {
122+ return Err(invalid(
123+ format!("{field}.values"),
124+ "Run field values require configurationType.",
125+ ));
126+ }
127+ if let Some(type_id) = run.configuration_type.as_deref() {
128+ if run.source == TaskSource::Provider
129+ || run.debug.is_some()
130+ || run.entrypoints
131+ || run.from_tasks.is_some()
132+ || !run.arguments.is_empty()
133+ || !run.extension.is_empty()
134+ || run.execution.is_some()
135+ {
136+ return Err(invalid(
137+ &field,
138+ "A run entry with configurationType uses target tags, field values, and the declared type's command line.",
139+ ));
140+ }
141+ let Some(targets) = &mut run.from_targets else {
142+ return Err(invalid(
143+ format!("{field}.fromTargets"),
144+ "A run entry with configurationType requires fromTargets.",
145+ ));
146+ };
147+ if targets.tags.is_empty()
148+ || targets.tags.len() > MAX_LIST
149+ || targets.tags.iter().any(|tag| !is_tag(tag))
150+ {
151+ return Err(invalid(
152+ format!("{field}.fromTargets.tags"),
153+ "fromTargets needs one or more tag identifiers.",
154+ ));
155+ }
156+ targets.tags = sorted_unique(std::mem::take(&mut targets.tags));
157+ let Some(run_type) = self
158+ .run_configuration_types
159+ .iter()
160+ .find(|declared| declared.id == type_id)
161+ else {
162+ return Err(invalid(
163+ format!("{field}.configurationType"),
164+ format!(
165+ "configurationType {type_id} is not declared in runConfigurationTypes."
166+ ),
167+ ));
168+ };
169+ let allowed = Allowed {
170+ root: true,
171+ project: Availability::Always,
172+ target: Availability::Always,
173+ ..Allowed::none()
174+ };
175+ if let Some(name) = &run.name {
176+ template::validate_text(name, &allowed, &format!("{field}.name"))?;
177+ }
178+ validate_run_type_values(
179+ run_type,
180+ &run.values,
181+ &allowed,
182+ &format!("{field}.values"),
183+ )?;
184+ continue;
185+ }
110186 if run.debug.is_some() && run.source != TaskSource::Provider {
111187 return Err(invalid(
112188 &field,
@@ -259,3 +335,125 @@ impl BuildSystemDeclaration {
259335 Ok(())
260336 }
261337}
338+
339+ /// Checks `values` of a `buildSystems[].run[]` entry that targets `run_type`.
340+ fn validate_run_type_values(
341+ run_type: &RunTypeDeclaration,
342+ values: &BTreeMap<String, Value>,
343+ allowed: &Allowed<'_>,
344+ field: &str,
345+ ) -> Validation<()> {
346+ for (id, value) in values {
347+ let value_field = format!("{field}.{id}");
348+ let Some(declared) = run_type.fields.iter().find(|entry| entry.id == *id) else {
349+ return Err(invalid(
350+ value_field,
351+ format!(
352+ "{id} is not a field of runConfigurationType {}.",
353+ run_type.id
354+ ),
355+ ));
356+ };
357+ match (declared.kind, value) {
358+ (
359+ RunFieldKind::Text
360+ | RunFieldKind::Choice
361+ | RunFieldKind::File
362+ | RunFieldKind::Directory,
363+ Value::String(text),
364+ ) => {
365+ if text.len() > MAX_TEXT || text.contains('\0') {
366+ return Err(invalid(value_field, "Field value is invalid."));
367+ }
368+ template::validate_text(text, allowed, &value_field)?;
369+ if declared.kind == RunFieldKind::Choice
370+ && !text.contains("${")
371+ && !declared.choices.iter().any(|choice| choice.value == *text)
372+ {
373+ return Err(invalid(
374+ value_field,
375+ "Choice field value must match one of the declared choices.",
376+ ));
377+ }
378+ }
379+ (RunFieldKind::Checkbox, Value::Bool(_)) => {}
380+ (RunFieldKind::Arguments, Value::Array(items)) => {
381+ if items.len() > 64 {
382+ return Err(invalid(value_field, "Too many arguments in field value."));
383+ }
384+ for (item_index, item) in items.iter().enumerate() {
385+ let Some(text) = item.as_str() else {
386+ return Err(invalid(
387+ format!("{value_field}[{item_index}]"),
388+ "Arguments field values must be strings.",
389+ ));
390+ };
391+ if text.len() > MAX_TEXT || text.contains('\0') {
392+ return Err(invalid(
393+ format!("{value_field}[{item_index}]"),
394+ "Field value is invalid.",
395+ ));
396+ }
397+ template::validate_text(
398+ text,
399+ allowed,
400+ &format!("{value_field}[{item_index}]"),
401+ )?;
402+ }
403+ }
404+ _ => {
405+ return Err(invalid(
406+ value_field,
407+ "Field value does not match the declared field kind.",
408+ ));
409+ }
410+ }
411+ }
412+
413+ // Ensure every visible required field without a default is supplied.
414+ let mut effective: BTreeMap<&str, Value> = BTreeMap::new();
415+ for declared in &run_type.fields {
416+ let visible = declared.visible_when.as_ref().is_none_or(|condition| {
417+ effective
418+ .get(condition.field.as_str())
419+ .is_some_and(|actual| *actual == condition.equals)
420+ });
421+ if !visible {
422+ continue;
423+ }
424+ let chosen = values
425+ .get(&declared.id)
426+ .cloned()
427+ .or_else(|| declared.default.clone())
428+ .or_else(|| {
429+ (declared.kind == RunFieldKind::Choice)
430+ .then(|| {
431+ declared
432+ .choices
433+ .first()
434+ .map(|choice| Value::String(choice.value.clone()))
435+ })
436+ .flatten()
437+ })
438+ .or_else(|| (declared.kind == RunFieldKind::Checkbox).then_some(Value::Bool(false)));
439+ let empty = match &chosen {
440+ None => true,
441+ Some(Value::String(text)) => text.trim().is_empty(),
442+ Some(Value::Array(items)) => items.is_empty(),
443+ Some(_) => false,
444+ };
445+ if declared.required && empty {
446+ return Err(invalid(
447+ format!("{field}.{}", declared.id),
448+ format!(
449+ "Required field {} of runConfigurationType {} must have a value or default.",
450+ declared.id, run_type.id
451+ ),
452+ ));
453+ }
454+ if let Some(chosen) = chosen {
455+ effective.insert(&declared.id, chosen);
456+ }
457+ }
458+ Ok(())
459+ }
0 commit comments