feat: added initial HTML support

This commit is contained in:
Elijah Potter
2024-07-14 21:30:08 -06:00
parent 0f5c0f3df8
commit bdbac8dcd4
7 changed files with 70 additions and 3 deletions

21
Cargo.lock generated
View File

@@ -543,6 +543,16 @@ dependencies = [
"unicode-width",
]
[[package]]
name = "harper-html"
version = "0.8.8"
dependencies = [
"harper-core",
"harper-tree-sitter",
"tree-sitter",
"tree-sitter-html",
]
[[package]]
name = "harper-ls"
version = "0.8.8"
@@ -553,6 +563,7 @@ dependencies = [
"futures",
"harper-comments",
"harper-core",
"harper-html",
"itertools 0.13.0",
"once_cell",
"open",
@@ -1437,6 +1448,16 @@ dependencies = [
"tree-sitter",
]
[[package]]
name = "tree-sitter-html"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "184e6b77953a354303dc87bf5fe36558c83569ce92606e7b382a0dc1b7443443"
dependencies = [
"cc",
"tree-sitter",
]
[[package]]
name = "tree-sitter-java"
version = "0.20.2"

View File

@@ -1,5 +1,5 @@
[workspace]
members = [ "harper-cli", "harper-core", "harper-ls", "harper-comments", "harper-wasm", "harper-tree-sitter"]
members = [ "harper-cli", "harper-core", "harper-ls", "harper-comments", "harper-wasm", "harper-tree-sitter", "harper-html"]
resolver = "2"
[profile.release]

View File

@@ -2,4 +2,4 @@
This crate holds a number of functions, but it is primarily a wrapper around `tree-sitter` that allows Harper to locate the comments of a wide variety of programming languages.
It also has purpose-built parsers for the structured comments of a number of languages, including Go.
These additional parsers are avaiable through the `TreeSitterParser` and are enabled automatically through there.
These additional parsers are available through the `CommentParser` and are enabled automatically through there.

14
harper-html/Cargo.toml Normal file
View File

@@ -0,0 +1,14 @@
[package]
name = "harper-html"
version = "0.8.8"
edition = "2021"
description = "The language checker for developers."
license = "Apache-2.0"
readme = "README.md"
repository = "https://github.com/elijah-potter/harper"
[dependencies]
harper-core = { path = "../harper-core", version = "0.8.0" }
harper-tree-sitter = { path = "../harper-tree-sitter", version = "0.8.0" }
tree-sitter-html = "0.19.0"
tree-sitter = "0.20.10"

29
harper-html/src/lib.rs Normal file
View File

@@ -0,0 +1,29 @@
use harper_core::parsers::{self, Parser, PlainEnglish};
use harper_core::Token;
use harper_tree_sitter::TreeSitterMasker;
use tree_sitter::Node;
pub struct HtmlParser {
inner: parsers::Mask<TreeSitterMasker, PlainEnglish>
}
impl HtmlParser {
pub fn new() -> Self {
Self {
inner: parsers::Mask::new(
TreeSitterMasker::new(tree_sitter_html::language(), Self::node_condition),
PlainEnglish
)
}
}
fn node_condition(n: &Node) -> bool {
n.kind() == "text"
}
}
impl Parser for HtmlParser {
fn parse(&mut self, source: &[char]) -> Vec<Token> {
self.inner.parse(source)
}
}

View File

@@ -10,6 +10,7 @@ repository = "https://github.com/elijah-potter/harper"
[dependencies]
harper-core = { path = "../harper-core", version = "0.8.0", features = ["concurrent"] }
harper-comments = { path = "../harper-comments", version = "0.8.0" }
harper-html = { path = "../harper-html", version = "0.8.0" }
tower-lsp = "0.20.0"
tokio = { version = "1.36.0", features = ["fs", "rt", "rt-multi-thread", "macros", "io-std", "io-util", "net"] }
clap = { version = "4.5.1", features = ["derive"] }

View File

@@ -14,6 +14,7 @@ use harper_core::{
Token,
TokenKind
};
use harper_html::HtmlParser;
use serde_json::Value;
use tokio::sync::{Mutex, RwLock};
use tower_lsp::jsonrpc::Result;
@@ -260,6 +261,8 @@ impl Backend {
Document::new(text, Box::new(Markdown))
} else if language_id == "gitcommit" {
Document::new(text, Box::new(GitCommitParser))
} else if language_id == "html" {
Document::new(text, Box::new(HtmlParser::new()))
} else if language_id == "mail" {
Document::new(text, Box::new(PlainEnglish))
} else {
@@ -372,7 +375,6 @@ impl LanguageServer for Backend {
save: Some(TextDocumentSyncSaveOptions::Supported(true))
}
)),
..Default::default()
}
})