-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Breaking change: `custom_filetypes` has been removed and replaced by the `extension` field. * wip: lua pattern support * fix: pattern search & lsp request * fix: tests * update: pattern handling & add rust tests * refactor: iniline spec * fix: class query logic * update!: config options * fix(workflow): precise branches Prevent double action triggers. * update: README.md
- Loading branch information
1 parent
05c1f15
commit da8eee8
Showing
24 changed files
with
352 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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=[\"']([^\"']+)[\"']" }, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Oops, something went wrong.