Skip to content

Commit

Permalink
chore: update tree-sitter, and add xml / dtd
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacasonato committed Jul 15, 2024
1 parent 80ca340 commit fdeeb85
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 50 deletions.
67 changes: 34 additions & 33 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,17 @@ syntect = { version = "5.1.0", optional = true, default-features = false, featur
] }
ammonia = { version = "3.3.0", optional = true }

tree-sitter-highlight = { version = "0.20.1", optional = true }
tree-sitter-javascript = { version = "0.20.1", optional = true }
tree-sitter-typescript = { version = "0.20.3", optional = true }
tree-sitter-json = { version = "0.20.1", optional = true }
tree-sitter-regex = { version = "0.20.0", optional = true }
tree-sitter-css = { version = "0.20.0", optional = true }
tree-sitter-toml = { version = "0.20.0", optional = true }
tree-sitter-md = { version = "0.1.7", optional = true }
tree-sitter-rust = { version = "0.20.4", optional = true }
tree-sitter-html = { version = "0.20.0", optional = true }
tree-sitter-bash = { version = "0.20.5", optional = true }
tree-sitter-highlight = { version = "0.22.6", optional = true }
tree-sitter-javascript = { version = "0.21.4", optional = true }
tree-sitter-typescript = { version = "0.21.2", optional = true }
tree-sitter-json = { version = "0.21.0", optional = true }
tree-sitter-regex = { version = "0.21.0", optional = true }
tree-sitter-css = { version = "0.21.0", optional = true }
tree-sitter-md = { version = "0.2.3", optional = true }
tree-sitter-rust = { version = "0.21.2", optional = true }
tree-sitter-html = { version = "0.20.3", optional = true }
tree-sitter-bash = { version = "0.21.0", optional = true }
tree-sitter-xml = { version = "0.6.4", optional = true }

[dev-dependencies]
anyhow = { version = "1.0.58" }
Expand All @@ -84,11 +84,11 @@ tree-sitter = [
"tree-sitter-json",
"tree-sitter-regex",
"tree-sitter-css",
"tree-sitter-toml",
"tree-sitter-md",
"tree-sitter-rust",
"tree-sitter-html",
"tree-sitter-bash",
"tree-sitter-xml",
]

[[test]]
Expand Down
26 changes: 21 additions & 5 deletions src/html/tree_sitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ pub fn tree_sitter_language_cb(
"json" | "jsonc" => tree_sitter_language_json(),
"css" => tree_sitter_language_css(),
"md" | "markdown" => tree_sitter_language_markdown(),
"toml" => tree_sitter_language_toml(),
"xml" => tree_sitter_language_xml(),
"dtd" => tree_sitter_language_dtd(),
"regex" => tree_sitter_language_regex(),
"rs" | "rust" => tree_sitter_language_rust(),
"html" => tree_sitter_language_html(),
Expand Down Expand Up @@ -190,16 +191,31 @@ fn tree_sitter_language_markdown() -> &'static HighlightConfiguration {
})
}

fn tree_sitter_language_toml() -> &'static HighlightConfiguration {
fn tree_sitter_language_xml() -> &'static HighlightConfiguration {
static CONFIG: OnceLock<HighlightConfiguration> = OnceLock::new();
CONFIG.get_or_init(|| {
let mut config = HighlightConfiguration::new(
tree_sitter_toml::language(),
tree_sitter_toml::HIGHLIGHT_QUERY,
tree_sitter_xml::language_xml(),
tree_sitter_xml::XML_HIGHLIGHT_QUERY,
"",
"",
)
.expect("failed to initialize tree_sitter_toml highlighter");
.expect("failed to initialize tree_sitter_xml highlighter");
config.configure(CAPTURE_NAMES);
config
})
}

fn tree_sitter_language_dtd() -> &'static HighlightConfiguration {
static CONFIG: OnceLock<HighlightConfiguration> = OnceLock::new();
CONFIG.get_or_init(|| {
let mut config = HighlightConfiguration::new(
tree_sitter_xml::language_dtd(),
tree_sitter_xml::DTD_HIGHLIGHT_QUERY,
"",
"",
)
.expect("failed to initialize tree_sitter_dtd highlighter");
config.configure(CAPTURE_NAMES);
config
})
Expand Down

0 comments on commit fdeeb85

Please sign in to comment.