pub struct TextDocuments(/* private fields */);
Implementations§
Source§impl TextDocuments
impl TextDocuments
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a text documents
§Examples
Basic usage:
use lsp_textdocument::TextDocuments;
let text_documents = TextDocuments::new();
pub fn documents(&self) -> &BTreeMap<Uri, FullTextDocument>
Sourcepub fn get_document(&self, uri: &Uri) -> Option<&FullTextDocument>
pub fn get_document(&self, uri: &Uri) -> Option<&FullTextDocument>
Get specify document by giving Uri
§Examples:
Basic usage:
use lsp_textdocument::TextDocuments;
use lsp_types::Uri;
let text_documents = TextDocuments::new();
let uri:Uri = "file://example.txt".parse().unwrap();
text_documents.get_document(&uri);
Sourcepub fn get_document_content(
&self,
uri: &Uri,
range: Option<Range>,
) -> Option<&str>
pub fn get_document_content( &self, uri: &Uri, range: Option<Range>, ) -> Option<&str>
Get specify document content by giving Range
§Examples
Basic usage:
use lsp_textdocument::TextDocuments;
use lsp_types::{Uri, Range, Position};
let uri: Uri = "file://example.txt".parse().unwrap();
let text_documents = TextDocuments::new();
// get document all content
let content = text_documents.get_document_content(&uri, None);
assert_eq!(content, Some("hello rust!"));
// get document specify content by range
let (start, end) = (Position::new(0, 1), Position::new(0, 9));
let range = Range::new(start, end);
let sub_content = text_documents.get_document_content(&uri, Some(range));
assert_eq!(sub_content, Some("ello rus"));
Sourcepub fn get_document_language(&self, uri: &Uri) -> Option<&str>
pub fn get_document_language(&self, uri: &Uri) -> Option<&str>
Get specify document’s language by giving Uri
§Examples
Basic usage:
use lsp_textdocument::TextDocuments;
use lsp_types::Uri;
let text_documents = TextDocuments::new();
let uri:Uri = "file://example.js".parse().unwrap();
let language = text_documents.get_document_language(&uri);
assert_eq!(language, Some("javascript"));
Sourcepub fn listen(&mut self, method: &str, params: &Value) -> bool
pub fn listen(&mut self, method: &str, params: &Value) -> bool
Listening the notification from client, you just need to pass method
and params
§Examples:
Basic usage:
use lsp_textdocument::TextDocuments;
let method = "textDocument/didOpen";
let params = serde_json::to_value("message produced by client").unwrap();
let mut text_documents = TextDocuments::new();
let accept: bool = text_documents.listen(method, ¶ms);
Trait Implementations§
Source§impl Default for TextDocuments
impl Default for TextDocuments
Source§fn default() -> TextDocuments
fn default() -> TextDocuments
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for TextDocuments
impl !RefUnwindSafe for TextDocuments
impl Send for TextDocuments
impl Sync for TextDocuments
impl Unpin for TextDocuments
impl !UnwindSafe for TextDocuments
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
Mutably borrows from an owned value. Read more