add tags config fixture test helper

This commit is contained in:
Michael Davis 2021-12-18 10:48:59 -06:00
parent 067f742ad3
commit 47dc88b647
No known key found for this signature in database
GPG key ID: 25D3AFE4BA2A0C49

View file

@ -4,6 +4,7 @@ use std::path::{Path, PathBuf};
use tree_sitter::Language;
use tree_sitter_highlight::HighlightConfiguration;
use tree_sitter_loader::Loader;
use tree_sitter_tags::TagsConfiguration;
include!("./dirs.rs");
@ -54,6 +55,14 @@ pub fn get_highlight_config(
result
}
pub fn get_tags_config(language_name: &str) -> TagsConfiguration {
let language = get_language(language_name);
let queries_path = get_language_queries_path(language_name);
let tags_query = fs::read_to_string(queries_path.join("tags.scm")).unwrap();
let locals_query = fs::read_to_string(queries_path.join("locals.scm")).unwrap_or(String::new());
TagsConfiguration::new(language, &tags_query, &locals_query).unwrap()
}
pub fn get_test_language(name: &str, parser_code: &str, path: Option<&Path>) -> Language {
let parser_c_path = SCRATCH_DIR.join(&format!("{}-parser.c", name));
if !fs::read_to_string(&parser_c_path)