Skip to content

Commit

Permalink
Add message to picker
Browse files Browse the repository at this point in the history
  • Loading branch information
ayoub-benali committed Jan 10, 2023
1 parent f7ea836 commit 9e05bd3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 5 additions & 3 deletions helix-term/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,7 @@ impl Application {
MethodCall::ShowMessageRequest(params) => {
if let Some(actions) = params.actions {
let call_id = id.clone();
let menu = Picker::new(actions, (), move |ctx, item, _event| {
let mut picker = Picker::new(actions, (), move |ctx, item, _event| {
let language_server =
match ctx.editor.language_servers.get_by_id(server_id) {
Some(language_server) => language_server,
Expand All @@ -1040,8 +1040,10 @@ impl Application {
language_server.reply(call_id.clone(), Ok(json!(item))),
);
});
let popup = Popup::new("some_id", menu);
self.compositor.replace_or_push("some_id", popup);
picker.message(params.message);
let popup_id = "show_message_request";
let popup = Popup::new(popup_id, picker);
self.compositor.replace_or_push(popup_id, popup);
// do not send a reply just yet
None
} else {
Expand Down
8 changes: 8 additions & 0 deletions helix-term/src/ui/picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ pub struct Picker<T: Item> {
show_preview: bool,

callback_fn: Box<dyn Fn(&mut Context, &T, Action)>,
message: String,
}

impl<T: Item> Picker<T> {
Expand Down Expand Up @@ -417,6 +418,7 @@ impl<T: Item> Picker<T> {
show_preview: true,
callback_fn: Box::new(callback_fn),
completion_height: 0,
message: String::new(),
};

// scoring on empty input:
Expand Down Expand Up @@ -561,6 +563,10 @@ impl<T: Item> Picker<T> {
self.show_preview = !self.show_preview;
}

pub fn message(&mut self, message: String) {
self.message = message
}

fn prompt_handle_event(&mut self, event: &Event, cx: &mut Context) -> EventResult {
if let EventResult::Consumed(_) = self.prompt.handle_event(event, cx) {
// TODO: recalculate only if pattern changed
Expand Down Expand Up @@ -666,6 +672,8 @@ impl<T: Item + 'static> Component for Picker<T> {

block.render(area, surface);

// TODO: render self.message if present

// -- Render the input bar:

let area = inner.clip_left(1).with_height(1);
Expand Down

0 comments on commit 9e05bd3

Please sign in to comment.