Add Code Actions to the Toolbar (#31236)

Closes issue #31120.


https://github.com/user-attachments/assets/a4b3c86d-7358-49ac-b8d9-e9af50daf671

Release Notes:

- Added a code actions icon to the toolbar. This icon can be disabled by
setting `toolbar.code_actions` to `false`.
This commit is contained in:
smit 2025-05-23 16:55:29 +05:30 committed by GitHub
parent fbc922ad46
commit 1cad1cbbfc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 167 additions and 50 deletions

View file

@ -26,6 +26,7 @@ use task::ResolvedTask;
use ui::{Color, IntoElement, ListItem, Pixels, Popover, Styled, prelude::*};
use util::ResultExt;
use crate::CodeActionSource;
use crate::editor_settings::SnippetSortOrder;
use crate::hover_popover::{hover_markdown_style, open_markdown_url};
use crate::{
@ -168,6 +169,7 @@ impl CodeContextMenu {
pub enum ContextMenuOrigin {
Cursor,
GutterIndicator(DisplayRow),
QuickActionBar,
}
#[derive(Clone, Debug)]
@ -840,7 +842,7 @@ pub struct AvailableCodeAction {
}
#[derive(Clone)]
pub(crate) struct CodeActionContents {
pub struct CodeActionContents {
tasks: Option<Rc<ResolvedTasks>>,
actions: Option<Rc<[AvailableCodeAction]>>,
debug_scenarios: Vec<DebugScenario>,
@ -968,12 +970,12 @@ impl CodeActionsItem {
}
}
pub(crate) struct CodeActionsMenu {
pub struct CodeActionsMenu {
pub actions: CodeActionContents,
pub buffer: Entity<Buffer>,
pub selected_item: usize,
pub scroll_handle: UniformListScrollHandle,
pub deployed_from_indicator: Option<DisplayRow>,
pub deployed_from: Option<CodeActionSource>,
}
impl CodeActionsMenu {
@ -1042,10 +1044,10 @@ impl CodeActionsMenu {
}
fn origin(&self) -> ContextMenuOrigin {
if let Some(row) = self.deployed_from_indicator {
ContextMenuOrigin::GutterIndicator(row)
} else {
ContextMenuOrigin::Cursor
match &self.deployed_from {
Some(CodeActionSource::Indicator(row)) => ContextMenuOrigin::GutterIndicator(*row),
Some(CodeActionSource::QuickActionBar) => ContextMenuOrigin::QuickActionBar,
None => ContextMenuOrigin::Cursor,
}
}