Struct lsp_textdocument::FullTextDocument
source · pub struct FullTextDocument { /* private fields */ }Implementations§
source§impl FullTextDocument
impl FullTextDocument
pub fn new(language_id: String, version: i32, content: String) -> Self
pub fn update(&mut self, changes: &[TextDocumentContentChangeEvent], version: i32)
sourcepub fn language_id(&self) -> &str
pub fn language_id(&self) -> &str
Document’s language id
sourcepub fn get_content(&self, range: Option<Range>) -> &str
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");sourcepub fn line_count(&self) -> u32
pub fn line_count(&self) -> u32
A amount of document content line
sourcepub fn content_len(&self) -> u32
pub fn content_len(&self) -> u32
The len of the document content
sourcepub fn position_at(&self, offset: u32) -> Position
pub fn position_at(&self, offset: u32) -> Position
Converts a zero-based offset to a position