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
|
@ -3,7 +3,10 @@ use collections::HashMap;
|
|||
use serde::Deserialize;
|
||||
use util::ResultExt;
|
||||
|
||||
use crate::static_source::{Definition, TaskDefinitions};
|
||||
use crate::{
|
||||
static_source::{Definition, TaskDefinitions},
|
||||
VariableName,
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, PartialEq)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
|
@ -129,10 +132,16 @@ impl TryFrom<VsCodeTaskFile> for TaskDefinitions {
|
|||
|
||||
fn try_from(value: VsCodeTaskFile) -> Result<Self, Self::Error> {
|
||||
let replacer = EnvVariableReplacer::new(HashMap::from_iter([
|
||||
("workspaceFolder".to_owned(), "ZED_WORKTREE_ROOT".to_owned()),
|
||||
("file".to_owned(), "ZED_FILE".to_owned()),
|
||||
("lineNumber".to_owned(), "ZED_ROW".to_owned()),
|
||||
("selectedText".to_owned(), "ZED_SELECTED_TEXT".to_owned()),
|
||||
(
|
||||
"workspaceFolder".to_owned(),
|
||||
VariableName::WorktreeRoot.to_string(),
|
||||
),
|
||||
("file".to_owned(), VariableName::File.to_string()),
|
||||
("lineNumber".to_owned(), VariableName::Row.to_string()),
|
||||
(
|
||||
"selectedText".to_owned(),
|
||||
VariableName::SelectedText.to_string(),
|
||||
),
|
||||
]));
|
||||
let definitions = value
|
||||
.tasks
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue