editor: Show code actions in mouse context menu (#28677)

Closes #27989

Asynchronous fetch of code actions on right-click, and shows them in
context menu.


https://github.com/user-attachments/assets/413eb0dd-cd1c-4628-a6f1-84eac813da32

Release Notes:

- Improved visibility of code actions by showing them in right-click
context menu.
This commit is contained in:
Smit Barmase 2025-04-14 17:44:00 +05:30 committed by GitHub
parent 98891e4c70
commit f2ce183286
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 398 additions and 173 deletions

View file

@ -774,7 +774,7 @@ pub struct AvailableCodeAction {
pub provider: Rc<dyn CodeActionProvider>,
}
#[derive(Clone)]
#[derive(Clone, Default)]
pub struct CodeActionContents {
pub tasks: Option<Rc<ResolvedTasks>>,
pub actions: Option<Rc<[AvailableCodeAction]>>,
@ -790,7 +790,7 @@ impl CodeActionContents {
}
}
fn is_empty(&self) -> bool {
pub fn is_empty(&self) -> bool {
match (&self.tasks, &self.actions) {
(Some(tasks), Some(actions)) => actions.is_empty() && tasks.templates.is_empty(),
(Some(tasks), None) => tasks.templates.is_empty(),
@ -799,7 +799,7 @@ impl CodeActionContents {
}
}
fn iter(&self) -> impl Iterator<Item = CodeActionsItem> + '_ {
pub fn iter(&self) -> impl Iterator<Item = CodeActionsItem> + '_ {
self.tasks
.iter()
.flat_map(|tasks| {
@ -867,14 +867,14 @@ pub enum CodeActionsItem {
}
impl CodeActionsItem {
fn as_task(&self) -> Option<&ResolvedTask> {
pub fn as_task(&self) -> Option<&ResolvedTask> {
let Self::Task(_, task) = self else {
return None;
};
Some(task)
}
fn as_code_action(&self) -> Option<&CodeAction> {
pub fn as_code_action(&self) -> Option<&CodeAction> {
let Self::CodeAction { action, .. } = self else {
return None;
};
@ -1014,6 +1014,7 @@ impl CodeActionsMenu {
if let Some(task) = editor.confirm_code_action(
&ConfirmCodeAction {
item_ix: Some(item_ix),
from_mouse_context_menu: false,
},
window,
cx,
@ -1039,6 +1040,7 @@ impl CodeActionsMenu {
if let Some(task) = editor.confirm_code_action(
&ConfirmCodeAction {
item_ix: Some(item_ix),
from_mouse_context_menu: false,
},
window,
cx,