Skip to content

Commit

Permalink
update: pattern handling & add rust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
luckasRanarison committed Aug 1, 2024
1 parent 5bb7b8b commit 934d91f
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 8 deletions.
14 changes: 7 additions & 7 deletions lua/tailwind-tools/classes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion lua/tailwind-tools/patterns.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ M.find_class_ranges = function(bufnr, pattern)
end

M.builtin_patterns = {
rust = "class=[\"']([^\"']+)[\"']",
rust = { "class=[\"']([^\"']+)[\"']" },
}

return M
27 changes: 27 additions & 0 deletions tests/queries/rust/leeptos.rs
Original file line number Diff line number Diff line change
@@ -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,
<Stylesheet id="leptos" href="/pkg/tailwind.css"/>
<div class="container">
<button
class="p-1 bg-sky-500 hover:bg-sky-700 text-white"
class:rounded-lg=move || count() % 2 == 1
on:click=move |_| {
set_count.update(|n| *n += 1);
}
>
"Click me: " {move || count()}
</button>
</div>
}
}

fn main() {
leptos::mount_to_body(|cx| view! { cx, <App/> })
}
9 changes: 9 additions & 0 deletions tests/queries/rust_spec.lua
Original file line number Diff line number Diff line change
@@ -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 },
},
})

0 comments on commit 934d91f

Please sign in to comment.