diff --git a/crates/story/examples/code-editor.rs b/crates/story/examples/code-editor.rs index 0348c613..f3c43cab 100644 --- a/crates/story/examples/code-editor.rs +++ b/crates/story/examples/code-editor.rs @@ -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, + 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 { diff --git a/crates/ui/src/input/lsp.rs b/crates/ui/src/input/lsp.rs index c3910eae..44dfaa67 100644 --- a/crates/ui/src/input/lsp.rs +++ b/crates/ui/src/input/lsp.rs @@ -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, + 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 = vec![]; if let Some(provider_responses) = provider_responses.await.ok() { diff --git a/crates/ui/src/input/mod.rs b/crates/ui/src/input/mod.rs index 06591618..cf7699ae 100644 --- a/crates/ui/src/input/mod.rs +++ b/crates/ui/src/input/mod.rs @@ -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::*;