Fix TypeScript and C++ highlighting by including sublanguage queries

main
Charlotte Som 2022-04-30 01:27:47 +01:00
parent e3d680a813
commit a01275f310
2 changed files with 41 additions and 8 deletions

View File

@ -7,7 +7,8 @@ edition = "2021"
default = ["built-in"] default = ["built-in"]
built-in = [ built-in = [
"tree-sitter-rust", "tree-sitter-javascript", "tree-sitter-regex", "tree-sitter-rust", "tree-sitter-javascript", "tree-sitter-regex",
"tree-sitter-python", "tree-sitter-cpp", "tree-sitter-typescript", "tree-sitter-python", "tree-sitter-c", "tree-sitter-cpp",
"tree-sitter-typescript",
] ]
[dependencies] [dependencies]
@ -21,5 +22,6 @@ 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-c = { version = "0.20.1", optional = true }
tree-sitter-cpp = { version = "0.20.0", optional = true } tree-sitter-cpp = { version = "0.20.0", optional = true }
tree-sitter-typescript = { version = "0.20.1", optional = true } tree-sitter-typescript = { version = "0.20.1", optional = true }

View File

@ -50,6 +50,8 @@ pub fn register_builtin_languages() {
register_language("python", python_hl_factory); register_language("python", python_hl_factory);
register_language("py", python_hl_factory); register_language("py", python_hl_factory);
register_language("c", c_hl_factory);
register_language("cpp", cpp_hl_factory); register_language("cpp", cpp_hl_factory);
register_language("c++", cpp_hl_factory); register_language("c++", cpp_hl_factory);
@ -103,10 +105,23 @@ pub fn python_hl_factory() -> Result<HighlightConfiguration, QueryError> {
) )
} }
pub fn c_hl_factory() -> Result<HighlightConfiguration, QueryError> {
HighlightConfiguration::new(
tree_sitter_c::language(),
tree_sitter_c::HIGHLIGHT_QUERY,
"",
"",
)
}
pub fn cpp_hl_factory() -> Result<HighlightConfiguration, QueryError> { pub fn cpp_hl_factory() -> Result<HighlightConfiguration, QueryError> {
HighlightConfiguration::new( HighlightConfiguration::new(
tree_sitter_cpp::language(), tree_sitter_cpp::language(),
tree_sitter_cpp::HIGHLIGHT_QUERY, &format!(
"{}{}",
tree_sitter_c::HIGHLIGHT_QUERY,
tree_sitter_cpp::HIGHLIGHT_QUERY
),
"", "",
"", "",
) )
@ -115,17 +130,33 @@ pub fn cpp_hl_factory() -> Result<HighlightConfiguration, QueryError> {
pub fn typescript_hl_factory() -> Result<HighlightConfiguration, QueryError> { pub fn typescript_hl_factory() -> Result<HighlightConfiguration, QueryError> {
HighlightConfiguration::new( HighlightConfiguration::new(
tree_sitter_typescript::language_typescript(), tree_sitter_typescript::language_typescript(),
&format!(
"{}{}",
tree_sitter_typescript::HIGHLIGHT_QUERY, tree_sitter_typescript::HIGHLIGHT_QUERY,
"", tree_sitter_javascript::HIGHLIGHT_QUERY
tree_sitter_typescript::LOCALS_QUERY, ),
tree_sitter_javascript::INJECTION_QUERY,
&format!(
"{}{}",
tree_sitter_javascript::LOCALS_QUERY,
tree_sitter_typescript::LOCALS_QUERY
),
) )
} }
pub fn tsx_hl_factory() -> Result<HighlightConfiguration, QueryError> { pub fn tsx_hl_factory() -> Result<HighlightConfiguration, QueryError> {
HighlightConfiguration::new( HighlightConfiguration::new(
tree_sitter_typescript::language_tsx(), tree_sitter_typescript::language_tsx(),
&format!(
"{}{}",
tree_sitter_typescript::HIGHLIGHT_QUERY, tree_sitter_typescript::HIGHLIGHT_QUERY,
"", tree_sitter_javascript::HIGHLIGHT_QUERY
tree_sitter_typescript::LOCALS_QUERY, ),
tree_sitter_javascript::INJECTION_QUERY,
&format!(
"{}{}",
tree_sitter_javascript::LOCALS_QUERY,
tree_sitter_typescript::LOCALS_QUERY
),
) )
} }