Allow task context providers to access project env (#17964)
Closes #13106 Release Notes: - Task context providers now have access to the local shell environment, allowing local rust tool installations to work Before: <img width="1136" alt="Screenshot 2024-09-17 at 22 09 38" src="https://github.com/user-attachments/assets/7d6c5606-4820-4f6f-92d1-c3d314b9ab42"> After: <img width="1136" alt="Screenshot 2024-09-17 at 22 09 58" src="https://github.com/user-attachments/assets/a962e607-15f5-44ce-b53e-a0dbe135f2d8">
This commit is contained in:
parent
d3d3a093b4
commit
8a6c65c63b
6 changed files with 50 additions and 25 deletions
|
@ -4890,21 +4890,6 @@ impl Project {
|
|||
};
|
||||
|
||||
cx.spawn(|project, mut cx| async move {
|
||||
let mut task_variables = cx
|
||||
.update(|cx| {
|
||||
combine_task_variables(
|
||||
captured_variables,
|
||||
location,
|
||||
BasicContextProvider::new(project.upgrade()?),
|
||||
cx,
|
||||
)
|
||||
.log_err()
|
||||
})
|
||||
.ok()
|
||||
.flatten()?;
|
||||
// Remove all custom entries starting with _, as they're not intended for use by the end user.
|
||||
task_variables.sweep();
|
||||
|
||||
let project_env = project
|
||||
.update(&mut cx, |project, cx| {
|
||||
let worktree_abs_path = worktree_abs_path.clone();
|
||||
|
@ -4915,6 +4900,22 @@ impl Project {
|
|||
.ok()?
|
||||
.await;
|
||||
|
||||
let mut task_variables = cx
|
||||
.update(|cx| {
|
||||
combine_task_variables(
|
||||
captured_variables,
|
||||
location,
|
||||
project_env.as_ref(),
|
||||
BasicContextProvider::new(project.upgrade()?),
|
||||
cx,
|
||||
)
|
||||
.log_err()
|
||||
})
|
||||
.ok()
|
||||
.flatten()?;
|
||||
// Remove all custom entries starting with _, as they're not intended for use by the end user.
|
||||
task_variables.sweep();
|
||||
|
||||
Some(TaskContext {
|
||||
project_env: project_env.unwrap_or_default(),
|
||||
cwd: worktree_abs_path.map(|p| p.to_path_buf()),
|
||||
|
@ -5111,6 +5112,7 @@ impl Project {
|
|||
fn combine_task_variables(
|
||||
mut captured_variables: TaskVariables,
|
||||
location: Location,
|
||||
project_env: Option<&HashMap<String, String>>,
|
||||
baseline: BasicContextProvider,
|
||||
cx: &mut AppContext,
|
||||
) -> anyhow::Result<TaskVariables> {
|
||||
|
@ -5120,13 +5122,13 @@ fn combine_task_variables(
|
|||
.language()
|
||||
.and_then(|language| language.context_provider());
|
||||
let baseline = baseline
|
||||
.build_context(&captured_variables, &location, cx)
|
||||
.build_context(&captured_variables, &location, project_env, cx)
|
||||
.context("building basic default context")?;
|
||||
captured_variables.extend(baseline);
|
||||
if let Some(provider) = language_context_provider {
|
||||
captured_variables.extend(
|
||||
provider
|
||||
.build_context(&captured_variables, &location, cx)
|
||||
.build_context(&captured_variables, &location, project_env, cx)
|
||||
.context("building provider context")?,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ use std::{
|
|||
};
|
||||
|
||||
use anyhow::Result;
|
||||
use collections::{btree_map, BTreeMap, VecDeque};
|
||||
use collections::{btree_map, BTreeMap, HashMap, VecDeque};
|
||||
use futures::{
|
||||
channel::mpsc::{unbounded, UnboundedSender},
|
||||
StreamExt,
|
||||
|
@ -543,6 +543,7 @@ impl ContextProvider for BasicContextProvider {
|
|||
&self,
|
||||
_: &TaskVariables,
|
||||
location: &Location,
|
||||
_: Option<&HashMap<String, String>>,
|
||||
cx: &mut AppContext,
|
||||
) -> Result<TaskVariables> {
|
||||
let buffer = location.buffer.read(cx);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue