use crate::{
lang::Lang,
registry::{self, Entry},
};
pub fn install() {
for lang in LANGS {
registry::register(Entry {
name: lang.name,
aliases: lang.aliases,
files: files_for(lang.name),
lang: Some(lang),
});
}
}
fn files_for(name: &str) -> &'static [&'static str] {
FILES
.iter()
.find(|(held, _)| *held == name)
.map(|(_, files)| *files)
.unwrap_or(&[])
}
#[rustfmt::skip]
const FILES: &[(&str, &[&str])] = &[
("bash", &[".bash_profile", ".bashrc", ".profile", ".zshrc", "bash", "sh", "zsh"]),
("go", &["go"]),
("json", &["json", "jsonc"]),
("python", &["py", "pyi"]),
("rust", &["rs"]),
("toml", &["toml"]),
("tsx", &["cjs", "jsx", "mjs", "tsx"]),
("typescript", &["cts", "mts", "ts"]),
];
#[cfg(feature = "rust")]
static RUST: Lang = Lang::new(
"rust",
&["rust", "rs"],
crate::lang::Grammar::Native(tree_sitter_rust::LANGUAGE),
include_str!("../queries/rust.scm"),
);
#[cfg(feature = "python")]
static PYTHON: Lang = Lang::new(
"python",
&["python", "py"],
crate::lang::Grammar::Native(tree_sitter_python::LANGUAGE),
include_str!("../queries/python.scm"),
);
#[cfg(feature = "typescript")]
static TYPESCRIPT: Lang = Lang::new(
"typescript",
&["typescript", "ts"],
crate::lang::Grammar::Native(tree_sitter_typescript::LANGUAGE_TYPESCRIPT),
include_str!("../queries/typescript.scm"),
);
#[cfg(feature = "typescript")]
static TSX: Lang = Lang::new(
"tsx",
&["tsx", "jsx", "javascript", "js"],
crate::lang::Grammar::Native(tree_sitter_typescript::LANGUAGE_TSX),
include_str!("../queries/tsx.scm"),
);
#[cfg(feature = "json")]
static JSON: Lang = Lang::new(
"json",
&["json", "jsonc"],
crate::lang::Grammar::Native(tree_sitter_json::LANGUAGE),
include_str!("../queries/json.scm"),
);
#[cfg(feature = "go")]
static GO: Lang = Lang::new(
"go",
&["go", "golang"],
crate::lang::Grammar::Native(tree_sitter_go::LANGUAGE),
include_str!("../queries/go.scm"),
);
#[cfg(feature = "bash")]
static BASH: Lang = Lang::new(
"bash",
&["bash", "sh", "shell", "zsh", "console"],
crate::lang::Grammar::Native(tree_sitter_bash::LANGUAGE),
include_str!("../queries/bash.scm"),
);
#[cfg(feature = "toml")]
static TOML: Lang = Lang::new(
"toml",
&["toml"],
crate::lang::Grammar::Native(tree_sitter_toml_ng::LANGUAGE),
include_str!("../queries/toml.scm"),
);
pub static LANGS: &[&Lang] = &[
#[cfg(feature = "rust")]
&RUST,
#[cfg(feature = "python")]
&PYTHON,
#[cfg(feature = "typescript")]
&TYPESCRIPT,
#[cfg(feature = "typescript")]
&TSX,
#[cfg(feature = "json")]
&JSON,
#[cfg(feature = "go")]
&GO,
#[cfg(feature = "bash")]
&BASH,
#[cfg(feature = "toml")]
&TOML,
];