on master help sign in
Add query-check xtask
commit4e4c6da3bfdea0e50e460298eedf41d835f2a551 authorMichael Davis <mcarsondavis@gmail.com> dateThu 25 Aug 2022, 17:24 (4 years ago) parentfa1dc7e
5 files changed+60−1
.github/workflows/build.yml+20 Cargo.lock+1 helix-core/src/syntax.rs+1−1 xtask/Cargo.toml+1 xtask/src/main.rs+37
.github/workflows/build.yml+20
@@ -131,3 +131,23 @@ jobs:
131131 || (echo "Run 'cargo xtask docgen', commit the changes and push again" \
132132 && exit 1)
133133
134+ queries:
135+ name: Tree-sitter queries
136+ runs-on: ubuntu-latest
137+ steps:
138+ - name: Checkout sources
139+ uses: actions/checkout@v3
140+
141+ - name: Install stable toolchain
142+ uses: helix-editor/rust-toolchain@v1
143+ with:
144+ profile: minimal
145+ override: true
146+
147+ - uses: Swatinem/rust-cache@v1
148+
149+ - name: Generate docs
150+ uses: actions-rs/cargo@v1
151+ with:
152+ command: xtask
153+ args: query-check
Cargo.lock+1
@@ -1476,6 +1476,7 @@ name = "xtask"
14761476version = "0.6.0"
14771477dependencies = [
14781478 "helix-core",
1479+ "helix-loader",
14791480 "helix-term",
14801481 "toml",
14811482]
helix-core/src/syntax.rs+1−1
@@ -334,7 +334,7 @@ impl TextObjectQuery {
334334 }
335335}
336336
337−fn read_query(language: &str, filename: &str) -> String {
337+pub fn read_query(language: &str, filename: &str) -> String {
338338 static INHERITS_REGEX: Lazy<Regex> =
339339 Lazy::new(|| Regex::new(r";+\s*inherits\s*:?\s*([a-z_,()-]+)\s*").unwrap());
340340
xtask/Cargo.toml+1
@@ -8,4 +8,5 @@ edition = "2021"
88[dependencies]
99helix-term = { version = "0.6", path = "../helix-term" }
1010helix-core = { version = "0.6", path = "../helix-core" }
11+helix-loader = { version = "0.6", path = "../helix-loader" }
1112toml = "0.5"
xtask/src/main.rs+37
@@ -217,6 +217,41 @@ pub mod tasks {
217217 Ok(())
218218 }
219219
220+ pub fn query_check() -> Result<(), String> {
221+ use crate::helpers::lang_config;
222+ use helix_core::{syntax::read_query, tree_sitter::Query};
223+ use helix_loader::grammar::get_language;
224+
225+ let query_files = [
226+ "highlights.scm",
227+ "locals.scm",
228+ "injections.scm",
229+ "textobjects.scm",
230+ "indents.scm",
231+ ];
232+
233+ for language in lang_config().language {
234+ let language_name = language.language_id.to_ascii_lowercase();
235+ let grammar_name = language.grammar.unwrap_or(language.language_id);
236+ for query_file in query_files {
237+ let language = get_language(&grammar_name);
238+ let query_text = read_query(&language_name, query_file);
239+ if !query_text.is_empty() && language.is_ok() {
240+ if let Err(reason) = Query::new(language.unwrap(), &query_text) {
241+ return Err(format!(
242+ "Failed to parse {} queries for {}: {}",
243+ query_file, language_name, reason
244+ ));
245+ }
246+ }
247+ }
248+ }
249+
250+ println!("Query check succeeded");
251+
252+ Ok(())
253+ }
254+
220255 pub fn print_help() {
221256 println!(
222257 "
@@ -224,6 +259,7 @@ Usage: Run with `cargo xtask <task>`, eg. `cargo xtask docgen`.
224259
225260 Tasks:
226261 docgen: Generate files to be included in the mdbook output.
262+ query-check: Check that tree-sitter queries are valid.
227263"
228264 );
229265 }
@@ -235,6 +271,7 @@ fn main() -> Result<(), DynError> {
235271 None => tasks::print_help(),
236272 Some(t) => match t.as_str() {
237273 "docgen" => tasks::docgen()?,
274+ "query-check" => tasks::query_check()?,
238275 invalid => return Err(format!("Invalid task name: {}", invalid).into()),
239276 },
240277 };