Skip to content

Commit 0cab868

Browse files
fix: handle offset conceal nodes
## Details Currently when computing the range of a conceal highlight we always use the entire range of the node. However if an offset directive is specified then the range in the metadata should be used instead. This change accomplishes this by adding a series of fallbacks when computing conceal information. First by checking the metadata range, then the metadata[node_id] range, and finally falling back to the node range of neither of these exist.
1 parent d3a565e commit 0cab868

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

doc/render-markdown.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*render-markdown.txt* For 0.10.0 Last change: 2024 September 27
1+
*render-markdown.txt* For 0.10.0 Last change: 2024 September 29
22

33
==============================================================================
44
Table of Contents *render-markdown-table-of-contents*

lua/render-markdown/core/context.lua

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,9 @@ function Context:compute_conceal()
229229
local parser = vim.treesitter.get_parser(self.buf)
230230
self:parse(parser)
231231
parser:for_each_tree(function(tree, language_tree)
232-
local nodes = self:compute_conceal_nodes(language_tree:lang(), tree:root())
233-
for _, node in ipairs(nodes) do
234-
local row, start_col, _, end_col = node:range()
232+
local conceal_ranges = self:compute_conceal_ranges(language_tree:lang(), tree:root())
233+
for _, conceal_range in ipairs(conceal_ranges) do
234+
local row, start_col, end_col = unpack(conceal_range)
235235
if ranges[row] == nil then
236236
ranges[row] = {}
237237
end
@@ -244,8 +244,8 @@ end
244244
---@private
245245
---@param language string
246246
---@param root TSNode
247-
---@return TSNode[]
248-
function Context:compute_conceal_nodes(language, root)
247+
---@return [integer, integer, integer][]
248+
function Context:compute_conceal_ranges(language, root)
249249
if not self:overlaps_node(root) then
250250
return {}
251251
end
@@ -256,15 +256,24 @@ function Context:compute_conceal_nodes(language, root)
256256
if query == nil then
257257
return {}
258258
end
259-
local nodes = {}
259+
local result = {}
260260
for _, range in ipairs(self.ranges) do
261-
for _, node, metadata in query:iter_captures(root, self.buf, range.top, range.bottom) do
261+
for id, node, metadata in query:iter_captures(root, self.buf, range.top, range.bottom) do
262262
if metadata.conceal ~= nil then
263-
table.insert(nodes, node)
263+
local node_range = metadata.range
264+
if node_range == nil and metadata[id] ~= nil then
265+
node_range = metadata[id].range
266+
end
267+
if node_range == nil then
268+
---@diagnostic disable-next-line: missing-fields
269+
node_range = { node:range() }
270+
end
271+
local row, start_col, _, end_col = unpack(node_range)
272+
table.insert(result, { row, start_col, end_col })
264273
end
265274
end
266275
end
267-
return nodes
276+
return result
268277
end
269278

270279
---@type table<integer, render.md.Context>

lua/render-markdown/health.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ local state = require('render-markdown.state')
44
local M = {}
55

66
---@private
7-
M.version = '7.2.3'
7+
M.version = '7.2.4'
88

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

0 commit comments

Comments
 (0)