Support tasks from rust-analyzer (#28359)
(and any other LSP server in theory, if it exposes any LSP-ext endpoint for the same) Closes https://github.com/zed-industries/zed/issues/16160 * adds a way to disable tree-sitter tasks (the ones from the plugins, enabled by default) with ```json5 "languages": { "Rust": "tasks": { "enabled": false } } } ``` language settings * adds a way to disable LSP tasks (the ones from the rust-analyzer language server, enabled by default) with ```json5 "lsp": { "rust-analyzer": { "enable_lsp_tasks": false, } } ``` * adds rust-analyzer tasks into tasks modal and gutter: <img width="1728" alt="modal" src="https://github.com/user-attachments/assets/22b9cee1-4ffb-4c9e-b1f1-d01e80e72508" /> <img width="396" alt="gutter" src="https://github.com/user-attachments/assets/bd818079-e247-4332-bdb5-1b7cb1cce768" /> Release Notes: - Added tasks from rust-analyzer
This commit is contained in:
parent
763cc6dba3
commit
39c98ce882
24 changed files with 882 additions and 201 deletions
|
@ -13,11 +13,13 @@ path = "src/tasks_ui.rs"
|
|||
|
||||
[dependencies]
|
||||
anyhow.workspace = true
|
||||
collections.workspace = true
|
||||
debugger_ui.workspace = true
|
||||
editor.workspace = true
|
||||
file_icons.workspace = true
|
||||
fuzzy.workspace = true
|
||||
feature_flags.workspace = true
|
||||
itertools.workspace = true
|
||||
gpui.workspace = true
|
||||
menu.workspace = true
|
||||
picker.workspace = true
|
||||
|
|
|
@ -7,6 +7,7 @@ use gpui::{
|
|||
Focusable, InteractiveElement, ParentElement, Render, SharedString, Styled, Subscription, Task,
|
||||
WeakEntity, Window, rems,
|
||||
};
|
||||
use itertools::Itertools;
|
||||
use picker::{Picker, PickerDelegate, highlighted_match_with_paths::HighlightedMatch};
|
||||
use project::{TaskSourceKind, task_store::TaskStore};
|
||||
use task::{
|
||||
|
@ -221,42 +222,66 @@ impl PickerDelegate for TasksModalDelegate {
|
|||
cx: &mut Context<picker::Picker<Self>>,
|
||||
) -> Task<()> {
|
||||
let task_type = self.task_modal_type.clone();
|
||||
cx.spawn_in(window, async move |picker, cx| {
|
||||
let Some(candidates) = picker
|
||||
.update(cx, |picker, cx| match &mut picker.delegate.candidates {
|
||||
Some(candidates) => string_match_candidates(candidates.iter(), task_type),
|
||||
None => {
|
||||
let Some(task_inventory) = picker
|
||||
.delegate
|
||||
.task_store
|
||||
.read(cx)
|
||||
.task_inventory()
|
||||
.cloned()
|
||||
else {
|
||||
let candidates = match &self.candidates {
|
||||
Some(candidates) => Task::ready(string_match_candidates(candidates, task_type)),
|
||||
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 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 Ok(lsp_tasks) = workspace.update(cx, |workspace, cx| {
|
||||
editor::lsp_tasks(
|
||||
workspace.project().clone(),
|
||||
&lsp_task_sources,
|
||||
task_position,
|
||||
cx,
|
||||
)
|
||||
}) else {
|
||||
return Vec::new();
|
||||
};
|
||||
|
||||
let (used, current) = task_inventory
|
||||
.read(cx)
|
||||
.used_and_current_resolved_tasks(&picker.delegate.task_contexts, cx);
|
||||
picker.delegate.last_used_candidate_index = if used.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(used.len() - 1)
|
||||
};
|
||||
let lsp_tasks = lsp_tasks.await;
|
||||
picker
|
||||
.update(cx, |picker, _| {
|
||||
picker.delegate.last_used_candidate_index = if used.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(used.len() - 1)
|
||||
};
|
||||
|
||||
let mut new_candidates = used;
|
||||
new_candidates.extend(current);
|
||||
let match_candidates =
|
||||
string_match_candidates(new_candidates.iter(), task_type);
|
||||
let _ = picker.delegate.candidates.insert(new_candidates);
|
||||
match_candidates
|
||||
}
|
||||
})
|
||||
.ok()
|
||||
else {
|
||||
return;
|
||||
};
|
||||
let mut new_candidates = used;
|
||||
new_candidates.extend(lsp_tasks.into_iter().flat_map(
|
||||
|(kind, tasks_with_locations)| {
|
||||
tasks_with_locations
|
||||
.into_iter()
|
||||
.sorted_by_key(|(location, task)| {
|
||||
(location.is_none(), task.resolved_label.clone())
|
||||
})
|
||||
.map(move |(_, task)| (kind.clone(), task))
|
||||
},
|
||||
));
|
||||
new_candidates.extend(current);
|
||||
let match_candidates =
|
||||
string_match_candidates(&new_candidates, task_type);
|
||||
let _ = picker.delegate.candidates.insert(new_candidates);
|
||||
match_candidates
|
||||
})
|
||||
.ok()
|
||||
.unwrap_or_default()
|
||||
})
|
||||
} else {
|
||||
Task::ready(Vec::new())
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
cx.spawn_in(window, async move |picker, cx| {
|
||||
let candidates = candidates.await;
|
||||
let matches = fuzzy::match_strings(
|
||||
&candidates,
|
||||
&query,
|
||||
|
@ -426,6 +451,7 @@ impl PickerDelegate for TasksModalDelegate {
|
|||
color: Color::Default,
|
||||
};
|
||||
let icon = match source_kind {
|
||||
TaskSourceKind::Lsp(..) => Some(Icon::new(IconName::Bolt)),
|
||||
TaskSourceKind::UserInput => Some(Icon::new(IconName::Terminal)),
|
||||
TaskSourceKind::AbsPath { .. } => Some(Icon::new(IconName::Settings)),
|
||||
TaskSourceKind::Worktree { .. } => Some(Icon::new(IconName::FileTree)),
|
||||
|
@ -697,10 +723,11 @@ impl PickerDelegate for TasksModalDelegate {
|
|||
}
|
||||
|
||||
fn string_match_candidates<'a>(
|
||||
candidates: impl Iterator<Item = &'a (TaskSourceKind, ResolvedTask)> + 'a,
|
||||
candidates: impl IntoIterator<Item = &'a (TaskSourceKind, ResolvedTask)> + 'a,
|
||||
task_modal_type: TaskModal,
|
||||
) -> Vec<StringMatchCandidate> {
|
||||
candidates
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.filter(|(_, (_, candidate))| match candidate.task_type() {
|
||||
TaskType::Script => task_modal_type == TaskModal::ScriptModal,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::collections::HashMap;
|
||||
use std::path::Path;
|
||||
|
||||
use collections::HashMap;
|
||||
use debugger_ui::Start;
|
||||
use editor::Editor;
|
||||
use feature_flags::{Debugger, FeatureFlagViewExt};
|
||||
|
@ -313,6 +313,17 @@ fn task_contexts(workspace: &Workspace, window: &mut Window, cx: &mut App) -> Ta
|
|||
})
|
||||
});
|
||||
|
||||
let lsp_task_sources = active_editor
|
||||
.as_ref()
|
||||
.map(|active_editor| active_editor.update(cx, |editor, cx| editor.lsp_task_sources(cx)))
|
||||
.unwrap_or_default();
|
||||
|
||||
let latest_selection = active_editor.as_ref().map(|active_editor| {
|
||||
active_editor.update(cx, |editor, _| {
|
||||
editor.selections.newest_anchor().head().text_anchor
|
||||
})
|
||||
});
|
||||
|
||||
let mut worktree_abs_paths = workspace
|
||||
.worktrees(cx)
|
||||
.filter(|worktree| is_visible_directory(worktree, cx))
|
||||
|
@ -325,6 +336,9 @@ fn task_contexts(workspace: &Workspace, window: &mut Window, cx: &mut App) -> Ta
|
|||
cx.background_spawn(async move {
|
||||
let mut task_contexts = TaskContexts::default();
|
||||
|
||||
task_contexts.lsp_task_sources = lsp_task_sources;
|
||||
task_contexts.latest_selection = latest_selection;
|
||||
|
||||
if let Some(editor_context_task) = editor_context_task {
|
||||
if let Some(editor_context) = editor_context_task.await {
|
||||
task_contexts.active_item_context =
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue