Skip to content

Commit

Permalink
Unite remote and local task variables
Browse files Browse the repository at this point in the history
This fixes gutter task runnables
  • Loading branch information
SomeoneToIgnore committed Oct 4, 2024
1 parent 0b1f27d commit cf89604
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 27 deletions.
27 changes: 15 additions & 12 deletions crates/editor/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4694,15 +4694,15 @@ impl Editor {
value.clone(),
);
}
project
.read(cx)
.task_store()
.read(cx)
.task_context_for_location(
captured_task_variables,
location,
cx,
)
project.update(cx, |project, cx| {
project.task_store().update(cx, |task_store, cx| {
task_store.task_context_for_location(
captured_task_variables,
location,
cx,
)
})
})
});

Some(cx.spawn(|editor, mut cx| async move {
Expand Down Expand Up @@ -9122,9 +9122,12 @@ impl Editor {
.as_ref()
.into_iter()
.flat_map(|inventory| {
inventory
.read(cx)
.list_tasks(file.clone(), None, worktree_id, cx)
inventory.read(cx).list_tasks(
file.clone(),
Some(runnable.language.clone()),
worktree_id,
cx,
)
})
.filter(move |(_, template)| {
template.tags.iter().any(|source_tag| source_tag == &tag)
Expand Down
10 changes: 5 additions & 5 deletions crates/editor/src/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ fn task_context_with_editor(
variables
};

project
.read(cx)
.task_store()
.read(cx)
.task_context_for_location(captured_variables, location, cx)
project.update(cx, |project, cx| {
project.task_store().update(cx, |task_store, cx| {
task_store.task_context_for_location(captured_variables, location, cx)
})
})
}

pub fn task_context(workspace: &Workspace, cx: &mut WindowContext<'_>) -> AsyncTask<TaskContext> {
Expand Down
1 change: 1 addition & 0 deletions crates/project/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,7 @@ impl Project {
.await
}

#[allow(clippy::too_many_arguments)]
async fn from_join_project_response(
response: TypedEnvelope<proto::JoinProjectResponse>,
subscriptions: [EntitySubscription; 5],
Expand Down
45 changes: 36 additions & 9 deletions crates/project/src/task_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ impl TaskSettingsStore for TaskSettings {
worktree: Option<WorktreeId>,
templates: RawTaskTemplates<'a>,
) {
// TODO kb logging or a pop-up (separatee per kind of templates?)
let mut bad_templates = 0;

match worktree {
Expand Down Expand Up @@ -169,14 +170,13 @@ impl TaskStore {
.location
.context("no location given for task context handling")?;
let (buffer_store, is_remote) = store.update(&mut cx, |store, _| {
let (store, is_remote) = match store {
Ok(match store {
TaskStore::Local { buffer_store, .. } => (buffer_store.clone(), false),
TaskStore::Remote { buffer_store, .. } => (buffer_store.clone(), true),
TaskStore::Empty => {
anyhow::bail!("empty task store cannot handle task context requests")
}
};
Ok((store, is_remote))
})
})??;
let buffer_store = buffer_store
.upgrade()
Expand Down Expand Up @@ -216,9 +216,15 @@ impl TaskStore {
range: start..end,
};
let context_task = store.update(&mut cx, |store, cx| {
// TODO kb why not send the original task variables from the client?
let captured_variables = {
let mut variables = TaskVariables::default();
let mut variables = TaskVariables::from_iter(
envelope
.payload
.task_variables
.into_iter()
.filter_map(|(k, v)| Some((k.parse().log_err()?, v))),
);

for range in location
.buffer
.read(cx)
Expand Down Expand Up @@ -282,7 +288,7 @@ impl TaskStore {
&self,
captured_variables: TaskVariables,
location: Location,
cx: &AppContext,
cx: &mut AppContext,
) -> Task<Option<TaskContext>> {
match self {
TaskStore::Local {
Expand All @@ -297,8 +303,16 @@ impl TaskStore {
cx,
),
TaskStore::Remote {
upstream_client, ..
} => remote_task_context_for_location(upstream_client, location, cx),
upstream_client,
worktree_store,
..
} => remote_task_context_for_location(
upstream_client,
worktree_store.clone(),
captured_variables,
location,
cx,
),
TaskStore::Empty => Task::ready(None),
}
}
Expand Down Expand Up @@ -386,16 +400,29 @@ fn local_task_context_for_location(

fn remote_task_context_for_location(
upstream_client: &AnyProtoClient,
worktree_store: Model<WorktreeStore>,
captured_variables: TaskVariables,
location: Location,
cx: &AppContext,
cx: &mut AppContext,
) -> Task<Option<TaskContext>> {
// We need to gather a client context, as the headless one may lack certain information (e.g. tree-sitter parsing is disabled there, so symbols are not available).
let mut remote_context = BasicContextProvider::new(worktree_store)
.build_context(&TaskVariables::default(), &location, None, cx)
.log_err()
.unwrap_or_default();
remote_context.extend(captured_variables);

let context_task = upstream_client.request(proto::TaskContextForLocation {
project_id: SSH_PROJECT_ID,
location: Some(proto::Location {
buffer_id: location.buffer.read(cx).remote_id().into(),
start: Some(serialize_anchor(&location.range.start)),
end: Some(serialize_anchor(&location.range.end)),
}),
task_variables: remote_context
.into_iter()
.map(|(k, v)| (k.to_string(), v))
.collect(),
});
cx.spawn(|_| async move {
let task_context = context_task.await.log_err()?;
Expand Down
1 change: 1 addition & 0 deletions crates/proto/proto/zed.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2257,6 +2257,7 @@ message GetSupermavenApiKeyResponse {
message TaskContextForLocation {
uint64 project_id = 1;
Location location = 2;
map<string, string> task_variables = 3;
}

message TaskContext {
Expand Down
1 change: 0 additions & 1 deletion crates/task/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ impl VariableName {
impl FromStr for VariableName {
type Err = ();

// TODO kb need a derive instead
fn from_str(s: &str) -> Result<Self, Self::Err> {
let without_prefix = s.strip_prefix(ZED_VARIABLE_NAME_PREFIX).ok_or(())?;
let value = match without_prefix {
Expand Down

0 comments on commit cf89604

Please sign in to comment.