From 934d91f744efd57639c375193b30dca11d500d51 Mon Sep 17 00:00:00 2001 From: Luckas Date: Thu, 1 Aug 2024 18:56:53 +0300 Subject: [PATCH] update: pattern handling & add rust tests --- lua/tailwind-tools/classes.lua | 14 +++++++------- lua/tailwind-tools/patterns.lua | 2 +- tests/queries/rust/leeptos.rs | 27 +++++++++++++++++++++++++++ tests/queries/rust_spec.lua | 9 +++++++++ 4 files changed, 44 insertions(+), 8 deletions(-) create mode 100644 tests/queries/rust/leeptos.rs create mode 100644 tests/queries/rust_spec.lua diff --git a/lua/tailwind-tools/classes.lua b/lua/tailwind-tools/classes.lua index d69dd82..48b40ff 100644 --- a/lua/tailwind-tools/classes.lua +++ b/lua/tailwind-tools/classes.lua @@ -17,16 +17,16 @@ M.get_ranges = function(bufnr) if not vim.tbl_contains(filetypes, ft) then return end - local class_ranges - local pattern = patterns.builtin_patterns[ft] or custom_patterns[ft] + local results = {} + local pattern_list = patterns.builtin_patterns[ft] or custom_patterns[ft] - if pattern then - class_ranges = patterns.find_class_ranges(bufnr, pattern) - else - class_ranges = tresitter.find_class_ranges(bufnr, ft) + for _, pattern in pairs(pattern_list or {}) do + vim.list_extend(results, patterns.find_class_ranges(bufnr, pattern)) end - return class_ranges + vim.list_extend(results, tresitter.find_class_ranges(bufnr, ft) or {}) + + return results end return M diff --git a/lua/tailwind-tools/patterns.lua b/lua/tailwind-tools/patterns.lua index 671a871..3fc2ea2 100644 --- a/lua/tailwind-tools/patterns.lua +++ b/lua/tailwind-tools/patterns.lua @@ -61,7 +61,7 @@ M.find_class_ranges = function(bufnr, pattern) end M.builtin_patterns = { - rust = "class=[\"']([^\"']+)[\"']", + rust = { "class=[\"']([^\"']+)[\"']" }, } 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 }, + }, +})