on master help sign in
Add query-check xtask
4e4c6daMichael Davis
.github/workflows/build.yml+20
@@ -131,3 +131,23 @@ jobs:
131 || (echo "Run 'cargo xtask docgen', commit the changes and push again" \
131 || (echo "Run 'cargo xtask docgen', commit the changes and push again" \
132 && exit 1)
132 && exit 1)
133
133
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"
1476version = "0.6.0"
1476version = "0.6.0"
1477dependencies = [
1477dependencies = [
1478 "helix-core",
1478 "helix-core",
1479+ "helix-loader",
1479 "helix-term",
1480 "helix-term",
1480 "toml",
1481 "toml",
1481]
1482]
helix-core/src/syntax.rs+1−1
@@ -334,7 +334,7 @@ impl TextObjectQuery {
334 }
334 }
335}
335}
336
336
337−fn read_query(language: &str, filename: &str) -> String {
337+pub fn read_query(language: &str, filename: &str) -> String {
338 static INHERITS_REGEX: Lazy<Regex> =
338 static INHERITS_REGEX: Lazy<Regex> =
339 Lazy::new(|| Regex::new(r";+\s*inherits\s*:?\s*([a-z_,()-]+)\s*").unwrap());
339 Lazy::new(|| Regex::new(r";+\s*inherits\s*:?\s*([a-z_,()-]+)\s*").unwrap());
340
340
xtask/Cargo.toml+1
@@ -8,4 +8,5 @@ edition = "2021"
8[dependencies]
8[dependencies]
9helix-term = { version = "0.6", path = "../helix-term" }
9helix-term = { version = "0.6", path = "../helix-term" }
10helix-core = { version = "0.6", path = "../helix-core" }
10helix-core = { version = "0.6", path = "../helix-core" }
11+helix-loader = { version = "0.6", path = "../helix-loader" }
11toml = "0.5"
12toml = "0.5"
xtask/src/main.rs+37
@@ -217,6 +217,41 @@ pub mod tasks {
217 Ok(())
217 Ok(())
218 }
218 }
219
219
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+
220 pub fn print_help() {
255 pub fn print_help() {
221 println!(
256 println!(
222 "
257 "
@@ -224,6 +259,7 @@ Usage: Run with `cargo xtask <task>`, eg. `cargo xtask docgen`.
224
259
225 Tasks:
260 Tasks:
226 docgen: Generate files to be included in the mdbook output.
261 docgen: Generate files to be included in the mdbook output.
262+ query-check: Check that tree-sitter queries are valid.
227"
263"
228 );
264 );
229 }
265 }
@@ -235,6 +271,7 @@ fn main() -> Result<(), DynError> {
235 None => tasks::print_help(),
271 None => tasks::print_help(),
236 Some(t) => match t.as_str() {
272 Some(t) => match t.as_str() {
237 "docgen" => tasks::docgen()?,
273 "docgen" => tasks::docgen()?,
274+ "query-check" => tasks::query_check()?,
238 invalid => return Err(format!("Invalid task name: {}", invalid).into()),
275 invalid => return Err(format!("Invalid task name: {}", invalid).into()),
239 },
276 },
240 };
277 };