pub trait LspClient {
// Provided methods
fn did_open(&mut self, _document: &LspDocument, _text: &str) { ... }
fn did_change(
&mut self,
_document: &LspDocument,
_changes: &[LspTextChange],
) { ... }
fn did_save(&mut self, _document: &LspDocument, _text: &str) { ... }
fn did_close(&mut self, _document: &LspDocument) { ... }
fn request_hover(&mut self, _document: &LspDocument, _position: LspPosition) { ... }
fn request_completion(
&mut self,
_document: &LspDocument,
_position: LspPosition,
) { ... }
fn request_definition(
&mut self,
_document: &LspDocument,
_position: LspPosition,
) { ... }
}Expand description
LSP integration types and traits for editor clients. LSP client hooks invoked by the editor.
Every method has a no-op default, so an implementation only overrides the
notifications and requests it actually cares about. Attach one with
CodeEditor::attach_lsp; the editor never blocks on a response, so
request results come back through whatever channel the implementation
chooses.
§Example
use std::cell::RefCell;
use std::rc::Rc;
use iced_code_editor::{CodeEditor, LspClient, LspDocument, LspTextChange};
/// A client that only records how many change batches it received.
struct CountingClient(Rc<RefCell<usize>>);
impl LspClient for CountingClient {
fn did_change(&mut self, _document: &LspDocument, changes: &[LspTextChange]) {
*self.0.borrow_mut() += changes.len();
}
}
let changes = Rc::new(RefCell::new(0));
let mut editor = CodeEditor::new("fn main() {}", "rs");
editor.attach_lsp(
Box::new(CountingClient(Rc::clone(&changes))),
LspDocument::new("file:///tmp/main.rs", "rust"),
);
// `did_open` fired, but no change has been flushed yet.
assert_eq!(*changes.borrow(), 0);Provided Methods§
Sourcefn did_open(&mut self, _document: &LspDocument, _text: &str)
fn did_open(&mut self, _document: &LspDocument, _text: &str)
Notifies the client that a document was opened.
Sourcefn did_change(&mut self, _document: &LspDocument, _changes: &[LspTextChange])
fn did_change(&mut self, _document: &LspDocument, _changes: &[LspTextChange])
Notifies the client that the document changed.
Sourcefn did_save(&mut self, _document: &LspDocument, _text: &str)
fn did_save(&mut self, _document: &LspDocument, _text: &str)
Notifies the client that the document was saved.
Sourcefn did_close(&mut self, _document: &LspDocument)
fn did_close(&mut self, _document: &LspDocument)
Notifies the client that the document was closed.
Sourcefn request_hover(&mut self, _document: &LspDocument, _position: LspPosition)
fn request_hover(&mut self, _document: &LspDocument, _position: LspPosition)
Requests hover information at the given position.
Sourcefn request_completion(
&mut self,
_document: &LspDocument,
_position: LspPosition,
)
fn request_completion( &mut self, _document: &LspDocument, _position: LspPosition, )
Requests completion items at the given position.
Sourcefn request_definition(
&mut self,
_document: &LspDocument,
_position: LspPosition,
)
fn request_definition( &mut self, _document: &LspDocument, _position: LspPosition, )
Requests the definition location(s) for the symbol at the given position.
This method is called when the user triggers a “Go to Definition” action
(e.g., via Ctrl+Click or a context menu). The client implementation should
send a textDocument/definition request to the LSP server.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".