tasks: Expose captured variables to ContextProvider (#12134)
This PR changes the interface of ContextProvider, allowing it to inspect *all* variables set so far during the process of building `TaskVariables`. This makes it possible to capture e.g. an identifier in tree-sitter query, process it and then export it as a task variable. Notably, the list of variables includes captures prefixed with leading underscore; they are removed after all calls to `build_context`, but it makes it possible to capture something and then conditionally preserve it (and perhaps modify it). Release Notes: - N/A
This commit is contained in:
parent
ba9449692e
commit
58796a8480
15 changed files with 212 additions and 201 deletions
|
@ -185,6 +185,20 @@ impl TaskVariables {
|
|||
pub fn extend(&mut self, other: Self) {
|
||||
self.0.extend(other.0);
|
||||
}
|
||||
/// Get the value associated with given variable name, if there is one.
|
||||
pub fn get(&self, key: &VariableName) -> Option<&str> {
|
||||
self.0.get(key).map(|s| s.as_str())
|
||||
}
|
||||
/// Clear out variables obtained from tree-sitter queries, which are prefixed with '_' character
|
||||
pub fn sweep(&mut self) {
|
||||
self.0.retain(|name, _| {
|
||||
if let VariableName::Custom(name) = name {
|
||||
!name.starts_with('_')
|
||||
} else {
|
||||
true
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl FromIterator<(VariableName, String)> for TaskVariables {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue