Add initial package.json scripts task autodetection (#32497)

Now, every JS/TS-related file will get their package.json script
contents added as tasks:

<img width="1020" alt="image"
src="https://github.com/user-attachments/assets/5bf80f80-fd72-4ba8-8ccf-418872895a25"
/>

To achieve that, `fn associated_tasks` from the `ContextProvider` was
made asynchronous and the related code adjusted.

Release Notes:

- Added initial `package.json` scripts task autodetection

---------

Co-authored-by: Piotr Osiewicz <piotr@zed.dev>
This commit is contained in:
Kirill Bulatov 2025-06-11 01:16:27 +03:00 committed by GitHub
parent 0c0933d1c0
commit 9c513223c4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 782 additions and 661 deletions

View file

@ -260,13 +260,14 @@ impl PickerDelegate for TasksModalDelegate {
Some(candidates) => Task::ready(string_match_candidates(candidates)),
None => {
if let Some(task_inventory) = self.task_store.read(cx).task_inventory().cloned() {
let (used, current) = task_inventory
.read(cx)
.used_and_current_resolved_tasks(&self.task_contexts, cx);
let task_list = task_inventory.update(cx, |this, cx| {
this.used_and_current_resolved_tasks(self.task_contexts.clone(), cx)
});
let workspace = self.workspace.clone();
let lsp_task_sources = self.task_contexts.lsp_task_sources.clone();
let task_position = self.task_contexts.latest_selection;
cx.spawn(async move |picker, cx| {
let (used, current) = task_list.await;
let Ok((lsp_tasks, prefer_lsp)) = workspace.update(cx, |workspace, cx| {
let lsp_tasks = editor::lsp_tasks(
workspace.project().clone(),

View file

@ -192,31 +192,33 @@ where
task_contexts(workspace, window, cx)
})?;
let task_contexts = task_contexts.await;
let mut tasks = workspace.update(cx, |workspace, cx| {
let Some(task_inventory) = workspace
.project()
.read(cx)
.task_store()
.read(cx)
.task_inventory()
.cloned()
else {
return Vec::new();
};
let (file, language) = task_contexts
.location()
.map(|location| {
let buffer = location.buffer.read(cx);
(
buffer.file().cloned(),
buffer.language_at(location.range.start),
)
})
.unwrap_or_default();
task_inventory
.read(cx)
.list_tasks(file, language, task_contexts.worktree(), cx)
})?;
let mut tasks = workspace
.update(cx, |workspace, cx| {
let Some(task_inventory) = workspace
.project()
.read(cx)
.task_store()
.read(cx)
.task_inventory()
.cloned()
else {
return Task::ready(Vec::new());
};
let (file, language) = task_contexts
.location()
.map(|location| {
let buffer = location.buffer.read(cx);
(
buffer.file().cloned(),
buffer.language_at(location.range.start),
)
})
.unwrap_or_default();
task_inventory
.read(cx)
.list_tasks(file, language, task_contexts.worktree(), cx)
})?
.await;
let did_spawn = workspace
.update_in(cx, |workspace, window, cx| {