Fix manual copilot with show_inline_completions: false (#16621)

For @mre and friends!

Release Notes:

- Fixed manually trigging completions when `show_inline_completions:
false`
This commit is contained in:
Conrad Irwin 2024-08-21 20:27:19 -06:00 committed by GitHub
parent 136f75ee9a
commit eb9eae09b1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 24 additions and 21 deletions

View File

@ -1060,7 +1060,7 @@ mod tests {
editor.change_selections(None, cx, |selections| { editor.change_selections(None, cx, |selections| {
selections.select_ranges([Point::new(0, 0)..Point::new(0, 0)]) selections.select_ranges([Point::new(0, 0)..Point::new(0, 0)])
}); });
editor.next_inline_completion(&Default::default(), cx); editor.refresh_inline_completion(true, false, cx);
}); });
executor.advance_clock(COPILOT_DEBOUNCE_TIMEOUT); executor.advance_clock(COPILOT_DEBOUNCE_TIMEOUT);
@ -1070,7 +1070,7 @@ mod tests {
editor.change_selections(None, cx, |s| { editor.change_selections(None, cx, |s| {
s.select_ranges([Point::new(2, 0)..Point::new(2, 0)]) s.select_ranges([Point::new(2, 0)..Point::new(2, 0)])
}); });
editor.next_inline_completion(&Default::default(), cx); editor.refresh_inline_completion(true, false, cx);
}); });
executor.advance_clock(COPILOT_DEBOUNCE_TIMEOUT); executor.advance_clock(COPILOT_DEBOUNCE_TIMEOUT);

View File

@ -2201,7 +2201,7 @@ impl Editor {
}), }),
provider: Arc::new(provider), provider: Arc::new(provider),
}); });
self.refresh_inline_completion(false, cx); self.refresh_inline_completion(false, false, cx);
} }
pub fn placeholder_text(&self, _cx: &WindowContext) -> Option<&str> { pub fn placeholder_text(&self, _cx: &WindowContext) -> Option<&str> {
@ -3319,7 +3319,7 @@ impl Editor {
let trigger_in_words = !had_active_inline_completion; let trigger_in_words = !had_active_inline_completion;
this.trigger_completion_on_input(&text, trigger_in_words, cx); this.trigger_completion_on_input(&text, trigger_in_words, cx);
linked_editing_ranges::refresh_linked_ranges(this, cx); linked_editing_ranges::refresh_linked_ranges(this, cx);
this.refresh_inline_completion(true, cx); this.refresh_inline_completion(true, false, cx);
}); });
} }
@ -3505,7 +3505,7 @@ impl Editor {
.collect(); .collect();
this.change_selections(Some(Autoscroll::fit()), cx, |s| s.select(new_selections)); this.change_selections(Some(Autoscroll::fit()), cx, |s| s.select(new_selections));
this.refresh_inline_completion(true, cx); this.refresh_inline_completion(true, false, cx);
}); });
} }
@ -4393,7 +4393,7 @@ impl Editor {
}) })
} }
this.refresh_inline_completion(true, cx); this.refresh_inline_completion(true, false, cx);
}); });
let show_new_completions_on_confirm = completion let show_new_completions_on_confirm = completion
@ -4893,17 +4893,19 @@ impl Editor {
None None
} }
fn refresh_inline_completion( pub fn refresh_inline_completion(
&mut self, &mut self,
debounce: bool, debounce: bool,
user_requested: bool,
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) -> Option<()> { ) -> Option<()> {
let provider = self.inline_completion_provider()?; let provider = self.inline_completion_provider()?;
let cursor = self.selections.newest_anchor().head(); let cursor = self.selections.newest_anchor().head();
let (buffer, cursor_buffer_position) = let (buffer, cursor_buffer_position) =
self.buffer.read(cx).text_anchor_for_position(cursor, cx)?; self.buffer.read(cx).text_anchor_for_position(cursor, cx)?;
if !self.show_inline_completions if !user_requested
|| !provider.is_enabled(&buffer, cursor_buffer_position, cx) && (!self.show_inline_completions
|| !provider.is_enabled(&buffer, cursor_buffer_position, cx))
{ {
self.discard_inline_completion(false, cx); self.discard_inline_completion(false, cx);
return None; return None;
@ -4937,7 +4939,7 @@ impl Editor {
pub fn show_inline_completion(&mut self, _: &ShowInlineCompletion, cx: &mut ViewContext<Self>) { pub fn show_inline_completion(&mut self, _: &ShowInlineCompletion, cx: &mut ViewContext<Self>) {
if !self.has_active_inline_completion(cx) { if !self.has_active_inline_completion(cx) {
self.refresh_inline_completion(false, cx); self.refresh_inline_completion(false, true, cx);
return; return;
} }
@ -4966,7 +4968,7 @@ impl Editor {
if self.has_active_inline_completion(cx) { if self.has_active_inline_completion(cx) {
self.cycle_inline_completion(Direction::Next, cx); self.cycle_inline_completion(Direction::Next, cx);
} else { } else {
let is_copilot_disabled = self.refresh_inline_completion(false, cx).is_none(); let is_copilot_disabled = self.refresh_inline_completion(false, true, cx).is_none();
if is_copilot_disabled { if is_copilot_disabled {
cx.propagate(); cx.propagate();
} }
@ -4981,7 +4983,7 @@ impl Editor {
if self.has_active_inline_completion(cx) { if self.has_active_inline_completion(cx) {
self.cycle_inline_completion(Direction::Prev, cx); self.cycle_inline_completion(Direction::Prev, cx);
} else { } else {
let is_copilot_disabled = self.refresh_inline_completion(false, cx).is_none(); let is_copilot_disabled = self.refresh_inline_completion(false, true, cx).is_none();
if is_copilot_disabled { if is_copilot_disabled {
cx.propagate(); cx.propagate();
} }
@ -5009,7 +5011,7 @@ impl Editor {
self.change_selections(None, cx, |s| s.select_ranges([range])) self.change_selections(None, cx, |s| s.select_ranges([range]))
} }
self.insert_with_autoindent_mode(&completion.text.to_string(), None, cx); self.insert_with_autoindent_mode(&completion.text.to_string(), None, cx);
self.refresh_inline_completion(true, cx); self.refresh_inline_completion(true, true, cx);
cx.notify(); cx.notify();
} }
@ -5045,7 +5047,7 @@ impl Editor {
} }
self.insert_with_autoindent_mode(&partial_completion, None, cx); self.insert_with_autoindent_mode(&partial_completion, None, cx);
self.refresh_inline_completion(true, cx); self.refresh_inline_completion(true, true, cx);
cx.notify(); cx.notify();
} }
} }
@ -5511,7 +5513,7 @@ impl Editor {
this.edit(edits, None, cx); this.edit(edits, None, cx);
}) })
} }
this.refresh_inline_completion(true, cx); this.refresh_inline_completion(true, false, cx);
linked_editing_ranges::refresh_linked_ranges(this, cx); linked_editing_ranges::refresh_linked_ranges(this, cx);
}); });
} }
@ -5530,7 +5532,7 @@ impl Editor {
}) })
}); });
this.insert("", cx); this.insert("", cx);
this.refresh_inline_completion(true, cx); this.refresh_inline_completion(true, false, cx);
}); });
} }
@ -5617,7 +5619,7 @@ impl Editor {
self.transact(cx, |this, cx| { self.transact(cx, |this, cx| {
this.buffer.update(cx, |b, cx| b.edit(edits, None, cx)); this.buffer.update(cx, |b, cx| b.edit(edits, None, cx));
this.change_selections(Some(Autoscroll::fit()), cx, |s| s.select(selections)); this.change_selections(Some(Autoscroll::fit()), cx, |s| s.select(selections));
this.refresh_inline_completion(true, cx); this.refresh_inline_completion(true, false, cx);
}); });
} }
@ -6785,7 +6787,7 @@ impl Editor {
} }
self.request_autoscroll(Autoscroll::fit(), cx); self.request_autoscroll(Autoscroll::fit(), cx);
self.unmark_text(cx); self.unmark_text(cx);
self.refresh_inline_completion(true, cx); self.refresh_inline_completion(true, false, cx);
cx.emit(EditorEvent::Edited { transaction_id }); cx.emit(EditorEvent::Edited { transaction_id });
cx.emit(EditorEvent::TransactionUndone { transaction_id }); cx.emit(EditorEvent::TransactionUndone { transaction_id });
} }
@ -6806,7 +6808,7 @@ impl Editor {
} }
self.request_autoscroll(Autoscroll::fit(), cx); self.request_autoscroll(Autoscroll::fit(), cx);
self.unmark_text(cx); self.unmark_text(cx);
self.refresh_inline_completion(true, cx); self.refresh_inline_completion(true, false, cx);
cx.emit(EditorEvent::Edited { transaction_id }); cx.emit(EditorEvent::Edited { transaction_id });
} }
} }
@ -11420,7 +11422,7 @@ impl Editor {
fn settings_changed(&mut self, cx: &mut ViewContext<Self>) { fn settings_changed(&mut self, cx: &mut ViewContext<Self>) {
self.tasks_update_task = Some(self.refresh_runnables(cx)); self.tasks_update_task = Some(self.refresh_runnables(cx));
self.refresh_inline_completion(true, cx); self.refresh_inline_completion(true, false, cx);
self.refresh_inlay_hints( self.refresh_inlay_hints(
InlayHintRefreshReason::SettingsChange(inlay_hint_settings( InlayHintRefreshReason::SettingsChange(inlay_hint_settings(
self.selections.newest_anchor().head(), self.selections.newest_anchor().head(),

View File

@ -2300,6 +2300,7 @@ impl Project {
buffer.update(cx, |buffer, cx| { buffer.update(cx, |buffer, cx| {
let worktree_id = old_file.worktree_id(cx); let worktree_id = old_file.worktree_id(cx);
let ids = &self.language_server_ids; let ids = &self.language_server_ids;
if let Some(language) = buffer.language().cloned() { if let Some(language) = buffer.language().cloned() {
@ -2620,7 +2621,7 @@ impl Project {
let worktree_id = file.worktree_id(cx); let worktree_id = file.worktree_id(cx);
let abs_path = file.as_local()?.abs_path(cx); let abs_path = file.as_local()?.abs_path(cx);
let text_document = lsp::TextDocumentIdentifier { let text_document = lsp::TextDocumentIdentifier {
uri: lsp::Url::from_file_path(abs_path).unwrap(), uri: lsp::Url::from_file_path(abs_path).log_err()?,
}; };
for (_, _, server) in self.language_servers_for_worktree(worktree_id) { for (_, _, server) in self.language_servers_for_worktree(worktree_id) {