input: Fix completions API to assign Rope.

This commit is contained in:
Jason Lee 2025-09-17 14:37:21 +08:00
parent 478db2785a
commit e01b139995
3 changed files with 9 additions and 6 deletions

View file

@ -8,8 +8,8 @@ use gpui_component::{
h_flex,
highlighter::{Diagnostic, DiagnosticSeverity, Language, LanguageConfig, LanguageRegistry},
input::{
self, CodeActionProvider, CompletionProvider, InputEvent, InputState, Position, RopeExt,
TabSize, TextInput,
self, CodeActionProvider, CompletionProvider, InputEvent, InputState, Position, Rope,
RopeExt, TabSize, TextInput,
},
v_flex, ActiveTheme, ContextModal, IconName, IndexPath, Selectable, Sizable,
};
@ -131,7 +131,7 @@ impl ExampleLspStore {
impl CompletionProvider for ExampleLspStore {
fn completions(
&self,
_state: Entity<InputState>,
rope: &Rope,
_offset: usize,
trigger: CompletionContext,
_: &mut Window,
@ -146,6 +146,8 @@ impl CompletionProvider for ExampleLspStore {
return Task::ready(Ok(vec![]));
}
let _ = rope.to_string(); // Just to use the rope parameter.
// Simulate to delay for fetching completions
let items = self.completions.clone();
cx.background_executor().spawn(async move {

View file

@ -5,6 +5,7 @@ use gpui::{App, Context, Entity, EntityInputHandler, SharedString, Task, Window}
use lsp_types::{
request::Completion, CodeAction, CompletionContext, CompletionItem, CompletionResponse,
};
use rope::Rope;
use crate::input::{
popovers::{CodeActionItem, CodeActionMenu, CompletionMenu, ContextMenu},
@ -16,7 +17,7 @@ pub trait CompletionProvider {
/// Fetches completions based on the given byte offset.
fn completions(
&self,
state: Entity<InputState>,
text: &Rope,
offset: usize,
trigger: CompletionContext,
window: &mut Window,
@ -174,8 +175,7 @@ impl InputState {
};
let provider_responses =
provider.completions(cx.entity(), start_offset, completion_context, window, cx);
provider.completions(&self.text, start_offset, completion_context, window, cx);
self._context_menu_task = cx.spawn_in(window, async move |editor, cx| {
let mut completions: Vec<CompletionItem> = vec![];
if let Some(provider_responses) = provider_responses.await.ok() {

View file

@ -21,6 +21,7 @@ pub use mask_pattern::MaskPattern;
pub use mode::TabSize;
pub use number_input::{NumberInput, NumberInputEvent, StepAction};
pub use otp_input::*;
pub use rope::Rope;
pub use rope_ext::*;
pub use state::*;
pub use text_input::*;