diff --git a/.luarc.json b/.luarc.json index f8ecc0f..7536f99 100644 --- a/.luarc.json +++ b/.luarc.json @@ -1,13 +1,10 @@ { - "diagnostics": { - "runtime": { - "version": "LuaJIT" - } - }, + "runtime.version": "LuaJIT", "workspace.library": [ "/usr/local/share/nvim/runtime/lua", "~/.local/share/nvim/lazy/nvim-cmp", "${3rd}/luv/library", - "${3rd}/luassert/library" + "${3rd}/luassert/library", + "${3rd}/busted/library" ] } diff --git a/README.md b/README.md index 9367634..9bfb9ea 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ # tailwind-tools.nvim -Unofficial [Tailwind CSS](https://github.com/tailwindlabs/tailwindcss) integration and tooling for [Neovim](https://github.com/neovim/neovim) using the built-in LSP client and treesitter, inspired by the official Visual Studio Code [extension](https://github.com/tailwindlabs/tailwindcss-intellisense). +Unofficial [Tailwind CSS](https://github.com/tailwindlabs/tailwindcss) integration and tooling for [Neovim](https://github.com/neovim/neovim) using the built-in LSP client and Treesitter, inspired by the official Visual Studio Code [extension](https://github.com/tailwindlabs/tailwindcss-intellisense). ![preview](https://github.com/luckasRanarison/tailwind-tools.nvim/assets/101930730/cb1c0508-8375-474f-9078-2842fb62e0b7) @@ -21,7 +21,9 @@ Unofficial [Tailwind CSS](https://github.com/tailwindlabs/tailwindcss) integrati ## Features -The plugin works with all languages inheriting from html, css and tsx treesitter grammars (php, astro, vue, svelte, [...](./lua/tailwind-tools/filetypes.lua)) and provides the following features: +The plugin works with all languages inheriting from html, css and tsx treesitter grammars (php, astro, vue, svelte, [...](./lua/tailwind-tools/filetypes.lua)). Lua patterns can also be used as a fallback. + +It currently provides the following features: - Class color hints - Class concealing @@ -36,7 +38,7 @@ The plugin works with all languages inheriting from html, css and tsx treesitter - Neovim v0.9 or higher (v0.10 is recommended) - [tailwindcss-language-server](https://github.com/tailwindlabs/tailwindcss-intellisense/tree/master/packages/tailwindcss-language-server) >= `v0.0.14` (can be installed using [Mason](https://github.com/williamboman/mason.nvim)) -- `html`, `css`, `tsx` and your other languages treesitter grammars (using [nvim-treesitter](https://github.com/nvim-treesitter/nvim-treesitter)) +- `html`, `css`, `tsx` and other language Treesitter grammars (using [nvim-treesitter](https://github.com/nvim-treesitter/nvim-treesitter)) > [!TIP] > If you are not familiar with neovim LSP ecosystem check out [nvim-lspconfig](https://github.com/neovim/nvim-lspconfig) to learn how to setup the LSP. @@ -86,7 +88,15 @@ Here is the default configuration: fg = "#38BDF8", }, }, - custom_filetypes = {} -- see the extension section to learn how it works + -- see the extension section to learn more + extension = { + queries = {}, -- a list of filetypes having custom `class` queries + patterns = { -- a map of filetypes to Lua pattern lists + -- exmaple: + -- rust = { "class=[\"']([^\"']+)[\"']" }, + -- javascript = { "clsx%(([^)]+)%)" }, + }, + }, } ``` @@ -136,11 +146,23 @@ return { ## Extension -The plugin basically works with any language as long it has a treesitter parser and a `class` query. You can check the currently available queries and supported filetypes [here](./queries), feel free to request other languages support. +The plugin already supports many languages, but requests for additional language support and PRs are welcome. You can also extend the language support in your configuration by using Treesitter queries or Lua patterns (or both). -But you can also create your own queries! If you are not familiar with treesitter queries you should check out the treesitter query documentation from [Neovim](https://neovim.io/doc/user/treesitter.html#treesitter-query) or [Treesitter](https://tree-sitter.github.io/tree-sitter/using-parsers#query-syntax). +### Treesitter queries -To add a new filetype you first need to add it to your configuration then the plugin will search for a `class.scm` file (classexpr) associated to that filetype in your `runtimepath`. You could use your Neovim configuration folder to store queries in the following way: +Treesitter queries are recommended but can be harder to write, if you are not familiar with Treesitter queries, check out the documentation from [Neovim](https://neovim.io/doc/user/treesitter.html#treesitter-query) or [Treesitter](https://tree-sitter.github.io/tree-sitter/using-parsers#query-syntax). + +You can define custom queries for a filetype by adding the filetype to the `queries` list, like this: + +```lua +{ + extension = { + queries = { "myfiletype" }, + } +} +``` + +The plugin will search for a `class.scm` file (classexpr) associated with that filetype in your `runtimepath`. You can use your Neovim configuration folder to store queries in the following way: ``` ~/.config/nvim @@ -153,7 +175,7 @@ To add a new filetype you first need to add it to your configuration then the pl       └── class.scm ``` -The `class.scm` file should contain a query used to extract the class values for a given filetype. The class value should be captured using `@tailwind` as shown in the follwing example: +The `class.scm` file should contain a query used to extract the class values for a given filetype. The class value should be captured using `@tailwind`, as shown in the follwing example: ```scheme ; queries/myfiletype/class.scm @@ -167,6 +189,25 @@ The `class.scm` file should contain a query used to extract the class values for > [!NOTE] > Some class ranges cannot be precisely captured using queries alone and are handled in code. You can also check out the existing [queries](./queries) to see more examples. +### Lua patterns + +[Lua patterns](https://www.lua.org/pil/20.2.html) are easier to write, but note that the underlying implementation is not completely efficient, although this inefficiency is likely negligible. Currently, there are no reliable APIs for performing pattern searches and retrieving information about capture positions. + +You can define custom patterns by attaching a list of patterns to filetypes. Each pattern should have exactly **one** capture group representing the class value, as shown below: + +```lua +{ + extension = { + patterns = { + javascript = { "clsx%(([^)]+)%)" }, + }, + } +} +``` + +> [!TIP] +> Lua patterns can be combined with Treesitter queries. You can use both for a single filetype to get the combined results. + ## Related projects Here are some related projects: diff --git a/lua/tailwind-tools/classes.lua b/lua/tailwind-tools/classes.lua new file mode 100644 index 0000000..c6229e6 --- /dev/null +++ b/lua/tailwind-tools/classes.lua @@ -0,0 +1,28 @@ +local M = {} + +local patterns = require("tailwind-tools.patterns") +local filetypes = require("tailwind-tools.filetypes") +local tresitter = require("tailwind-tools.treesitter") +local config = require("tailwind-tools.config") + +---@param bufnr number +---@return number[][] +M.get_ranges = function(bufnr) + local results = {} + local ft = vim.bo[bufnr].ft + local extension = config.options.extension + local query_list = vim.tbl_extend("force", filetypes.treesitter, extension.queries) + local pattern_list = vim.tbl_extend("force", filetypes.luapattern, extension.patterns) + + for _, pattern in pairs(pattern_list[ft] or {}) do + vim.list_extend(results, patterns.find_class_ranges(bufnr, pattern)) + end + + if vim.tbl_contains(query_list, ft) then + vim.list_extend(results, tresitter.find_class_ranges(bufnr, ft) or {}) + end + + return results +end + +return M diff --git a/lua/tailwind-tools/conceal.lua b/lua/tailwind-tools/conceal.lua index ad69a5a..bba0484 100644 --- a/lua/tailwind-tools/conceal.lua +++ b/lua/tailwind-tools/conceal.lua @@ -3,13 +3,13 @@ local M = {} local lsp = require("tailwind-tools.lsp") local state = require("tailwind-tools.state") local config = require("tailwind-tools.config") -local treesitter = require("tailwind-tools.treesitter") +local classes = require("tailwind-tools.classes") ---@param bufnr number local function set_conceal(bufnr) - local class_nodes = treesitter.get_class_nodes(bufnr) + local class_ranges = classes.get_ranges(bufnr) - if not class_nodes then return end + if #class_ranges == 0 then return end vim.wo.conceallevel = 2 vim.api.nvim_buf_clear_namespace(bufnr, vim.g.tailwind_tools.conceal_ns, 0, -1) @@ -18,10 +18,10 @@ local function set_conceal(bufnr) local opts = config.options.conceal - for _, node in pairs(class_nodes) do - local start_row, start_col, end_row, end_col = treesitter.get_class_range(node, bufnr) + for _, range in pairs(class_ranges) do + local start_row, start_col, end_row, end_col = unpack(range) - if not opts.min_length or node:byte_length() >= opts.min_length then + if not opts.min_length or end_row ~= start_row or end_col - start_col >= opts.min_length then vim.api.nvim_buf_set_extmark(bufnr, vim.g.tailwind_tools.conceal_ns, start_row, start_col, { end_line = end_row, end_col = end_col, diff --git a/lua/tailwind-tools/config.lua b/lua/tailwind-tools/config.lua index 0b594e4..2898e76 100644 --- a/lua/tailwind-tools/config.lua +++ b/lua/tailwind-tools/config.lua @@ -19,7 +19,10 @@ M.options = { fg = "#38BDF8", }, }, - custom_filetypes = {}, + extension = { + queries = {}, + patterns = {}, + }, } return M diff --git a/lua/tailwind-tools/filetypes.lua b/lua/tailwind-tools/filetypes.lua index 86af8ac..5b476e6 100644 --- a/lua/tailwind-tools/filetypes.lua +++ b/lua/tailwind-tools/filetypes.lua @@ -1,14 +1,19 @@ return { - "html", - "css", - "php", - "twig", - "vue", - "svelte", - "astro", - "heex", - "elixir", - "htmldjango", - "javascriptreact", - "typescriptreact", + treesitter = { + "html", + "css", + "php", + "twig", + "vue", + "svelte", + "astro", + "heex", + "elixir", + "htmldjango", + "javascriptreact", + "typescriptreact", + }, + luapattern = { + rust = { "class=[\"']([^\"']+)[\"']" }, + }, } diff --git a/lua/tailwind-tools/lsp.lua b/lua/tailwind-tools/lsp.lua index ab21545..8223e1a 100644 --- a/lua/tailwind-tools/lsp.lua +++ b/lua/tailwind-tools/lsp.lua @@ -4,7 +4,7 @@ local log = require("tailwind-tools.log") local utils = require("tailwind-tools.utils") local state = require("tailwind-tools.state") local config = require("tailwind-tools.config") -local treesitter = require("tailwind-tools.treesitter") +local classes = require("tailwind-tools.classes") local color_events = { "BufEnter", @@ -176,22 +176,21 @@ M.sort_classes = function() local bufnr = vim.api.nvim_get_current_buf() local params = vim.lsp.util.make_text_document_params(bufnr) - local class_nodes = treesitter.get_class_nodes(bufnr, true) + local class_ranges = classes.get_ranges(bufnr) - if not class_nodes then return end + if #class_ranges == 0 then return end local class_text = {} - local class_ranges = {} - for _, node in pairs(class_nodes) do - local start_row, start_col, end_row, end_col = treesitter.get_class_range(node, bufnr) + for _, range in pairs(class_ranges) do + local start_row, start_col, end_row, end_col = unpack(range) local text = vim.api.nvim_buf_get_text(bufnr, start_row, start_col, end_row, end_col, {}) class_text[#class_text + 1] = table.concat(text, "\n") - class_ranges[#class_ranges + 1] = { start_row, start_col, end_row, end_col } end params.classLists = class_text + client.request("@/tailwindCSS/sortSelection", params, function(err, result, _, _) if err then return log.error(err.message) end if result.error then return log.error(result.error) end diff --git a/lua/tailwind-tools/motions.lua b/lua/tailwind-tools/motions.lua index 9d870f2..954cb60 100644 --- a/lua/tailwind-tools/motions.lua +++ b/lua/tailwind-tools/motions.lua @@ -1,25 +1,25 @@ local M = {} local log = require("tailwind-tools.log") -local treesitter = require("tailwind-tools.treesitter") +local classes = require("tailwind-tools.classes") ---@param comp fun(a: number, b: number): boolean local move_to_class = function(comp) - local nodes = treesitter.get_class_nodes(0, true) + local bufnr = vim.api.nvim_get_current_buf() + local class_ranges = classes.get_ranges(bufnr) - if not nodes then return end - if #nodes == 0 then return log.info("No classes") end + if #class_ranges == 0 then return log.info("No classes") end local cursor_row, cursor_col = unpack(vim.api.nvim_win_get_cursor(0)) - table.sort(nodes, function(a, b) - local a_row, a_col = treesitter.get_class_range(a, 0) - local b_row, b_col = treesitter.get_class_range(b, 0) + table.sort(class_ranges, function(a, b) + local a_row, a_col = unpack(a) + local b_row, b_col = unpack(b) return a_row == b_row and comp(b_col, a_col) or comp(b_row, a_row) end) - for _, node in ipairs(nodes) do - local node_row, node_col = treesitter.get_class_range(node, 0) + for _, range in ipairs(class_ranges) do + local node_row, node_col = unpack(range) local row = cursor_row - 1 if comp(node_row, row) or (node_row == row and comp(node_col, cursor_col)) then diff --git a/lua/tailwind-tools/patterns.lua b/lua/tailwind-tools/patterns.lua new file mode 100644 index 0000000..4b05d95 --- /dev/null +++ b/lua/tailwind-tools/patterns.lua @@ -0,0 +1,63 @@ +local M = {} + +---@param b_start number +---@param b_end number +---@param bufnr number +local function byte_range_to_pos(b_start, b_end, bufnr) + local line_count = vim.api.nvim_buf_line_count(bufnr) + local line_offsets = {} + + for i = 1, line_count do + line_offsets[i] = vim.api.nvim_buf_get_offset(bufnr, i - 1) + end + + local start_row, start_col, end_row, end_col + + for line, offset in pairs(line_offsets) do + local next_offset = line_offsets[line + 1] + + if not next_offset or b_start >= offset and b_start < next_offset then + start_row = line - 1 + start_col = b_start - offset + end + + if not next_offset or b_end >= offset and b_end < next_offset then + end_row = line - 1 + end_col = b_end - offset + break + end + end + + return start_row, start_col, end_row, end_col +end + +---@param bufnr number +---@param pattern string +M.find_class_ranges = function(bufnr, pattern) + local results = {} + local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, true) + local substr = table.concat(lines, "\n") + local offset = 0 + + while true do + local b_start, b_end, class = substr:find(pattern) + + if b_start == nil then break end + + substr = substr:sub(b_start) + offset = offset + b_start - 1 + + local match_len = b_end - b_start + local class_start = substr:find(class, 1, true) + offset - 1 + local class_end = class_start + #class + local sr, sc, er, ec = byte_range_to_pos(class_start, class_end, bufnr) + + results[#results + 1] = { sr, sc, er, ec } + substr = substr:sub(match_len) + offset = offset + match_len - 1 + end + + return results +end + +return M diff --git a/lua/tailwind-tools/treesitter.lua b/lua/tailwind-tools/treesitter.lua index 0183de7..ccf38d9 100644 --- a/lua/tailwind-tools/treesitter.lua +++ b/lua/tailwind-tools/treesitter.lua @@ -1,22 +1,15 @@ local M = {} local log = require("tailwind-tools.log") -local config = require("tailwind-tools.config") -local filetypes = require("tailwind-tools.filetypes") ---@param bufnr number ----@param all boolean? -M.get_class_nodes = function(bufnr, all) - local ft = vim.bo[bufnr].ft - local supported_filetypes = vim.tbl_extend("keep", filetypes, config.options.custom_filetypes) - - if not vim.tbl_contains(supported_filetypes, ft) then return end - +---@param ft string +local function find_class_nodes(bufnr, ft) local results = {} local parser = vim.treesitter.get_parser(bufnr) - if not parser then return log.warn("No parser available for " .. ft) end - if all and vim.version().minor >= 10 then parser:parse(true) end + if not parser then return log.error("No parser available for " .. ft) end + if vim.version().minor >= 10 then parser:parse(true) end parser:for_each_tree(function(tree, lang_tree) local root = tree:root() @@ -36,7 +29,7 @@ end ---@param node TSNode ---@param bufnr number -M.get_class_range = function(node, bufnr) +local function get_class_range(node, bufnr) local start_row, start_col, end_row, end_col = node:range() local children = node:named_children() @@ -49,4 +42,21 @@ M.get_class_range = function(node, bufnr) return start_row, start_col, end_row, end_col end +---@param bufnr number +---@param ft string +M.find_class_ranges = function(bufnr, ft) + local nodes = find_class_nodes(bufnr, ft) + + if not nodes then return end + + local results = {} + + for _, node in pairs(nodes) do + local sr, sc, er, ec = get_class_range(node, bufnr) + results[#results + 1] = { sr, sc, er, ec } + end + + return results +end + return M diff --git a/tests/queries/astro_spec.lua b/tests/queries/astro_spec.lua index 7e25468..e089da4 100644 --- a/tests/queries/astro_spec.lua +++ b/tests/queries/astro_spec.lua @@ -1,12 +1,11 @@ -local common = require("tests.queries.common") -local runner = common.Runner:new("tests/queries/astro/index.astro") - -describe("queries astro:", function() - runner:classes(4) - runner:ranges({ +require("tests.queries.runner").test({ + name = "astro", + provider = "treesitter", + file = "tests/queries/astro/index.astro", + ranges = { { 4, 17, 4, 42 }, { 6, 12, 6, 26 }, { 7, 14, 7, 41 }, { 9, 33, 9, 43 }, - }) -end) + }, +}) diff --git a/tests/queries/common.lua b/tests/queries/common.lua deleted file mode 100644 index bd21c93..0000000 --- a/tests/queries/common.lua +++ /dev/null @@ -1,41 +0,0 @@ -local assert = require("luassert") -local treesitter = require("tailwind-tools.treesitter") - -local M = {} - -local Runner = {} - -Runner.__index = Runner - ----@param file_path string ----@param filetype string? -function Runner:new(file_path, filetype) - assert.same(1, vim.fn.filereadable(file_path), file_path .. " is not readable") - vim.cmd.edit(file_path) - if filetype then vim.bo.filetype = filetype end - return setmetatable({ nodes = {} }, self) -end - -function Runner:classes(expected) - it("Should get classes", function() - self.nodes = assert(treesitter.get_class_nodes(0, true), "Expected nodes") - assert.same(expected, #self.nodes, "Mismatched node count") - end) -end - -function Runner:ranges(expected) - it("Should get ranges", function() - for i, node in pairs(self.nodes) do - local start_row, start_col, end_row, end_col = treesitter.get_class_range(node, 0) - - assert.same(expected[i][1], start_row, "Mismatched start row for node " .. i) - assert.same(expected[i][2], start_col, "Mismatched start column for node " .. i) - assert.same(expected[i][3], end_row, "Mismatched end row for node " .. i) - assert.same(expected[i][4], end_col, "Mismatched end column for node " .. i) - end - end) -end - -M.Runner = Runner - -return M diff --git a/tests/queries/css_spec.lua b/tests/queries/css_spec.lua index e9955a5..035eeaa 100644 --- a/tests/queries/css_spec.lua +++ b/tests/queries/css_spec.lua @@ -1,10 +1,9 @@ -local common = require("tests.queries.common") -local runner = common.Runner:new("tests/queries/css/style.css") - -describe("queries css:", function() - runner:classes(2) - runner:ranges({ +require("tests.queries.runner").test({ + name = "css", + provider = "treesitter", + file = "tests/queries/css/style.css", + ranges = { { 5, 9, 5, 34 }, { 9, 9, 10, 37 }, - }) -end) + }, +}) diff --git a/tests/queries/heex_spec.lua b/tests/queries/heex_spec.lua index 0bbd26f..522a570 100644 --- a/tests/queries/heex_spec.lua +++ b/tests/queries/heex_spec.lua @@ -1,11 +1,10 @@ -local common = require("tests.queries.common") -local runner = common.Runner:new("tests/queries/heex/index.html.heex") - -describe("queries heex:", function() - runner:classes(3) - runner:ranges({ +require("tests.queries.runner").test({ + name = "heex", + provider = "treesitter", + file = "tests/queries/heex/index.html.heex", + ranges = { { 0, 12, 0, 27 }, { 1, 13, 1, 20 }, { 2, 12, 5, 4 }, - }) -end) + }, +}) diff --git a/tests/queries/html_spec.lua b/tests/queries/html_spec.lua index 3fcfdf4..88381d5 100644 --- a/tests/queries/html_spec.lua +++ b/tests/queries/html_spec.lua @@ -1,10 +1,9 @@ -local common = require("tests.queries.common") -local runner = common.Runner:new("tests/queries/html/index.html") - -describe("queries html:", function() - runner:classes(2) - runner:ranges({ +require("tests.queries.runner").test({ + name = "html", + provider = "treesitter", + file = "tests/queries/html/index.html", + ranges = { { 10, 14, 10, 47 }, { 11, 16, 11, 39 }, - }) -end) + }, +}) diff --git a/tests/queries/htmldjango_spec.lua b/tests/queries/htmldjango_spec.lua index ee967f3..c255b65 100644 --- a/tests/queries/htmldjango_spec.lua +++ b/tests/queries/htmldjango_spec.lua @@ -1,10 +1,10 @@ -local common = require("tests.queries.common") -local runner = common.Runner:new("tests/queries/html/index.html", "htmldjango") - -describe("queries htmldjango:", function() - runner:classes(2) - runner:ranges({ +require("tests.queries.runner").test({ + name = "html", + provider = "treesitter", + file = "tests/queries/html/index.html", + filetype = "htmldjango", + ranges = { { 10, 14, 10, 47 }, { 11, 16, 11, 39 }, - }) -end) + }, +}) diff --git a/tests/queries/php_spec.lua b/tests/queries/php_spec.lua index 4ae8364..3c9de37 100644 --- a/tests/queries/php_spec.lua +++ b/tests/queries/php_spec.lua @@ -1,10 +1,9 @@ -local common = require("tests.queries.common") -local runner = common.Runner:new("tests/queries/php/index.php") - -describe("queries php:", function() - runner:classes(2) - runner:ranges({ +require("tests.queries.runner").test({ + name = "php", + provider = "treesitter", + file = "tests/queries/php/index.php", + ranges = { { 10, 14, 10, 47 }, { 11, 16, 11, 39 }, - }) -end) + }, +}) diff --git a/tests/queries/runner.lua b/tests/queries/runner.lua new file mode 100644 index 0000000..16b1917 --- /dev/null +++ b/tests/queries/runner.lua @@ -0,0 +1,36 @@ +local M = {} + +local assert = require("luassert") +local classes = require("tailwind-tools.classes") + +---@class TestSpec +---@field name string +---@field provider "treesitter" | "luapattern" +---@field file string +---@field filetype? string +---@field ranges number[][] + +---@param spec TestSpec +M.test = function(spec) + describe(string.format("query %s (%s):", spec.name, spec.provider), function() + assert.same(1, vim.fn.filereadable(spec.file), spec.file .. " is not readable") + + vim.cmd.edit(spec.file) + vim.bo.filetype = spec.filetype or vim.bo.filetype + + local ranges = classes.get_ranges(0) + + it( + "Should get class count", + function() assert.same(#ranges, #spec.ranges, "Mismatched class count") end + ) + + it("Should get ranges", function() + for i, range in pairs(ranges) do + assert.same(range, spec.ranges[i], "Mismatched range (index = " .. i .. ")") + end + end) + end) +end + +return M diff --git a/tests/queries/rust/leeptos.rs b/tests/queries/rust/leeptos.rs new file mode 100644 index 0000000..1fdcb5c --- /dev/null +++ b/tests/queries/rust/leeptos.rs @@ -0,0 +1,27 @@ +use leptos::*; +use leptos_meta::*; + +#[component] +fn App(cx: Scope) -> impl IntoView { + let (count, set_count) = create_signal(cx, 0); + provide_meta_context(cx); + + view! { cx, + +
+ +
+ } +} + +fn main() { + leptos::mount_to_body(|cx| view! { cx, }) +} diff --git a/tests/queries/rust_spec.lua b/tests/queries/rust_spec.lua new file mode 100644 index 0000000..5ece68a --- /dev/null +++ b/tests/queries/rust_spec.lua @@ -0,0 +1,9 @@ +require("tests.queries.runner").test({ + name = "rust", + provider = "luapattern", + file = "tests/queries/rust/leeptos.rs", + ranges = { + { 10, 20, 10, 29 }, + { 12, 23, 12, 65 }, + }, +}) diff --git a/tests/queries/svelte_spec.lua b/tests/queries/svelte_spec.lua index e9bacf9..7d41db4 100644 --- a/tests/queries/svelte_spec.lua +++ b/tests/queries/svelte_spec.lua @@ -1,11 +1,10 @@ -local common = require("tests.queries.common") -local runner = common.Runner:new("tests/queries/svelte/test.svelte") - -describe("queries svelte:", function() - runner:classes(3) - runner:ranges({ +require("tests.queries.runner").test({ + name = "svelte", + provider = "treesitter", + file = "tests/queries/svelte/test.svelte", + ranges = { { 4, 12, 4, 26 }, { 5, 14, 5, 41 }, { 8, 17, 8, 27 }, - }) -end) + }, +}) diff --git a/tests/queries/tsx_spec.lua b/tests/queries/tsx_spec.lua index 39d2104..423c242 100644 --- a/tests/queries/tsx_spec.lua +++ b/tests/queries/tsx_spec.lua @@ -1,11 +1,10 @@ -local common = require("tests.queries.common") -local runner = common.Runner:new("tests/queries/tsx/Component.tsx") - -describe("queries tsx:", function() - runner:classes(3) - runner:ranges({ +require("tests.queries.runner").test({ + name = "tsx", + provider = "treesitter", + file = "tests/queries/tsx/Component.tsx", + ranges = { { 6, 19, 7, 55 }, { 9, 24, 9, 47 }, { 13, 33, 13, 45 }, - }) -end) + }, +}) diff --git a/tests/queries/twig_spec.lua b/tests/queries/twig_spec.lua index 598ab20..a4c21d8 100644 --- a/tests/queries/twig_spec.lua +++ b/tests/queries/twig_spec.lua @@ -1,11 +1,10 @@ -local common = require("tests.queries.common") -local runner = common.Runner:new("tests/queries/twig/test.twig") - -describe("queries twig:", function() - runner:classes(3) - runner:ranges({ +require("tests.queries.runner").test({ + name = "twig", + provider = "treesitter", + file = "tests/queries/twig/test.twig", + ranges = { { 0, 12, 0, 26 }, { 1, 14, 1, 41 }, { 4, 17, 4, 27 }, - }) -end) + }, +}) diff --git a/tests/queries/vue_spec.lua b/tests/queries/vue_spec.lua index d66e6fc..d3ea426 100644 --- a/tests/queries/vue_spec.lua +++ b/tests/queries/vue_spec.lua @@ -1,11 +1,12 @@ -local common = require("tests.queries.common") -local runner = common.Runner:new("tests/queries/vue/test.vue") - -describe("queries vue:", function() - runner:classes(3) - runner:ranges({ +local spec = { + name = "vue", + provider = "treesitter", + file = "tests/queries/vue/test.vue", + ranges = { { 1, 14, 1, 28 }, { 2, 16, 2, 43 }, { 4, 39, 4, 49 }, - }) -end) + }, +} + +require("tests.queries.runner").test(spec)