Add more built-in languages: C++, TypeScript

main
Charlotte Som 2022-04-28 19:59:27 +01:00
parent 2cc38dba2c
commit 5f47ca5aa9
2 changed files with 43 additions and 4 deletions

View File

@ -5,7 +5,10 @@ edition = "2021"
[features] [features]
default = ["built-in"] default = ["built-in"]
built-in = ["tree-sitter-rust", "tree-sitter-javascript", "tree-sitter-regex", "tree-sitter-python"] built-in = [
"tree-sitter-rust", "tree-sitter-javascript", "tree-sitter-regex",
"tree-sitter-python", "tree-sitter-cpp", "tree-sitter-typescript",
]
[dependencies] [dependencies]
html-escape = "0.2.11" html-escape = "0.2.11"
@ -18,3 +21,5 @@ tree-sitter-rust = { version = "0.20.1", optional = true }
tree-sitter-javascript = { version = "0.20.0", optional = true } tree-sitter-javascript = { version = "0.20.0", optional = true }
tree-sitter-regex = { git = "https://github.com/tree-sitter/tree-sitter-regex.git", rev = "e1cfca", optional = true } tree-sitter-regex = { git = "https://github.com/tree-sitter/tree-sitter-regex.git", rev = "e1cfca", optional = true }
tree-sitter-python = { version = "0.19.1", optional = true } tree-sitter-python = { version = "0.19.1", optional = true }
tree-sitter-cpp = { version = "0.20.0", optional = true }
tree-sitter-typescript = { version = "0.20.1", optional = true }

View File

@ -33,8 +33,15 @@ pub fn register_builtin_languages() {
register_language("regex", regex_hl_factory); register_language("regex", regex_hl_factory);
register_language("python", tree_sitter_python); register_language("python", regex_hl_python);
register_language("py", tree_sitter_python); register_language("py", regex_hl_python);
register_language("cpp", regex_hl_cpp);
register_language("c++", regex_hl_cpp);
register_language("typescript", regex_hl_typescript);
register_language("ts", regex_hl_typescript);
register_language("tsx", regex_hl_tsx);
} }
pub fn rust_hl_factory() -> Result<HighlightConfiguration, QueryError> { pub fn rust_hl_factory() -> Result<HighlightConfiguration, QueryError> {
@ -73,7 +80,7 @@ pub fn regex_hl_factory() -> Result<HighlightConfiguration, QueryError> {
) )
} }
pub fn tree_sitter_python() -> Result<HighlightConfiguration, QueryError> { pub fn regex_hl_python() -> Result<HighlightConfiguration, QueryError> {
HighlightConfiguration::new( HighlightConfiguration::new(
tree_sitter_python::language(), tree_sitter_python::language(),
tree_sitter_python::HIGHLIGHT_QUERY, tree_sitter_python::HIGHLIGHT_QUERY,
@ -81,3 +88,30 @@ pub fn tree_sitter_python() -> Result<HighlightConfiguration, QueryError> {
"", "",
) )
} }
pub fn regex_hl_cpp() -> Result<HighlightConfiguration, QueryError> {
HighlightConfiguration::new(
tree_sitter_cpp::language(),
tree_sitter_cpp::HIGHLIGHT_QUERY,
"",
"",
)
}
pub fn regex_hl_typescript() -> Result<HighlightConfiguration, QueryError> {
HighlightConfiguration::new(
tree_sitter_typescript::language_typescript(),
tree_sitter_typescript::HIGHLIGHT_QUERY,
"",
tree_sitter_typescript::LOCALS_QUERY,
)
}
pub fn regex_hl_tsx() -> Result<HighlightConfiguration, QueryError> {
HighlightConfiguration::new(
tree_sitter_typescript::language_tsx(),
tree_sitter_typescript::HIGHLIGHT_QUERY,
"",
tree_sitter_typescript::LOCALS_QUERY,
)
}