Skip to main content

LspOverlayState

Struct LspOverlayState 

Source
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: bool

Whether the hover tooltip is currently visible.

§hover_position: Option<Point>

Screen position where the hover tooltip should be rendered.

§hover_interactive: bool

Whether the mouse cursor is currently over the hover tooltip.

§all_completions: Vec<String>

All completion items received from the LSP server.

§completion_filter: String

Current filter string applied to completion items.

§completion_items: Vec<String>

Filtered completion items to display.

§completion_visible: bool

Whether the completion menu is currently visible.

§completion_selected: usize

Index of the currently selected completion item.

§completion_suppressed: bool

Whether completion has been suppressed after applying an item.

§completion_position: Option<Point>

Screen position of the completion menu anchor.

Implementations§

Source§

impl LspOverlayState

Source

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);
Source

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)));
Source

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());
Source

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());
Source

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);
Source

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());
Source

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()]);
Source

pub fn navigate(&mut self, delta: i32)

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);
Source

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"));
Source

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§

Source§

impl Default for LspOverlayState

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<State, Message> IntoBoot<State, Message> for State

Source§

fn into_boot(self) -> (State, Task<Message>)

Turns some type into the initial state of some Application.
Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> MaybeClone for T

Source§

impl<T> MaybeDebug for T

Source§

impl<T> MaybeSend for T
where T: Send,

Source§

impl<T> WasmNotSend for T
where T: Send,