Skip to content

Commit 582a65b

Browse files
committed
fix: replace get_node_text
1 parent 6696621 commit 582a65b

File tree

5 files changed

+28
-28
lines changed

5 files changed

+28
-28
lines changed

lua/orgmode/org/indent.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ local get_matches = ts_utils.memoize_by_buf_tick(function(bufnr)
2525
}
2626

2727
if type == 'headline' then
28-
opts.stars = vim.treesitter.query.get_node_text(node:field('stars')[1], bufnr):len()
28+
opts.stars = vim.treesitter.get_node_text(node:field('stars')[1], bufnr):len()
2929
opts.indent = opts.indent + opts.stars + 1
3030
matches[range.start.line + 1] = opts
3131
end
@@ -52,7 +52,7 @@ local get_matches = ts_utils.memoize_by_buf_tick(function(bufnr)
5252
end
5353
if parent then
5454
local headline = parent:named_child('headline')
55-
local stars = vim.treesitter.query.get_node_text(headline:field('stars')[1], bufnr):len()
55+
local stars = vim.treesitter.get_node_text(headline:field('stars')[1], bufnr):len()
5656
opts.indent = stars + 1
5757
for i = range.start.line, range['end'].line - 1 do
5858
matches[i + 1] = opts

lua/orgmode/org/mappings.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ function OrgMappings:handle_return(suffix)
599599
local counter = 1
600600
while next_sibling do
601601
local bullet = next_sibling:child(0)
602-
local text = vim.treesitter.query.get_node_text(bullet, 0)
602+
local text = vim.treesitter.get_node_text(bullet, 0)
603603
local new_text = tostring(tonumber(text:match('%d+')) + 1) .. closer
604604

605605
if counter == 1 then

lua/orgmode/treesitter/headline.lua

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ local tree_utils = require('orgmode.utils.treesitter')
44
local Date = require('orgmode.objects.date')
55
local Range = require('orgmode.parser.range')
66
local config = require('orgmode.config')
7-
local query = vim.treesitter.query
7+
local ts = vim.treesitter
88

99
---@class Headline
1010
---@field headline userdata
@@ -46,7 +46,7 @@ end
4646
---@return number
4747
function Headline:level()
4848
local stars = self:stars()
49-
return query.get_node_text(stars, 0):len()
49+
return ts.get_node_text(stars, 0):len()
5050
end
5151

5252
function Headline:priority()
@@ -94,7 +94,7 @@ end
9494

9595
function Headline:_handle_promote_demote(recursive, modifier)
9696
local whole_subtree = function()
97-
local text = query.get_node_text(self.headline:parent(), 0)
97+
local text = ts.get_node_text(self.headline:parent(), 0)
9898
local lines = modifier(vim.split(text, '\n', true))
9999
tree_utils.set_node_lines(self.headline:parent(), lines)
100100
return self:refresh()
@@ -128,7 +128,7 @@ function Headline:tags()
128128
local node = self.headline:field('tags')[1]
129129
local text = ''
130130
if node then
131-
text = query.get_node_text(node, 0)
131+
text = ts.get_node_text(node, 0)
132132
end
133133
return node, text
134134
end
@@ -142,7 +142,7 @@ function Headline:set_tags(tags)
142142
end
143143
end
144144

145-
local txt = query.get_node_text(predecessor, 0)
145+
local txt = ts.get_node_text(predecessor, 0)
146146
local pred_end_row, pred_end_col, _ = predecessor:end_()
147147
local line = vim.fn.getline(pred_end_row + 1)
148148
local stars = line:match('^%*+%s*')
@@ -190,13 +190,13 @@ function Headline:set_priority(priority)
190190

191191
local todo = self:todo()
192192
if todo then
193-
local text = query.get_node_text(todo, 0)
193+
local text = ts.get_node_text(todo, 0)
194194
tree_utils.set_node_text(todo, ('%s [#%s]'):format(text, priority))
195195
return
196196
end
197197

198198
local stars = self:stars()
199-
local text = query.get_node_text(stars, 0)
199+
local text = ts.get_node_text(stars, 0)
200200
tree_utils.set_node_text(stars, ('%s [#%s]'):format(text, priority))
201201
end
202202

@@ -209,7 +209,7 @@ function Headline:set_todo(keyword)
209209
end
210210

211211
local stars = self:stars()
212-
local text = query.get_node_text(stars, 0)
212+
local text = ts.get_node_text(stars, 0)
213213
tree_utils.set_node_text(stars, string.format('%s %s', text, keyword))
214214
end
215215

@@ -231,7 +231,7 @@ function Headline:todo()
231231
return nil
232232
end
233233

234-
local text = query.get_node_text(todo_node, 0)
234+
local text = ts.get_node_text(todo_node, 0)
235235
for _, word in ipairs(keywords) do
236236
-- there may be multiple substitutions necessary
237237
local escaped_word = vim.pesc(word)
@@ -272,7 +272,7 @@ function Headline:is_done()
272272
end
273273

274274
function Headline:title()
275-
local title = query.get_node_text(self:item(), 0) or ''
275+
local title = ts.get_node_text(self:item(), 0) or ''
276276
local todo, word = self:todo()
277277
if todo then
278278
title = title:gsub('^' .. vim.pesc(word) .. '%s*', '')
@@ -334,11 +334,11 @@ function Headline:get_property(property_name)
334334
for _, node in ipairs(ts_utils.get_named_children(properties)) do
335335
local name = node:field('name')[1]
336336
local value = node:field('value')[1]
337-
if name and query.get_node_text(name, 0):lower() == property_name:lower() then
337+
if name and ts.get_node_text(name, 0):lower() == property_name:lower() then
338338
return {
339339
node = node,
340340
name = name,
341-
value = value and query.get_node_text(value, 0),
341+
value = value and ts.get_node_text(value, 0),
342342
}
343343
end
344344
end
@@ -369,7 +369,7 @@ function Headline:dates()
369369
end
370370

371371
for _, node in ipairs(ts_utils.get_named_children(plan)) do
372-
local name = query.get_node_text(node:named_child(0), 0)
372+
local name = ts.get_node_text(node:named_child(0), 0)
373373
dates[name] = node
374374
end
375375
return dates
@@ -445,7 +445,7 @@ function Headline:update_cookie(list_node)
445445
local cookie = self:cookie()
446446
if cookie then
447447
local new_cookie_val
448-
if query.get_node_text(cookie, 0):find('%%') then
448+
if ts.get_node_text(cookie, 0):find('%%') then
449449
new_cookie_val = ('[%d%%]'):format((#checked_boxes / #total_boxes) * 100)
450450
else
451451
new_cookie_val = ('[%d/%d]'):format(#checked_boxes, #total_boxes)
@@ -456,7 +456,7 @@ end
456456

457457
function Headline:child_checkboxes(list_node)
458458
return vim.tbl_map(function(node)
459-
local text = query.get_node_text(node, 0)
459+
local text = ts.get_node_text(node, 0)
460460
return text:match('%[.%]')
461461
end, ts_utils.get_named_children(list_node))
462462
end
@@ -465,7 +465,7 @@ end
465465
function Headline:parse(pattern)
466466
local match = ''
467467
local matching_nodes = vim.tbl_filter(function(node)
468-
local text = query.get_node_text(node, 0) or ''
468+
local text = ts.get_node_text(node, 0) or ''
469469
local m = text:match(pattern)
470470
if m then
471471
match = text:match(pattern)
@@ -487,7 +487,7 @@ function Headline:_get_date(type)
487487
if not timestamp_node then
488488
return nil
489489
end
490-
local parsed_date = Date.from_org_date(query.get_node_text(timestamp_node, 0), {
490+
local parsed_date = Date.from_org_date(ts.get_node_text(timestamp_node, 0), {
491491
range = Range.from_node(timestamp_node),
492492
})
493493
return parsed_date and parsed_date[1] or nil
@@ -522,7 +522,7 @@ function Headline:_add_date(type, date, active)
522522
break
523523
end
524524
end
525-
local ptext = query.get_node_text(last_child, 0)
525+
local ptext = ts.get_node_text(last_child, 0)
526526
tree_utils.set_node_text(last_child, ptext .. ' ' .. text)
527527
return self:refresh()
528528
end

lua/orgmode/treesitter/listitem.lua

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
local ts_utils = require('nvim-treesitter.ts_utils')
22
local tree_utils = require('orgmode.utils.treesitter')
3-
local query = vim.treesitter.query
3+
local ts = vim.treesitter
44
local Headline = require('orgmode.treesitter.headline')
55

66
---@class Listitem
@@ -36,7 +36,7 @@ function Listitem:checkbox()
3636
if not checkbox then
3737
return nil
3838
end
39-
local text = query.get_node_text(checkbox, 0)
39+
local text = ts.get_node_text(checkbox, 0)
4040
return { text = text, range = { checkbox:range() } }
4141
end
4242

@@ -79,7 +79,7 @@ function Listitem:child_checkboxes()
7979
for _, content in ipairs(contents) do
8080
if content:type() == 'list' then
8181
return vim.tbl_map(function(node)
82-
local text = query.get_node_text(node, 0)
82+
local text = ts.get_node_text(node, 0)
8383
return text:match('%[.%]')
8484
end, ts_utils.get_named_children(content))
8585
end
@@ -94,7 +94,7 @@ function Listitem:cookie()
9494
return nil
9595
end
9696

97-
local text = query.get_node_text(cookie_node, 0)
97+
local text = ts.get_node_text(cookie_node, 0)
9898
if text:match('%[%d*/%d*%]') or text:match('%[%d?%d?%d?%%%]') then
9999
return cookie_node
100100
end
@@ -104,7 +104,7 @@ function Listitem:update_cookie(total_child_checkboxes, checked_child_checkboxes
104104
local cookie = self:cookie()
105105
if cookie then
106106
local new_cookie_val
107-
if query.get_node_text(cookie, 0):find('%%') then
107+
if ts.get_node_text(cookie, 0):find('%%') then
108108
new_cookie_val = ('[%d%%]'):format((#checked_child_checkboxes / #total_child_checkboxes) * 100)
109109
else
110110
new_cookie_val = ('[%d/%d]'):format(#checked_child_checkboxes, #total_child_checkboxes)

lua/orgmode/treesitter/table.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ local ts_utils = require('orgmode.utils.treesitter')
22
local Table = require('orgmode.parser.table')
33
local utils = require('orgmode.utils')
44
local config = require('orgmode.config')
5-
local query = vim.treesitter.query
5+
local ts = vim.treesitter
66

77
---@class TsTable
88
---@field node userdata
@@ -54,7 +54,7 @@ function TsTable:_parse_data()
5454
local cell_val = ''
5555
local cell_content = cell:field('contents')
5656
if cell_content and #cell_content > 0 then
57-
cell_val = query.get_node_text(cell_content[1], 0)
57+
cell_val = ts.get_node_text(cell_content[1], 0)
5858
end
5959
table.insert(row_data, cell_val)
6060
end

0 commit comments

Comments
 (0)