pub struct TextDocuments(_);

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) -> &HashMap<Url, FullTextDocument>

source

pub fn get_document(&self, uri: &Url) -> Option<&FullTextDocument>

get specify document by giving Url

Examples:

Basic usage:

use lsp_textdocument::TextDocuments;
use lsp_types::Url;

let text_documents = TextDocuments::new();
let uri:Url = "file://example.txt".parse().unwrap();
text_documents.get_document(&uri);
source

pub fn get_document_content(
&self,
uri: &Url,
range: Option<Range>
) -> Option<&str>

get specify document content by giving Range

Examples

Basic usage:

use lsp_textdocument::TextDocuments;
use lsp_types::{Url, Range, Position};

let uri: Url = "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: &Url) -> Option<&str>

get specify document’s language by giving Url

Examples

Basic usage:

use lsp_textdocument::TextDocuments;
use lsp_types::Url;

let text_documents = TextDocuments::new();
let uri:Url = "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();
text_documents.listen(method, &params);

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 Twhere
U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.