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:
Piotr Osiewicz 2024-05-22 19:45:43 +02:00 committed by GitHub
parent ba9449692e
commit 58796a8480
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 212 additions and 201 deletions

View file

@ -58,9 +58,7 @@ use std::{
};
use syntax_map::{QueryCursorHandle, SyntaxSnapshot};
use task::RunnableTag;
pub use task_context::{
BasicContextProvider, ContextProvider, ContextProviderWithTasks, RunnableRange,
};
pub use task_context::{ContextProvider, RunnableRange};
use theme::SyntaxTheme;
use tree_sitter::{self, wasmtime, Query, QueryCursor, WasmStore};
@ -1016,7 +1014,7 @@ impl Language {
for (ix, name) in query.capture_names().iter().enumerate() {
if *name == "run" {
run_capture_index = Some(ix as u32);
} else if !name.starts_with('_') {
} else {
runnable_tags.insert(ix as u32, RunnableTag(name.to_string().into()));
}
}