Stricten Zed Task variable API (#10163)
Introduce `VariableName` enum to simplify Zed task templating management: now all the variables can be looked up statically and can be checked/modified in a centralized way: e.g. `ZED_` prefix is now added for all such custom vars. Release Notes: - N/A
This commit is contained in:
parent
ee1b1779f1
commit
1085642c88
10 changed files with 188 additions and 91 deletions
|
@ -13,7 +13,7 @@ use smol::fs::{self, File};
|
|||
use std::{any::Any, borrow::Cow, env::consts, path::PathBuf, sync::Arc};
|
||||
use task::{
|
||||
static_source::{Definition, TaskDefinitions},
|
||||
TaskVariables,
|
||||
TaskVariables, VariableName,
|
||||
};
|
||||
use util::{
|
||||
fs::remove_matching,
|
||||
|
@ -322,6 +322,9 @@ impl LspAdapter for RustLspAdapter {
|
|||
|
||||
pub(crate) struct RustContextProvider;
|
||||
|
||||
const RUST_PACKAGE_TASK_VARIABLE: VariableName =
|
||||
VariableName::Custom(Cow::Borrowed("RUST_PACKAGE"));
|
||||
|
||||
impl ContextProvider for RustContextProvider {
|
||||
fn build_context(
|
||||
&self,
|
||||
|
@ -347,19 +350,24 @@ impl ContextProvider for RustContextProvider {
|
|||
.ok();
|
||||
|
||||
if let Some(package_name) = package_name {
|
||||
context.0.insert("ZED_PACKAGE".to_owned(), package_name);
|
||||
context.insert(RUST_PACKAGE_TASK_VARIABLE.clone(), package_name);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(context)
|
||||
}
|
||||
|
||||
fn associated_tasks(&self) -> Option<TaskDefinitions> {
|
||||
Some(TaskDefinitions(vec![
|
||||
Definition {
|
||||
label: "Rust: Test current crate".to_owned(),
|
||||
command: "cargo".into(),
|
||||
args: vec!["test".into(), "-p".into(), "$ZED_PACKAGE".into()],
|
||||
..Default::default()
|
||||
args: vec![
|
||||
"test".into(),
|
||||
"-p".into(),
|
||||
RUST_PACKAGE_TASK_VARIABLE.template_value(),
|
||||
],
|
||||
..Definition::default()
|
||||
},
|
||||
Definition {
|
||||
label: "Rust: Test current function".to_owned(),
|
||||
|
@ -367,29 +375,33 @@ impl ContextProvider for RustContextProvider {
|
|||
args: vec![
|
||||
"test".into(),
|
||||
"-p".into(),
|
||||
"$ZED_PACKAGE".into(),
|
||||
RUST_PACKAGE_TASK_VARIABLE.template_value(),
|
||||
"--".into(),
|
||||
"$ZED_SYMBOL".into(),
|
||||
VariableName::Symbol.template_value(),
|
||||
],
|
||||
..Default::default()
|
||||
..Definition::default()
|
||||
},
|
||||
Definition {
|
||||
label: "Rust: cargo run".into(),
|
||||
command: "cargo".into(),
|
||||
args: vec!["run".into()],
|
||||
..Default::default()
|
||||
..Definition::default()
|
||||
},
|
||||
Definition {
|
||||
label: "Rust: cargo check current crate".into(),
|
||||
command: "cargo".into(),
|
||||
args: vec!["check".into(), "-p".into(), "$ZED_PACKAGE".into()],
|
||||
..Default::default()
|
||||
args: vec![
|
||||
"check".into(),
|
||||
"-p".into(),
|
||||
RUST_PACKAGE_TASK_VARIABLE.template_value(),
|
||||
],
|
||||
..Definition::default()
|
||||
},
|
||||
Definition {
|
||||
label: "Rust: cargo check workspace".into(),
|
||||
command: "cargo".into(),
|
||||
args: vec!["check".into(), "--workspace".into()],
|
||||
..Default::default()
|
||||
..Definition::default()
|
||||
},
|
||||
]))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue