editor: Fix up task indicators in multibuffers (#11434)

We were retrieving task context incorrectly with a display point row as
the location argument, and not the actual row in the buffer.



Release Notes:

- N/A
This commit is contained in:
Piotr Osiewicz 2024-05-06 15:39:49 +02:00 committed by GitHub
parent 593f0e0c3e
commit 27a9498cb0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -399,7 +399,7 @@ impl Default for ScrollbarMarkerState {
} }
} }
#[derive(Clone)] #[derive(Clone, Debug)]
struct RunnableTasks { struct RunnableTasks {
templates: SmallVec<[(TaskSourceKind, TaskTemplate); 1]>, templates: SmallVec<[(TaskSourceKind, TaskTemplate); 1]>,
// We need the column at which the task context evaluation should take place. // We need the column at which the task context evaluation should take place.
@ -1346,7 +1346,6 @@ impl CodeActionsMenu {
) -> (ContextMenuOrigin, AnyElement) { ) -> (ContextMenuOrigin, AnyElement) {
let actions = self.actions.clone(); let actions = self.actions.clone();
let selected_item = self.selected_item; let selected_item = self.selected_item;
let element = uniform_list( let element = uniform_list(
cx.view().clone(), cx.view().clone(),
"code_actions_menu", "code_actions_menu",
@ -3850,34 +3849,30 @@ impl Editor {
let spawned_test_task = this.update(&mut cx, |this, cx| { let spawned_test_task = this.update(&mut cx, |this, cx| {
if this.focus_handle.is_focused(cx) { if this.focus_handle.is_focused(cx) {
let row = action let snapshot = this.snapshot(cx);
.deployed_from_indicator let display_row = action.deployed_from_indicator.unwrap_or_else(|| {
.unwrap_or_else(|| this.selections.newest::<Point>(cx).head().row); this.selections
let tasks = this.tasks.get(&row).map(|t| Arc::new(t.to_owned())); .newest::<Point>(cx)
let (buffer, code_actions) = this .head()
.available_code_actions .to_display_point(&snapshot.display_snapshot)
.clone() .row()
.map(|(buffer, code_actions)| { });
let snapshot = buffer.read(cx).snapshot();
let code_actions: Arc<[CodeAction]> = code_actions
.into_iter()
.filter(|action| {
text::ToPoint::to_point(&action.range.start, &snapshot).row
== row
})
.cloned()
.collect();
(buffer, code_actions)
})
.unzip();
let buffer_point =
DisplayPoint::new(display_row, 0).to_point(&snapshot.display_snapshot);
let buffer_row = snapshot
.buffer_snapshot
.buffer_line_for_row(buffer_point.row)
.map(|(_, Range { start, .. })| start);
let tasks = this.tasks.get(&display_row).map(|t| Arc::new(t.to_owned()));
let (buffer, code_actions) = this.available_code_actions.clone().unzip();
if tasks.is_none() && code_actions.is_none() { if tasks.is_none() && code_actions.is_none() {
return None; return None;
} }
let buffer = buffer.or_else(|| { let buffer = buffer.or_else(|| {
let snapshot = this.snapshot(cx); let snapshot = this.snapshot(cx);
let (buffer_snapshot, _) = let (buffer_snapshot, _) =
snapshot.buffer_snapshot.buffer_line_for_row(row)?; snapshot.buffer_snapshot.buffer_line_for_row(display_row)?;
let buffer_id = buffer_snapshot.remote_id(); let buffer_id = buffer_snapshot.remote_id();
this.buffer().read(cx).buffer(buffer_id) this.buffer().read(cx).buffer(buffer_id)
}); });
@ -3888,7 +3883,8 @@ impl Editor {
this.discard_inline_completion(cx); this.discard_inline_completion(cx);
let task_context = tasks.as_ref().zip(this.workspace.clone()).and_then( let task_context = tasks.as_ref().zip(this.workspace.clone()).and_then(
|(tasks, (workspace, _))| { |(tasks, (workspace, _))| {
let position = Point::new(row, tasks.column); if let Some(buffer_point) = buffer_row {
let position = Point::new(buffer_point.row, tasks.column);
let range_start = buffer.read(cx).anchor_at(position, Bias::Right); let range_start = buffer.read(cx).anchor_at(position, Bias::Right);
let location = Location { let location = Location {
buffer: buffer.clone(), buffer: buffer.clone(),
@ -3900,6 +3896,9 @@ impl Editor {
}) })
.ok() .ok()
.flatten() .flatten()
} else {
None
}
}, },
); );
let tasks = tasks let tasks = tasks
@ -3915,7 +3914,7 @@ impl Editor {
.map(|task| (kind.clone(), task)) .map(|task| (kind.clone(), task))
}) })
.collect(), .collect(),
position: Point::new(row, tasks.column), position: Point::new(display_row, tasks.column),
}) })
}); });
let spawn_straight_away = tasks let spawn_straight_away = tasks
@ -3924,7 +3923,6 @@ impl Editor {
&& code_actions && code_actions
.as_ref() .as_ref()
.map_or(true, |actions| actions.is_empty()); .map_or(true, |actions| actions.is_empty());
*this.context_menu.write() = Some(ContextMenu::CodeActions(CodeActionsMenu { *this.context_menu.write() = Some(ContextMenu::CodeActions(CodeActionsMenu {
buffer, buffer,
actions: CodeActionContents { actions: CodeActionContents {
@ -3945,7 +3943,7 @@ impl Editor {
} }
cx.notify(); cx.notify();
} }
None Some(Task::ready(Ok(())))
})?; })?;
if let Some(task) = spawned_test_task { if let Some(task) = spawned_test_task {
task.await?; task.await?;