Skip to content

Commit

Permalink
update query directive in readme
Browse files Browse the repository at this point in the history
  • Loading branch information
hankthetank27 committed Sep 4, 2024
1 parent 4c19cc5 commit 23ac814
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,20 @@ tree-sitter-liquid is included in [nvim-treesitter](https://github.com/nvim-tree

-- custom query predicate for allowing injections based on file extension
require"vim.treesitter.query".add_directive("set-lang-by-filetype!", function (_, _, bufnr, pred, metadata)
local function find_nth_dot_from_end(str, n)
for i = #str, 1, -1 do
if str:sub(i, i) == "." then
n = n - 1
if n <= 0 then
return i
end
end
end
return nil
end
local filename = vim.fn.expand("#"..bufnr..":t")
local extension_index = filename:find("%.")
local dots_in_extension = select(2, string.gsub(pred[2], "%.", "")) + 1
local extension_index = find_nth_dot_from_end(filename, dots_in_extension)
if not extension_index then
return
end
Expand Down

0 comments on commit 23ac814

Please sign in to comment.