Skip to content

Commit c91fa46

Browse files
feat: use builtin extends query in vim.treesitter.query.set for injections
## Details With the neovim 0.11.0 release the vim.treesitter.query.set API was updated to support the `extends` and `inherits` keywords much like writing query files support but programmatically at runtime. We can take advantage of this to simplify the logic of updating `injections`, like we do for the `gitcommit` filetype if configured. Rather than needing to loop through all the files append them to a string, then add our injection, we can simply pre-pend the query with the `;; extends` keyword and call set, no looping & appending needed. Gate this new logic to only run if the user is on `0.11.0`, keep the old logic around for the time being, eventually deprecate the previous approach when we bump the minimum requirement for this plugin
1 parent 35119c1 commit c91fa46

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

lua/render-markdown/core/treesitter.lua

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
local Env = require('render-markdown.lib.env')
2+
13
---@type table<string, vim.treesitter.Query>
24
local queries = {}
35

@@ -24,12 +26,16 @@ function M.inject(language, injection)
2426
end
2527

2628
local query = ''
27-
local files = vim.treesitter.query.get_files(language, 'injections')
28-
for _, file in ipairs(files) do
29-
local f = io.open(file, 'r')
30-
if f ~= nil then
31-
query = query .. f:read('*all') .. '\n'
32-
f:close()
29+
if Env.has_11 then
30+
query = query .. ';; extends' .. '\n'
31+
else
32+
local files = vim.treesitter.query.get_files(language, 'injections')
33+
for _, file in ipairs(files) do
34+
local f = io.open(file, 'r')
35+
if f ~= nil then
36+
query = query .. f:read('*all') .. '\n'
37+
f:close()
38+
end
3339
end
3440
end
3541
query = query .. injection.query

lua/render-markdown/health.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ local state = require('render-markdown.state')
55
local M = {}
66

77
---@private
8-
M.version = '8.1.17'
8+
M.version = '8.1.18'
99

1010
function M.check()
1111
M.start('version')

0 commit comments

Comments
 (0)