aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMagnus Larsen <magnusfynbo@hotmail.com>2024-06-02 05:46:51 +0200
committerGitHub <noreply@github.com>2024-06-01 20:46:51 -0700
commit63e0a32c85a39484813957dc480f171907aa90b9 (patch)
tree9ad5828a5ac1d4725ad91d4604a642a586164d51
parentccbbeb7087f7ee41552ebc4bac50c346d5832803 (diff)
feat: add treesitter query formatter (#425)
* [feat]: add treesitter query formatter * [docgen] Update docs skip-checks: true * lint * refactor: fix condition and simplify some logic * [docgen] Update docs skip-checks: true --------- Co-authored-by: Magnus Larsen <mzla@topsoe.com> Co-authored-by: Github Actions <actions@github> Co-authored-by: Steven Arcangeli <stevearc@stevearc.com>
-rw-r--r--README.md1
-rw-r--r--doc/conform.txt1
-rw-r--r--lua/conform/formatters/format-queries.lua21
3 files changed, 23 insertions, 0 deletions
diff --git a/README.md b/README.md
index 230a9dd..908263a 100644
--- a/README.md
+++ b/README.md
@@ -225,6 +225,7 @@ You can view this list in vim with `:help conform-formatters`
- [fixjson](https://github.com/rhysd/fixjson) - JSON Fixer for Humans using (relaxed) JSON5.
- [fnlfmt](https://git.sr.ht/~technomancy/fnlfmt) - A formatter for Fennel code.
- [forge_fmt](https://github.com/foundry-rs/foundry) - Forge is a command-line tool that ships with Foundry. Forge tests, builds, and deploys your smart contracts.
+- [format-queries](https://github.com/nvim-treesitter/nvim-treesitter/blob/main/CONTRIBUTING.md#formatting) - Tree-sitter query formatter.
- [fourmolu](https://hackage.haskell.org/package/fourmolu) - A fork of ormolu that uses four space indentation and allows arbitrary configuration.
- [fprettify](https://github.com/fortran-lang/fprettify) - Auto-formatter for modern fortran source code.
- [gci](https://github.com/daixiang0/gci) - GCI, a tool that controls Go package import order and makes it always deterministic.
diff --git a/doc/conform.txt b/doc/conform.txt
index d1ef2b6..8c793fa 100644
--- a/doc/conform.txt
+++ b/doc/conform.txt
@@ -263,6 +263,7 @@ FORMATTERS *conform-formatter
`fnlfmt` - A formatter for Fennel code.
`forge_fmt` - Forge is a command-line tool that ships with Foundry. Forge tests,
builds, and deploys your smart contracts.
+`format-queries` - Tree-sitter query formatter.
`fourmolu` - A fork of ormolu that uses four space indentation and allows
arbitrary configuration.
`fprettify` - Auto-formatter for modern fortran source code.
diff --git a/lua/conform/formatters/format-queries.lua b/lua/conform/formatters/format-queries.lua
new file mode 100644
index 0000000..6f7da25
--- /dev/null
+++ b/lua/conform/formatters/format-queries.lua
@@ -0,0 +1,21 @@
+---@return nil|string
+local function get_format_script()
+ return vim.api.nvim_get_runtime_file("scripts/format-queries.lua", false)[1]
+end
+
+---@type conform.FileFormatterConfig
+return {
+ meta = {
+ url = "https://github.com/nvim-treesitter/nvim-treesitter/blob/main/CONTRIBUTING.md#formatting",
+ description = "Tree-sitter query formatter.",
+ },
+ condition = function()
+ local ok = pcall(vim.treesitter.language.inspect, "query")
+ return ok and get_format_script() ~= nil
+ end,
+ command = "nvim",
+ args = function()
+ return { "-l", get_format_script(), "$FILENAME" }
+ end,
+ stdin = false,
+}