Crates.io | html-languageservice |
lib.rs | html-languageservice |
version | 0.7.0 |
source | src |
created_at | 2023-12-04 08:42:33.664143 |
updated_at | 2024-09-25 11:02:38.62878 |
description | The basics of an HTML language server. |
homepage | https://github.com/ren-wei/html-languageservice |
repository | https://github.com/ren-wei/html-languageservice |
max_upload_size | |
id | 1057421 |
size | 777,595 |
The project is a rewrite of vscode-html-languageservice use
rust
. It has all the features of the original project while still having higher performance.
This project is a collection of features necessary to implement an HTML language server.
completion
feature activatehover
feature activateformatter
feature activatehighlight
feature activatelinks
feature activatesymbols
feature activatefolding
feature activateselection_range
feature activatecompletion
feature activatecompletion
feature activaterename
feature activatematching_tag_position
feature activatelinked_editing
feature activateThe hover
and complete
related to the data need to create the HTMLLanguageService
struct first, and the other functions are not related to the data, but are used as its association functions and can be called directly.
Make sure you activated the full features of the html-languageservice
crate on Cargo.toml
:
html-languageservice = { version = "0.6.1", features = ["full"] }
You can also activate only some of the features you need on Cargo.toml
:
html-languageservice = { version = "0.6.1", features = ["completion", "hover"] }
Second, You need to prepare: document
and position
.
Then, parse document
as html_document
you need to HTMLDataManager
, tags, attributes, and attribute value data are stored in the HTMLDataManager
.
Finally, call a function or method to get the result.
use std::sync::Arc;
use html_languageservice::{
services::html_completion::DefaultDocumentContext, LanguageService, LanguageServiceOptions,
};
use lsp_textdocument::FullTextDocument;
use lsp_types::Position;
#[tokio::main]
async fn main() {
// prepare
let document = FullTextDocument::new("html".to_string(), 1, "<div></div>".to_string());
let position = Position::new(0, 1);
// init
let data_manager = HTMLDataManager::new(true, None);
let html_document = HTMLLanguageService::parse_html_document(&document, &data_manager);
let ls = HTMLLanguageService::new(HTMLLanguageServiceOptions::default());
// hover
let hover = ls
.do_hover(&document, &position, &html_document, None, &data_manager)
.await;
assert!(hover.is_some());
// complete
let document_context = DefaultDocumentContext;
let completion_list = ls
.do_complete(
&document,
&position,
&html_document,
document_context,
None,
&data_manager,
)
.await;
assert!(completion_list.items.len() > 0);
}