Crates.io | html-languageservice |
lib.rs | html-languageservice |
version | |
source | src |
created_at | 2023-12-04 08:42:33.664143 |
updated_at | 2024-12-10 15:45:24.517807 |
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 |
Cargo.toml error: | TOML parse error at line 17, column 1 | 17 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
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);
}