163 lines
4.2 KiB
Rust
163 lines
4.2 KiB
Rust
use tree_sitter::QueryError;
|
|
use tree_sitter_highlight::HighlightConfiguration;
|
|
|
|
use crate::register_language;
|
|
|
|
pub static COMMON_HIGHLIGHT_NAMES: &[&str] = &[
|
|
"attribute",
|
|
"comment",
|
|
"constant",
|
|
"constant.builtin",
|
|
"constant.character",
|
|
"constructor",
|
|
"embedded",
|
|
"escape",
|
|
"function",
|
|
"function.builtin",
|
|
"function.macro",
|
|
"function.method",
|
|
"injection.content",
|
|
"injection.language",
|
|
"keyword",
|
|
"label",
|
|
"local.definition",
|
|
"local.reference",
|
|
"local.scope",
|
|
"number",
|
|
"operator",
|
|
"property",
|
|
"punctuation.bracket",
|
|
"punctuation.delimiter",
|
|
"punctuation.special",
|
|
"string",
|
|
"string.special",
|
|
"type",
|
|
"type.builtin",
|
|
"variable",
|
|
"variable.builtin",
|
|
"variable.parameter",
|
|
];
|
|
|
|
pub fn register_builtin_languages() {
|
|
register_language("rust", rust_hl_factory);
|
|
|
|
register_language("javascript", javascript_hl_factory);
|
|
register_language("js", javascript_hl_factory);
|
|
register_language("jsx", jsx_hl_factory);
|
|
|
|
register_language("regex", regex_hl_factory);
|
|
|
|
register_language("python", python_hl_factory);
|
|
register_language("py", python_hl_factory);
|
|
|
|
register_language("c", c_hl_factory);
|
|
|
|
register_language("cpp", cpp_hl_factory);
|
|
register_language("c++", cpp_hl_factory);
|
|
|
|
register_language("typescript", typescript_hl_factory);
|
|
register_language("ts", typescript_hl_factory);
|
|
register_language("tsx", tsx_hl_factory);
|
|
}
|
|
|
|
pub fn rust_hl_factory() -> Result<HighlightConfiguration, QueryError> {
|
|
HighlightConfiguration::new(
|
|
tree_sitter_rust::language(),
|
|
tree_sitter_rust::HIGHLIGHT_QUERY,
|
|
"",
|
|
"",
|
|
)
|
|
}
|
|
|
|
pub fn javascript_hl_factory() -> Result<HighlightConfiguration, QueryError> {
|
|
HighlightConfiguration::new(
|
|
tree_sitter_javascript::language(),
|
|
tree_sitter_javascript::HIGHLIGHT_QUERY,
|
|
tree_sitter_javascript::INJECTION_QUERY,
|
|
tree_sitter_javascript::LOCALS_QUERY,
|
|
)
|
|
}
|
|
|
|
pub fn jsx_hl_factory() -> Result<HighlightConfiguration, QueryError> {
|
|
HighlightConfiguration::new(
|
|
tree_sitter_javascript::language(),
|
|
tree_sitter_javascript::JSX_HIGHLIGHT_QUERY,
|
|
tree_sitter_javascript::INJECTION_QUERY,
|
|
tree_sitter_javascript::LOCALS_QUERY,
|
|
)
|
|
}
|
|
|
|
pub fn regex_hl_factory() -> Result<HighlightConfiguration, QueryError> {
|
|
HighlightConfiguration::new(
|
|
tree_sitter_regex::language(),
|
|
tree_sitter_regex::HIGHLIGHTS_QUERY,
|
|
"",
|
|
"",
|
|
)
|
|
}
|
|
|
|
pub fn python_hl_factory() -> Result<HighlightConfiguration, QueryError> {
|
|
HighlightConfiguration::new(
|
|
tree_sitter_python::language(),
|
|
tree_sitter_python::HIGHLIGHT_QUERY,
|
|
"",
|
|
"",
|
|
)
|
|
}
|
|
|
|
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> {
|
|
HighlightConfiguration::new(
|
|
tree_sitter_cpp::language(),
|
|
&format!(
|
|
"{}{}",
|
|
tree_sitter_c::HIGHLIGHT_QUERY,
|
|
tree_sitter_cpp::HIGHLIGHT_QUERY
|
|
),
|
|
"",
|
|
"",
|
|
)
|
|
}
|
|
|
|
pub fn typescript_hl_factory() -> Result<HighlightConfiguration, QueryError> {
|
|
HighlightConfiguration::new(
|
|
tree_sitter_typescript::language_typescript(),
|
|
&format!(
|
|
"{}{}",
|
|
tree_sitter_typescript::HIGHLIGHT_QUERY,
|
|
tree_sitter_javascript::HIGHLIGHT_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> {
|
|
HighlightConfiguration::new(
|
|
tree_sitter_typescript::language_tsx(),
|
|
&format!(
|
|
"{}{}",
|
|
tree_sitter_typescript::HIGHLIGHT_QUERY,
|
|
tree_sitter_javascript::HIGHLIGHT_QUERY
|
|
),
|
|
tree_sitter_javascript::INJECTION_QUERY,
|
|
&format!(
|
|
"{}{}",
|
|
tree_sitter_javascript::LOCALS_QUERY,
|
|
tree_sitter_typescript::LOCALS_QUERY
|
|
),
|
|
)
|
|
}
|