commit 524164ae056aeea51b9d20f649ed77d4f88ed490
parent 30d9970cd74d980c93aebeba019a7179147e9a1a
Author: Riley Bruins <ribru17@hotmail.com>
Date: Fri, 14 Mar 2025 10:40:36 -0700
ci: lint and format treesitter queries
This also adds a `formatquery` rule to write the new format to the query
files.
Diffstat:
4 files changed, 36 insertions(+), 6 deletions(-)
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
@@ -41,6 +41,11 @@ jobs:
wget --directory-prefix="$BIN_DIR" https://github.com/JohnnyMorganz/StyLua/releases/latest/download/stylua-linux-aarch64.zip
(cd "$BIN_DIR"; unzip stylua*.zip)
+ - name: Install ts_query_ls
+ run: |
+ wget --directory-prefix="$BIN_DIR" https://github.com/ribru17/ts_query_ls/releases/latest/download/ts_query_ls-aarch64-unknown-linux-gnu.tar.gz
+ (cd "$BIN_DIR"; tar -xzvf ts_query_ls-aarch64-unknown-linux-gnu.tar.gz)
+
- name: Build third-party deps
run: |
cmake -S cmake.deps -B .deps -G Ninja
@@ -70,6 +75,10 @@ jobs:
run: cmake --build build --target lintsh
- if: success() || failure() && steps.abort_job.outputs.status == 'success'
+ name: lintquery
+ run: cmake --build build --target lintquery
+
+ - if: success() || failure() && steps.abort_job.outputs.status == 'success'
name: clint.lua
run: cmake --build build --target lintc-clint
diff --git a/CMakeLists.txt b/CMakeLists.txt
@@ -236,6 +236,8 @@ find_program(SHELLCHECK_PRG shellcheck ${LINT_REQUIRED})
mark_as_advanced(SHELLCHECK_PRG)
find_program(STYLUA_PRG stylua ${LINT_REQUIRED})
mark_as_advanced(STYLUA_PRG)
+find_program(TS_QUERY_LS_PRG ts_query_ls ${LINT_REQUIRED})
+mark_as_advanced(TS_QUERY_LS_PRG)
set(STYLUA_DIRS runtime scripts src test contrib)
@@ -277,12 +279,24 @@ add_glob_target(
GLOB_PAT *.sh
TOUCH_STRATEGY PER_DIR)
+add_custom_target(lintquery-compilation
+ COMMAND ${TS_QUERY_LS_PRG}
+ check ${PROJECT_SOURCE_DIR}/runtime/queries --config
+ '{"parser_install_directories": ["${DEPS_PREFIX}/lib/nvim/parser"]}')
+
+add_custom_target(lintquery-format
+ COMMAND ${TS_QUERY_LS_PRG}
+ format ${PROJECT_SOURCE_DIR}/runtime/queries --check)
+
+add_custom_target(lintquery)
+add_dependencies(lintquery lintquery-compilation lintquery-format)
+
add_custom_target(lintcommit
COMMAND $<TARGET_FILE:nvim_bin> --clean -l ${PROJECT_SOURCE_DIR}/scripts/lintcommit.lua main)
add_dependencies(lintcommit nvim_bin)
add_custom_target(lint)
-add_dependencies(lint lintc lintlua lintsh)
+add_dependencies(lint lintc lintlua lintsh lintquery)
# Format
add_glob_target(
@@ -301,8 +315,13 @@ add_custom_target(formatlua2
"${PROJECT_SOURCE_DIR}/test/functional/ui/multigrid_spec.lua"
)
add_dependencies(formatlua formatlua2)
+
+add_custom_target(formatquery
+ COMMAND ${TS_QUERY_LS_PRG}
+ format ${PROJECT_SOURCE_DIR}/runtime/queries)
+
add_custom_target(format)
-add_dependencies(format formatc formatlua)
+add_dependencies(format formatc formatlua formatquery)
install_helper(
FILES ${CMAKE_SOURCE_DIR}/src/man/nvim.1
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
@@ -183,9 +183,11 @@ make lint
- You can format files by using:
```bash
- make format # or formatc, formatlua
+ make format # or formatc, formatlua, formatquery
```
- This will format changed Lua and C files with all appropriate flags set.
+ This will format changed C, Lua, and treesitter query files with all
+ appropriate flags set.
+
- Style rules are (mostly) defined by `src/uncrustify.cfg` which tries to match
the [style-guide]. To use the Nvim `gq` command with `uncrustify`:
```vim
diff --git a/Makefile b/Makefile
@@ -144,8 +144,8 @@ test/old/testdir/%.vim: phony_force nvim
functionaltest-lua: | nvim
$(CMAKE) --build build --target functionaltest
-FORMAT=formatc formatlua format
-LINT=lintlua lintsh lintc clang-analyzer lintcommit lintdoc lintdocurls lint luals
+FORMAT=formatc formatlua formatquery format
+LINT=lintlua lintsh lintc clang-analyzer lintcommit lintdoc lintdocurls lint luals lintquery
TEST=functionaltest unittest
generated-sources benchmark $(FORMAT) $(LINT) $(TEST) doc: | build/.ran-cmake
$(CMAKE) --build build --target $@