pub struct LspOverlayState {
pub hover_text: Option<String>,
pub hover_items: Vec<Item>,
pub hover_visible: bool,
pub hover_position: Option<Point>,
pub hover_interactive: bool,
pub all_completions: Vec<String>,
pub completion_filter: String,
pub completion_items: Vec<String>,
pub completion_visible: bool,
pub completion_selected: usize,
pub completion_suppressed: bool,
pub completion_position: Option<Point>,
}Expand description
State for the LSP overlay display (hover tooltips and completion menus).
This struct aggregates all display-related LSP state. Instantiate once in
your application and pass it to view_lsp_overlay for rendering.
§Example
use iced_code_editor::LspOverlayState;
let mut state = LspOverlayState::new();
assert!(!state.hover_visible);
assert!(!state.completion_visible);Fields§
§hover_text: Option<String>The hover text received from the LSP server.
hover_items: Vec<Item>Parsed markdown items derived from hover_text.
hover_visible: boolWhether the hover tooltip is currently visible.
hover_position: Option<Point>Screen position where the hover tooltip should be rendered.
hover_interactive: boolWhether the mouse cursor is currently over the hover tooltip.
all_completions: Vec<String>All completion items received from the LSP server.
completion_filter: StringCurrent filter string applied to completion items.
completion_items: Vec<String>Filtered completion items to display.
completion_visible: boolWhether the completion menu is currently visible.
completion_selected: usizeIndex of the currently selected completion item.
completion_suppressed: boolWhether completion has been suppressed after applying an item.
completion_position: Option<Point>Screen position of the completion menu anchor.
Implementations§
Source§impl LspOverlayState
impl LspOverlayState
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new LspOverlayState with all fields at their default values.
§Example
use iced_code_editor::LspOverlayState;
let state = LspOverlayState::new();
assert!(!state.hover_visible);
assert!(!state.completion_visible);Sourcepub fn set_hover_position(&mut self, point: Point)
pub fn set_hover_position(&mut self, point: Point)
Sets the screen position where the hover tooltip should appear.
Call this when dispatching a hover request to the LSP server.
§Example
use iced::Point;
use iced_code_editor::LspOverlayState;
let mut state = LspOverlayState::new();
state.set_hover_position(Point::new(100.0, 200.0));
assert_eq!(state.hover_position, Some(Point::new(100.0, 200.0)));Sourcepub fn show_hover(&mut self, text: String)
pub fn show_hover(&mut self, text: String)
Displays a hover tooltip with the given text.
Parses the text as markdown and marks the tooltip as visible.
§Example
use iced_code_editor::LspOverlayState;
let mut state = LspOverlayState::new();
state.show_hover("**bold** text".to_string());
assert!(state.hover_visible);
assert!(state.hover_text.is_some());Sourcepub fn clear_hover(&mut self)
pub fn clear_hover(&mut self)
Clears all hover-related state.
Resets hover text, items, visibility, position, and interaction flags.
§Example
use iced_code_editor::LspOverlayState;
let mut state = LspOverlayState::new();
state.show_hover("some text".to_string());
state.clear_hover();
assert!(!state.hover_visible);
assert!(state.hover_text.is_none());Sourcepub fn set_completions(&mut self, items: Vec<String>, position: Point)
pub fn set_completions(&mut self, items: Vec<String>, position: Point)
Sets the completion items and their display position.
Resets the selection to index 0 and applies the current filter.
§Example
use iced::Point;
use iced_code_editor::LspOverlayState;
let mut state = LspOverlayState::new();
state.set_completions(
vec!["foo".to_string(), "bar".to_string()],
Point::ORIGIN,
);
assert_eq!(state.completion_items.len(), 2);Sourcepub fn clear_completions(&mut self)
pub fn clear_completions(&mut self)
Clears all completion-related state.
§Example
use iced::Point;
use iced_code_editor::LspOverlayState;
let mut state = LspOverlayState::new();
state.set_completions(vec!["foo".to_string()], Point::ORIGIN);
state.clear_completions();
assert!(!state.completion_visible);
assert!(state.all_completions.is_empty());Sourcepub fn filter_completions(&mut self)
pub fn filter_completions(&mut self)
Filters all_completions into completion_items using completion_filter.
Updates completion_visible and clamps completion_selected if needed.
§Example
use iced::Point;
use iced_code_editor::LspOverlayState;
let mut state = LspOverlayState::new();
state.set_completions(
vec!["foo".to_string(), "bar".to_string()],
Point::ORIGIN,
);
state.completion_filter = "fo".to_string();
state.filter_completions();
assert_eq!(state.completion_items, vec!["foo".to_string()]);Navigates through the completion list by delta steps, wrapping at boundaries.
§Example
use iced::Point;
use iced_code_editor::LspOverlayState;
let mut state = LspOverlayState::new();
state.set_completions(
vec!["a".to_string(), "b".to_string(), "c".to_string()],
Point::ORIGIN,
);
state.navigate(1);
assert_eq!(state.completion_selected, 1);
state.navigate(-1);
assert_eq!(state.completion_selected, 0);Sourcepub fn selected_item(&self) -> Option<&str>
pub fn selected_item(&self) -> Option<&str>
Returns the currently selected completion item, if any.
§Example
use iced::Point;
use iced_code_editor::LspOverlayState;
let mut state = LspOverlayState::new();
state.set_completions(vec!["foo".to_string()], Point::ORIGIN);
assert_eq!(state.selected_item(), Some("foo"));Sourcepub fn scroll_offset_for_selected(&self) -> f32
pub fn scroll_offset_for_selected(&self) -> f32
Returns the vertical scroll offset in pixels to keep the selected completion item visible when navigating with the keyboard.
Pass the returned value to scrollable::AbsoluteOffset::y.
§Example
use iced::Point;
use iced_code_editor::LspOverlayState;
let mut state = LspOverlayState::new();
state.set_completions(
vec!["a".to_string(), "b".to_string(), "c".to_string()],
Point::ORIGIN,
);
state.navigate(2);
assert_eq!(state.scroll_offset_for_selected(), 40.0);Trait Implementations§
Auto Trait Implementations§
impl Freeze for LspOverlayState
impl !RefUnwindSafe for LspOverlayState
impl Send for LspOverlayState
impl !Sync for LspOverlayState
impl Unpin for LspOverlayState
impl UnsafeUnpin for LspOverlayState
impl UnwindSafe for LspOverlayState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<State, Message> IntoBoot<State, Message> for State
impl<State, Message> IntoBoot<State, Message> for State
Source§fn into_boot(self) -> (State, Task<Message>)
fn into_boot(self) -> (State, Task<Message>)
Application.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more