@@ -24,7 +24,7 @@ pub struct Prompt {
2424 selection: Option<usize>,
2525 history_register: Option<char>,
2626 history_pos: Option<usize>,
27− completion_fn: Box<dyn FnMut(&str) -> Vec<Completion>>,
27+ completion_fn: Box<dyn FnMut(&Context, &str) -> Vec<Completion>>,
2828 callback_fn: Box<dyn FnMut(&mut Context, &str, PromptEvent)>,
2929 pub doc_fn: Box<dyn Fn(&str) -> Option<&'static str>>,
3030}
@@ -59,14 +59,14 @@ impl Prompt {
5959 pub fn new(
6060 prompt: Cow<'static, str>,
6161 history_register: Option<char>,
62− mut completion_fn: impl FnMut(&str) -> Vec<Completion> + 'static,
62+ completion_fn: impl FnMut(&Context, &str) -> Vec<Completion> + 'static,
6363 callback_fn: impl FnMut(&mut Context, &str, PromptEvent) + 'static,
6464 ) -> Self {
6565 Self {
6666 prompt,
6767 line: String::new(),
6868 cursor: 0,
69− completion: completion_fn(""),
69+ completion: Vec::new(),
7070 selection: None,
7171 history_register,
7272 history_pos: None,
@@ -177,13 +177,13 @@ impl Prompt {
177177 }
178178 }
179179
180− pub fn insert_char(&mut self, c: char) {
180+ pub fn insert_char(&mut self, c: char, cx: &Context) {
181181 self.line.insert(self.cursor, c);
182182 let mut cursor = GraphemeCursor::new(self.cursor, self.line.len(), false);
183183 if let Ok(Some(pos)) = cursor.next_boundary(&self.line, 0) {
184184 self.cursor = pos;
185185 }
186− self.completion = (self.completion_fn)(&self.line);
186+ self.completion = (self.completion_fn)(cx, &self.line);
187187 self.exit_selection();
188188 }
189189
@@ -205,61 +205,61 @@ impl Prompt {
205205 self.cursor = self.line.len();
206206 }
207207
208− pub fn delete_char_backwards(&mut self) {
208+ pub fn delete_char_backwards(&mut self, cx: &Context) {
209209 let pos = self.eval_movement(Movement::BackwardChar(1));
210210 self.line.replace_range(pos..self.cursor, "");
211211 self.cursor = pos;
212212
213213 self.exit_selection();
214− self.completion = (self.completion_fn)(&self.line);
214+ self.completion = (self.completion_fn)(cx, &self.line);
215215 }
216216
217− pub fn delete_char_forwards(&mut self) {
217+ pub fn delete_char_forwards(&mut self, cx: &Context) {
218218 let pos = self.eval_movement(Movement::ForwardChar(1));
219219 self.line.replace_range(self.cursor..pos, "");
220220
221221 self.exit_selection();
222− self.completion = (self.completion_fn)(&self.line);
222+ self.completion = (self.completion_fn)(cx, &self.line);
223223 }
224224
225− pub fn delete_word_backwards(&mut self) {
225+ pub fn delete_word_backwards(&mut self, cx: &Context) {
226226 let pos = self.eval_movement(Movement::BackwardWord(1));
227227 self.line.replace_range(pos..self.cursor, "");
228228 self.cursor = pos;
229229
230230 self.exit_selection();
231− self.completion = (self.completion_fn)(&self.line);
231+ self.completion = (self.completion_fn)(cx, &self.line);
232232 }
233233
234− pub fn delete_word_forwards(&mut self) {
234+ pub fn delete_word_forwards(&mut self, cx: &Context) {
235235 let pos = self.eval_movement(Movement::ForwardWord(1));
236236 self.line.replace_range(self.cursor..pos, "");
237237
238238 self.exit_selection();
239− self.completion = (self.completion_fn)(&self.line);
239+ self.completion = (self.completion_fn)(cx, &self.line);
240240 }
241241
242− pub fn kill_to_start_of_line(&mut self) {
242+ pub fn kill_to_start_of_line(&mut self, cx: &Context) {
243243 let pos = self.eval_movement(Movement::StartOfLine);
244244 self.line.replace_range(pos..self.cursor, "");
245245 self.cursor = pos;
246246
247247 self.exit_selection();
248− self.completion = (self.completion_fn)(&self.line);
248+ self.completion = (self.completion_fn)(cx, &self.line);
249249 }
250250
251− pub fn kill_to_end_of_line(&mut self) {
251+ pub fn kill_to_end_of_line(&mut self, cx: &Context) {
252252 let pos = self.eval_movement(Movement::EndOfLine);
253253 self.line.replace_range(self.cursor..pos, "");
254254
255255 self.exit_selection();
256− self.completion = (self.completion_fn)(&self.line);
256+ self.completion = (self.completion_fn)(cx, &self.line);
257257 }
258258
259− pub fn clear(&mut self) {
259+ pub fn clear(&mut self, cx: &Context) {
260260 self.line.clear();
261261 self.cursor = 0;
262− self.completion = (self.completion_fn)(&self.line);
262+ self.completion = (self.completion_fn)(cx, &self.line);
263263 self.exit_selection();
264264 }
265265
@@ -442,16 +442,16 @@ impl Component for Prompt {
442442 ctrl!('f') | key!(Right) => self.move_cursor(Movement::ForwardChar(1)),
443443 ctrl!('e') | key!(End) => self.move_end(),
444444 ctrl!('a') | key!(Home) => self.move_start(),
445− ctrl!('w') => self.delete_word_backwards(),
446− alt!('d') => self.delete_word_forwards(),
447− ctrl!('k') => self.kill_to_end_of_line(),
448− ctrl!('u') => self.kill_to_start_of_line(),
445+ ctrl!('w') => self.delete_word_backwards(cx),
446+ alt!('d') => self.delete_word_forwards(cx),
447+ ctrl!('k') => self.kill_to_end_of_line(cx),
448+ ctrl!('u') => self.kill_to_start_of_line(cx),
449449 ctrl!('h') | key!(Backspace) => {
450− self.delete_char_backwards();
450+ self.delete_char_backwards(cx);
451451 (self.callback_fn)(cx, &self.line, PromptEvent::Update);
452452 }
453453 ctrl!('d') | key!(Delete) => {
454− self.delete_char_forwards();
454+ self.delete_char_forwards(cx);
455455 (self.callback_fn)(cx, &self.line, PromptEvent::Update);
456456 }
457457 ctrl!('s') => {
@@ -474,7 +474,7 @@ impl Component for Prompt {
474474 }
475475 key!(Enter) => {
476476 if self.selection.is_some() && self.line.ends_with(std::path::MAIN_SEPARATOR) {
477− self.completion = (self.completion_fn)(&self.line);
477+ self.completion = (self.completion_fn)(cx, &self.line);
478478 self.exit_selection();
479479 } else {
480480 (self.callback_fn)(cx, &self.line, PromptEvent::Validate);
@@ -515,7 +515,7 @@ impl Component for Prompt {
515515 code: KeyCode::Char(c),
516516 modifiers,
517517 } if !modifiers.contains(KeyModifiers::CONTROL) => {
518− self.insert_char(c);
518+ self.insert_char(c, cx);
519519 (self.callback_fn)(cx, &self.line, PromptEvent::Update);
520520 }
521521 _ => (),
@@ -525,6 +525,7 @@ impl Component for Prompt {
525525 }
526526
527527 fn render(&mut self, area: Rect, surface: &mut Surface, cx: &mut Context) {
528+ self.completion = (self.completion_fn)(cx, &self.line);
528529 self.render_prompt(area, surface, cx)
529530 }
530531