task: Allow obtaining custom task variables from tree-sitter queries (#11624)
From now on, only top-level captures are treated as runnable tags and the rest is appended to task context as custom environmental variables (unless the name is prefixed with _, in which case the capture is ignored). This is most likely gonna help with Pest-like test runners. Release Notes: - N/A --------- Co-authored-by: Remco <djsmits12@gmail.com>
This commit is contained in:
parent
95e246ac1c
commit
bff1d8b142
7 changed files with 126 additions and 67 deletions
|
@ -6,7 +6,7 @@ use anyhow::Context;
|
|||
use gpui::WindowContext;
|
||||
use language::{BasicContextProvider, ContextProvider};
|
||||
use project::{Location, WorktreeId};
|
||||
use task::{TaskContext, TaskVariables};
|
||||
use task::{TaskContext, TaskVariables, VariableName};
|
||||
use util::ResultExt;
|
||||
use workspace::Workspace;
|
||||
|
||||
|
@ -79,7 +79,21 @@ pub(crate) fn task_context_with_editor(
|
|||
buffer,
|
||||
range: start..end,
|
||||
};
|
||||
task_context_for_location(workspace, location, cx)
|
||||
task_context_for_location(workspace, location.clone(), cx).map(|mut task_context| {
|
||||
for range in location
|
||||
.buffer
|
||||
.read(cx)
|
||||
.snapshot()
|
||||
.runnable_ranges(location.range)
|
||||
{
|
||||
for (capture_name, value) in range.extra_captures {
|
||||
task_context
|
||||
.task_variables
|
||||
.insert(VariableName::Custom(capture_name.into()), value);
|
||||
}
|
||||
}
|
||||
task_context
|
||||
})
|
||||
}
|
||||
|
||||
pub fn task_context(workspace: &Workspace, cx: &mut WindowContext<'_>) -> TaskContext {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue