Skip to content

Commit adf277c

Browse files
chore(refactor): Add get_node treesitter helper
Ensure we are always using correct language when getting the node
1 parent 56c8246 commit adf277c

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

lua/orgmode/colors/highlighter/stars.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
local ts_utils = require('orgmode.utils.treesitter')
12
local config = require('orgmode.config')
23

34
---@class OrgStarsHighlighter
@@ -19,10 +20,9 @@ function OrgStars:on_line(bufnr, line)
1920
return
2021
end
2122

22-
local node = vim.treesitter.get_node({
23+
local node = ts_utils.get_node({
2324
bufnr = bufnr,
2425
pos = { line, 0 },
25-
lang = 'org',
2626
})
2727

2828
if not node or node:type() ~= 'stars' then

lua/orgmode/ui/virtual_indent.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ function VirtualIndent:set_indent(start_line, end_line, ignore_ts)
9595
start_line = start_line - 1
9696
end
9797

98-
local node_at_cursor = vim.treesitter.get_node({ lang = 'org' })
98+
local node_at_cursor = tree_utils.get_node()
9999
local tree_has_errors = false
100100
if node_at_cursor then
101101
tree_has_errors = node_at_cursor:tree():root():has_error()

lua/orgmode/utils/treesitter/init.lua

+9-3
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,24 @@ function M.parse_current_file()
1313
return vim.treesitter.get_parser(0, 'org', {}):parse()
1414
end
1515

16+
---@param opts? vim.treesitter.get_node.Opts
17+
function M.get_node(opts)
18+
opts = opts or {}
19+
opts.lang = opts.lang or 'org'
20+
return vim.treesitter.get_node(opts)
21+
end
22+
1623
---@param cursor? table
1724
---@return TSNode | nil
1825
function M.get_node_at_cursor(cursor)
1926
M.parse_current_file()
2027
if not cursor then
21-
return vim.treesitter.get_node({ lang = 'org' })
28+
return M.get_node()
2229
end
2330

24-
return vim.treesitter.get_node({
31+
return M.get_node({
2532
bufnr = 0,
2633
pos = { cursor[1] - 1, cursor[2] },
27-
lang = 'org',
2834
})
2935
end
3036

0 commit comments

Comments
 (0)