Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lua/orgmode/colors/markup_highlighter.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local ts = require('orgmode.treesitter.compat')
local config = require('orgmode.config')
local ts_utils = require('nvim-treesitter.ts_utils')
local query = nil
Expand Down Expand Up @@ -226,7 +227,7 @@ local function load_deps()
if query then
return
end
query = vim.treesitter.get_query('org', 'markup')
query = ts.get_query('org', 'markup')
vim.treesitter.query.add_predicate('org-is-valid-markup-range?', is_valid_markup_range)
vim.treesitter.query.add_predicate('org-is-valid-hyperlink-range?', is_valid_hyperlink_range)
vim.treesitter.query.add_predicate('org-is-valid-latex-range?', is_valid_latex_range)
Expand Down
5 changes: 3 additions & 2 deletions lua/orgmode/colors/todo_highlighter.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
local ts = require('orgmode.treesitter.compat')
local config = require('orgmode.config')
local highlights = require('orgmode.colors.highlights')
local tree_utils = require('orgmode.utils.treesitter')
local utils = require('orgmode.utils')

local function add_todo_keyword_highlights()
local query_files = vim.treesitter.get_query_files('org', 'highlights')
local query_files = ts.get_query_files('org', 'highlights')
if not query_files or #query_files == 0 then
return
end
Expand Down Expand Up @@ -51,7 +52,7 @@ local function add_todo_keyword_highlights()
for _, v in ipairs(lines) do
table.insert(all_lines, v)
end
vim.treesitter.set_query('org', 'highlights', table.concat(all_lines, '\n'))
ts.set_query('org', 'highlights', table.concat(all_lines, '\n'))
if vim.bo.filetype == 'org' then
tree_utils.restart_highlights()
end
Expand Down
9 changes: 5 additions & 4 deletions lua/orgmode/org/indent.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local ts = require('orgmode.treesitter.compat')
local config = require('orgmode.config')
local ts_utils = require('nvim-treesitter.ts_utils')
local query = nil
Expand Down Expand Up @@ -25,7 +26,7 @@ local get_matches = ts_utils.memoize_by_buf_tick(function(bufnr)
}

if type == 'headline' then
opts.stars = vim.treesitter.query.get_node_text(node:field('stars')[1], bufnr):len()
opts.stars = ts.get_node_text(node:field('stars')[1], bufnr):len()
opts.indent = opts.indent + opts.stars + 1
matches[range.start.line + 1] = opts
end
Expand All @@ -52,7 +53,7 @@ local get_matches = ts_utils.memoize_by_buf_tick(function(bufnr)
end
if parent then
local headline = parent:named_child('headline')
local stars = vim.treesitter.query.get_node_text(headline:field('stars')[1], bufnr):len()
local stars = ts.get_node_text(headline:field('stars')[1], bufnr):len()
opts.indent = stars + 1
for i = range.start.line, range['end'].line - 1 do
matches[i + 1] = opts
Expand All @@ -67,7 +68,7 @@ end)

local prev_section = nil
local function foldexpr()
query = query or vim.treesitter.get_query('org', 'org_indent')
query = query or ts.get_query('org', 'org_indent')
local matches = get_matches(0)
local match = matches[vim.v.lnum]
local next_match = matches[vim.v.lnum + 1]
Expand Down Expand Up @@ -114,7 +115,7 @@ end

local function indentexpr()
local noindent_mode = config.org_indent_mode == 'noindent'
query = query or vim.treesitter.get_query('org', 'org_indent')
query = query or ts.get_query('org', 'org_indent')

local prev_linenr = vim.fn.prevnonblank(vim.v.lnum - 1)

Expand Down
3 changes: 2 additions & 1 deletion lua/orgmode/org/mappings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ local constants = require('orgmode.utils.constants')
local ts_utils = require('nvim-treesitter.ts_utils')
local utils = require('orgmode.utils')
local ts_org = require('orgmode.treesitter')
local ts = require('orgmode.treesitter.compat')
local ts_table = require('orgmode.treesitter.table')
local EventManager = require('orgmode.events')
local Promise = require('orgmode.utils.promise')
Expand Down Expand Up @@ -599,7 +600,7 @@ function OrgMappings:handle_return(suffix)
local counter = 1
while next_sibling do
local bullet = next_sibling:child(0)
local text = vim.treesitter.query.get_node_text(bullet, 0)
local text = ts.get_node_text(bullet, 0)
local new_text = tostring(tonumber(text:match('%d+')) + 1) .. closer

if counter == 1 then
Expand Down
31 changes: 31 additions & 0 deletions lua/orgmode/treesitter/compat.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
-- Shim module to address deprecations across nvim versions
local ts = vim.treesitter
local tsq = ts.query

local M = {}

function M.get_query_files(lang, query_group, is_included)
return (tsq.get_files or tsq.get_query_files)(lang, query_group, is_included)
end

function M.get_query(lang, query_name)
return (tsq.get or tsq.get_query)(lang, query_name)
end

function M.set_query(lang, query_name, text)
return (tsq.set or tsq.set_query)(lang, query_name, text)
end

function M.parse_query(lang, query)
return (tsq.parse or tsq.parse_query)(lang, query)
end

function M.get_range(node, source, metadata)
return (ts.get_range or tsq.get_range)(node, source, metadata)
end

function M.get_node_text(node, source, opts)
return (ts.get_node_text or tsq.get_node_text)(node, source, opts)
end

return M
36 changes: 18 additions & 18 deletions lua/orgmode/treesitter/headline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ local tree_utils = require('orgmode.utils.treesitter')
local Date = require('orgmode.objects.date')
local Range = require('orgmode.parser.range')
local config = require('orgmode.config')
local query = vim.treesitter.query
local ts = require('orgmode.treesitter.compat')

---@class Headline
---@field headline userdata
Expand Down Expand Up @@ -46,7 +46,7 @@ end
---@return number
function Headline:level()
local stars = self:stars()
return query.get_node_text(stars, 0):len()
return ts.get_node_text(stars, 0):len()
end

function Headline:priority()
Expand Down Expand Up @@ -94,7 +94,7 @@ end

function Headline:_handle_promote_demote(recursive, modifier)
local whole_subtree = function()
local text = query.get_node_text(self.headline:parent(), 0)
local text = ts.get_node_text(self.headline:parent(), 0)
local lines = modifier(vim.split(text, '\n', true))
tree_utils.set_node_lines(self.headline:parent(), lines)
return self:refresh()
Expand Down Expand Up @@ -128,7 +128,7 @@ function Headline:tags()
local node = self.headline:field('tags')[1]
local text = ''
if node then
text = query.get_node_text(node, 0)
text = ts.get_node_text(node, 0)
end
return node, text
end
Expand All @@ -142,7 +142,7 @@ function Headline:set_tags(tags)
end
end

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

local todo = self:todo()
if todo then
local text = query.get_node_text(todo, 0)
local text = ts.get_node_text(todo, 0)
tree_utils.set_node_text(todo, ('%s [#%s]'):format(text, priority))
return
end

local stars = self:stars()
local text = query.get_node_text(stars, 0)
local text = ts.get_node_text(stars, 0)
tree_utils.set_node_text(stars, ('%s [#%s]'):format(text, priority))
end

Expand All @@ -209,7 +209,7 @@ function Headline:set_todo(keyword)
end

local stars = self:stars()
local text = query.get_node_text(stars, 0)
local text = ts.get_node_text(stars, 0)
tree_utils.set_node_text(stars, string.format('%s %s', text, keyword))
end

Expand All @@ -231,7 +231,7 @@ function Headline:todo()
return nil
end

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

function Headline:title()
local title = query.get_node_text(self:item(), 0) or ''
local title = ts.get_node_text(self:item(), 0) or ''
local todo, word = self:todo()
if todo then
title = title:gsub('^' .. vim.pesc(word) .. '%s*', '')
Expand Down Expand Up @@ -334,11 +334,11 @@ function Headline:get_property(property_name)
for _, node in ipairs(ts_utils.get_named_children(properties)) do
local name = node:field('name')[1]
local value = node:field('value')[1]
if name and query.get_node_text(name, 0):lower() == property_name:lower() then
if name and ts.get_node_text(name, 0):lower() == property_name:lower() then
return {
node = node,
name = name,
value = value and query.get_node_text(value, 0),
value = value and ts.get_node_text(value, 0),
}
end
end
Expand Down Expand Up @@ -369,7 +369,7 @@ function Headline:dates()
end

for _, node in ipairs(ts_utils.get_named_children(plan)) do
local name = query.get_node_text(node:named_child(0), 0)
local name = ts.get_node_text(node:named_child(0), 0)
dates[name] = node
end
return dates
Expand Down Expand Up @@ -445,7 +445,7 @@ function Headline:update_cookie(list_node)
local cookie = self:cookie()
if cookie then
local new_cookie_val
if query.get_node_text(cookie, 0):find('%%') then
if ts.get_node_text(cookie, 0):find('%%') then
new_cookie_val = ('[%d%%]'):format((#checked_boxes / #total_boxes) * 100)
else
new_cookie_val = ('[%d/%d]'):format(#checked_boxes, #total_boxes)
Expand All @@ -456,7 +456,7 @@ end

function Headline:child_checkboxes(list_node)
return vim.tbl_map(function(node)
local text = query.get_node_text(node, 0)
local text = ts.get_node_text(node, 0)
return text:match('%[.%]')
end, ts_utils.get_named_children(list_node))
end
Expand All @@ -465,7 +465,7 @@ end
function Headline:parse(pattern)
local match = ''
local matching_nodes = vim.tbl_filter(function(node)
local text = query.get_node_text(node, 0) or ''
local text = ts.get_node_text(node, 0) or ''
local m = text:match(pattern)
if m then
match = text:match(pattern)
Expand All @@ -487,7 +487,7 @@ function Headline:_get_date(type)
if not timestamp_node then
return nil
end
local parsed_date = Date.from_org_date(query.get_node_text(timestamp_node, 0), {
local parsed_date = Date.from_org_date(ts.get_node_text(timestamp_node, 0), {
range = Range.from_node(timestamp_node),
})
return parsed_date and parsed_date[1] or nil
Expand Down Expand Up @@ -522,7 +522,7 @@ function Headline:_add_date(type, date, active)
break
end
end
local ptext = query.get_node_text(last_child, 0)
local ptext = ts.get_node_text(last_child, 0)
tree_utils.set_node_text(last_child, ptext .. ' ' .. text)
return self:refresh()
end
Expand Down
10 changes: 5 additions & 5 deletions lua/orgmode/treesitter/listitem.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local ts_utils = require('nvim-treesitter.ts_utils')
local tree_utils = require('orgmode.utils.treesitter')
local query = vim.treesitter.query
local ts = require('orgmode.treesitter.compat')
local Headline = require('orgmode.treesitter.headline')

---@class Listitem
Expand Down Expand Up @@ -36,7 +36,7 @@ function Listitem:checkbox()
if not checkbox then
return nil
end
local text = query.get_node_text(checkbox, 0)
local text = ts.get_node_text(checkbox, 0)
return { text = text, range = { checkbox:range() } }
end

Expand Down Expand Up @@ -79,7 +79,7 @@ function Listitem:child_checkboxes()
for _, content in ipairs(contents) do
if content:type() == 'list' then
return vim.tbl_map(function(node)
local text = query.get_node_text(node, 0)
local text = ts.get_node_text(node, 0)
return text:match('%[.%]')
end, ts_utils.get_named_children(content))
end
Expand All @@ -94,7 +94,7 @@ function Listitem:cookie()
return nil
end

local text = query.get_node_text(cookie_node, 0)
local text = ts.get_node_text(cookie_node, 0)
if text:match('%[%d*/%d*%]') or text:match('%[%d?%d?%d?%%%]') then
return cookie_node
end
Expand All @@ -104,7 +104,7 @@ function Listitem:update_cookie(total_child_checkboxes, checked_child_checkboxes
local cookie = self:cookie()
if cookie then
local new_cookie_val
if query.get_node_text(cookie, 0):find('%%') then
if ts.get_node_text(cookie, 0):find('%%') then
new_cookie_val = ('[%d%%]'):format((#checked_child_checkboxes / #total_child_checkboxes) * 100)
else
new_cookie_val = ('[%d/%d]'):format(#checked_child_checkboxes, #total_child_checkboxes)
Expand Down
4 changes: 2 additions & 2 deletions lua/orgmode/treesitter/table.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local ts_utils = require('orgmode.utils.treesitter')
local Table = require('orgmode.parser.table')
local utils = require('orgmode.utils')
local config = require('orgmode.config')
local query = vim.treesitter.query
local ts = require('orgmode.treesitter.compat')

---@class TsTable
---@field node userdata
Expand Down Expand Up @@ -54,7 +54,7 @@ function TsTable:_parse_data()
local cell_val = ''
local cell_content = cell:field('contents')
if cell_content and #cell_content > 0 then
cell_val = query.get_node_text(cell_content[1], 0)
cell_val = ts.get_node_text(cell_content[1], 0)
end
table.insert(row_data, cell_val)
end
Expand Down
2 changes: 1 addition & 1 deletion lua/orgmode/utils/init.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local ts = require('vim.treesitter.query')
local ts = require('orgmode.treesitter.compat')
local ts_utils = require('nvim-treesitter.ts_utils')
local Promise = require('orgmode.utils.promise')
local uv = vim.loop
Expand Down
3 changes: 2 additions & 1 deletion lua/orgmode/utils/treesitter.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local ts = require('orgmode.treesitter.compat')
local ts_utils = require('nvim-treesitter.ts_utils')
local parsers = require('nvim-treesitter.parsers')
local M = {}
Expand All @@ -21,7 +22,7 @@ end
function M.parse_query(query)
local ts_query = query_cache[query]
if not ts_query then
ts_query = vim.treesitter.query.parse_query('org', query)
ts_query = ts.parse_query('org', query)
query_cache[query] = ts_query
end
return query_cache[query]
Expand Down