pub struct FullTextDocument { /* private fields */ }

Implementations§

source§

impl FullTextDocument

source

pub fn new(language_id: String, version: i32, content: String) -> Self

source

pub fn update(&mut self, changes: &[TextDocumentContentChangeEvent], version: i32)

source

pub fn language_id(&self) -> &str

Document’s language id

source

pub fn version(&self) -> i32

Document’s version

source

pub fn get_content(&self, range: Option<Range>) -> &str

Get document content

Examples

Basic usage:

use lsp_textdocument::FullTextDocument;
use lsp_types::{Range, Position};

let text_documents = FullTextDocument::new("plain_text".to_string(), 1, "hello rust!".to_string());

// get document all content
let content = text_documents.get_content(None);
assert_eq!(content, "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_content(Some(range));
assert_eq!(sub_content, "ello rus");
source

pub fn line_count(&self) -> u32

A amount of document content line

source

pub fn content_len(&self) -> u32

The len of the document content

source

pub fn position_at(&self, offset: u32) -> Position

Converts a zero-based offset to a position

source

pub fn offset_at(&self, position: Position) -> u32

Converts a position to a zero-based offset

Trait Implementations§

source§

impl Debug for FullTextDocument

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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.