Show a very basic code actions menu

This commit is contained in:
Antonio Scandurra 2023-11-10 12:26:35 +01:00
parent 23fd1e19dc
commit a30b47aa5f
2 changed files with 31 additions and 8 deletions

View file

@ -39,11 +39,11 @@ use futures::FutureExt;
use fuzzy::{StringMatch, StringMatchCandidate}; use fuzzy::{StringMatch, StringMatchCandidate};
use git::diff_hunk_to_display; use git::diff_hunk_to_display;
use gpui::{ use gpui::{
action, actions, point, px, relative, rems, size, AnyElement, AppContext, BackgroundExecutor, action, actions, div, point, px, relative, rems, size, uniform_list, AnyElement, AppContext,
Bounds, ClipboardItem, Component, Context, DispatchContext, EventEmitter, FocusHandle, BackgroundExecutor, Bounds, ClipboardItem, Component, Context, DispatchContext, EventEmitter,
FontFeatures, FontStyle, FontWeight, HighlightStyle, Hsla, InputHandler, Model, Pixels, Render, FocusHandle, FontFeatures, FontStyle, FontWeight, HighlightStyle, Hsla, InputHandler, Model,
Subscription, Task, TextStyle, UniformListScrollHandle, View, ViewContext, VisualContext, ParentElement, Pixels, Render, Styled, Subscription, Task, TextStyle, UniformListScrollHandle,
WeakView, WindowContext, View, ViewContext, VisualContext, WeakView, WindowContext,
}; };
use highlight_matching_bracket::refresh_matching_bracket_highlights; use highlight_matching_bracket::refresh_matching_bracket_highlights;
use hover_popover::{hide_hover, HoverState}; use hover_popover::{hide_hover, HoverState};
@ -1559,7 +1559,30 @@ impl CodeActionsMenu {
style: &EditorStyle, style: &EditorStyle,
cx: &mut ViewContext<Editor>, cx: &mut ViewContext<Editor>,
) -> (DisplayPoint, AnyElement<Editor>) { ) -> (DisplayPoint, AnyElement<Editor>) {
todo!("old version below") let actions = self.actions.clone();
let selected_item = self.selected_item;
let element = uniform_list(
"code_actions_menu",
self.actions.len(),
move |editor, range, cx| {
actions[range.clone()]
.iter()
.enumerate()
.map(|(ix, action)| {
let item_ix = range.start + ix;
div().child(action.lsp_action.title.clone())
})
.collect()
},
)
.bg(gpui::red())
.render();
if self.deployed_from_indicator {
*cursor_position.column_mut() = 0;
}
(cursor_position, element)
} }
// enum ActionTag {} // enum ActionTag {}
@ -4383,7 +4406,7 @@ impl Editor {
) -> Option<AnyElement<Self>> { ) -> Option<AnyElement<Self>> {
if self.available_code_actions.is_some() { if self.available_code_actions.is_some() {
Some( Some(
IconButton::new("code_actions", ui2::Icon::Bolt) IconButton::new("code_actions_indicator", ui2::Icon::Bolt)
.on_click(|editor: &mut Editor, cx| { .on_click(|editor: &mut Editor, cx| {
editor.toggle_code_actions( editor.toggle_code_actions(
&ToggleCodeActions { &ToggleCodeActions {

View file

@ -804,7 +804,7 @@ impl EditorElement {
cx.with_z_index(1, |cx| { cx.with_z_index(1, |cx| {
let line_height = self.style.text.line_height_in_pixels(cx.rem_size()); let line_height = self.style.text.line_height_in_pixels(cx.rem_size());
let available_space = size( let available_space = size(
AvailableSpace::Definite(cx.viewport_size().width * 0.7), AvailableSpace::MinContent,
AvailableSpace::Definite( AvailableSpace::Definite(
(12. * line_height).min((bounds.size.height - line_height) / 2.), (12. * line_height).min((bounds.size.height - line_height) / 2.),
), ),