Struct TextDocuments

Source
pub struct TextDocuments(/* private fields */);

Implementations§

Source§

impl TextDocuments

Source

pub fn new() -> Self

Create a text documents

§Examples

Basic usage:

use lsp_textdocument::TextDocuments;

let text_documents = TextDocuments::new();
Source

pub fn documents(&self) -> &BTreeMap<Uri, FullTextDocument>

Source

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

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

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

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, &params);

Trait Implementations§

Source§

impl Default for TextDocuments

Source§

fn default() -> TextDocuments

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, 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<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.