refactor: share language IDs with indentation configuration

This commit is contained in:
Valdemar Lorenzen
2026-10-14 12:11:26 +02:00
parent 6a43fb9e0c
commit 5580d6fbd4
9 changed files with 41 additions and 16 deletions
+7 -2
View File
@@ -9,12 +9,16 @@ use tree_sitter::{
mod languages;
use languages::LanguageSpec;
pub(crate) const RUST_ID: &str = "rust";
pub(crate) const RUBY_ID: &str = "ruby";
pub(crate) const PYTHON_ID: &str = "python";
pub(crate) fn is_markdown_path(path: &Path) -> bool {
languages::detect(Some(path), None).is_some_and(|syntax| syntax.name == "Markdown")
}
pub(crate) fn language_name(path: Option<&Path>, first_line: Option<&str>) -> Option<&'static str> {
languages::detect(path, first_line).map(|syntax| syntax.name)
pub(crate) fn language_id(path: Option<&Path>, first_line: Option<&str>) -> Option<&'static str> {
languages::detect(path, first_line).map(|syntax| syntax.id)
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
@@ -2120,6 +2124,7 @@ mod tests {
"((identifier) @function (#unsupported? @function))",
]
.map(|query| LanguageSpec {
id: language.id,
name: "invalid test grammar query",
language: language.language.clone(),
highlights: query,