@@ -69,14 +69,17 @@ impl menu::Item for CompletionItem {
6969/// Wraps a Menu.
7070pub struct Completion {
7171 popup: Popup<Menu<CompletionItem>>,
72+ start_offset: usize,
7273 trigger_offset: usize,
7374 // TODO: maintain a completioncontext with trigger kind & trigger char
7475}
7576
7677impl Completion {
7778 pub fn new(
79+ editor: &Editor,
7880 items: Vec<CompletionItem>,
7981 offset_encoding: helix_lsp::OffsetEncoding,
82+ start_offset: usize,
8083 trigger_offset: usize,
8184 ) -> Self {
8285 // let items: Vec<CompletionItem> = Vec::new();
@@ -175,16 +178,22 @@ impl Completion {
175178 };
176179 });
177180 let popup = Popup::new(menu);
178− Self {
181+ let mut completion = Self {
179182 popup,
183+ start_offset,
180184 trigger_offset,
181− }
185+ };
186+
187+ // need to recompute immediately in case start_offset != trigger_offset
188+ completion.recompute_filter(editor);
189+
190+ completion
182191 }
183192
184− pub fn update(&mut self, cx: &mut commands::Context) {
193+ pub fn recompute_filter(&mut self, editor: &Editor) {
185194 // recompute menu based on matches
186195 let menu = self.popup.contents_mut();
187− let (view, doc) = current!(cx.editor);
196+ let (view, doc) = current_ref!(editor);
188197
189198 // cx.hooks()
190199 // cx.add_hook(enum type, ||)
@@ -200,14 +209,18 @@ impl Completion {
200209 .selection(view.id)
201210 .primary()
202211 .cursor(doc.text().slice(..));
203− if self.trigger_offset <= cursor {
204− let fragment = doc.text().slice(self.trigger_offset..cursor);
212+ if self.start_offset <= cursor {
213+ let fragment = doc.text().slice(self.start_offset..cursor);
205214 let text = Cow::from(fragment);
206215 // TODO: logic is same as ui/picker
207216 menu.score(&text);
208217 }
209218 }
210219
220+ pub fn update(&mut self, cx: &mut commands::Context) {
221+ self.recompute_filter(cx.editor)
222+ }
223+
211224 pub fn is_empty(&self) -> bool {
212225 self.popup.contents().is_empty()
213226 }