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

View file

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