Skip to content

Commit b57d51d

Browse files
fix(0.11): lsp hover doc event order change
## Details Report: #333 Caused by a recent change to neovim that moved when filetype is set to after content being set: neovim/neovim#32112 To handle this add a call to `update` after attaching to a buffer for the first time. This will trigger rendering without needing an event (previously `BufWinEnter`) to get the initial view to work. Other small changes: - Add notes to self about highlight type definition changes in 0.11 - `get_parser` can return `nil` in 0.11 so add `nil` checks around these - Check whether parsing is needed at both the time of scheduling our render update and again when executing it since the state may have changed between the 2 and we can potentially avoid the additional overhead, similar concept to validating the buffer / window at both of these times
1 parent 1cd546e commit b57d51d

File tree

8 files changed

+44
-30
lines changed

8 files changed

+44
-30
lines changed

doc/render-markdown.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*render-markdown.txt* For 0.10.0 Last change: 2025 February 25
1+
*render-markdown.txt* For 0.10.0 Last change: 2025 February 27
22

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

lua/render-markdown/colors.lua

+4
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,10 @@ function M.combine(foreground, background, force)
9292
vim.api.nvim_set_hl(0, name, {
9393
fg = fg.fg,
9494
bg = bg.bg,
95+
-- TODO(0.11): remove
9596
---@diagnostic disable-next-line: undefined-field
9697
ctermfg = fg.ctermfg,
98+
-- TODO(0.11): remove
9799
---@diagnostic disable-next-line: undefined-field
98100
ctermbg = bg.ctermbg,
99101
})
@@ -111,6 +113,7 @@ function M.bg_to_fg(highlight, force)
111113
local hl = M.get_hl(highlight)
112114
vim.api.nvim_set_hl(0, name, {
113115
fg = hl.bg,
116+
-- TODO(0.11): remove
114117
---@diagnostic disable-next-line: undefined-field
115118
ctermfg = hl.ctermbg,
116119
})
@@ -123,6 +126,7 @@ end
123126
---@param name string
124127
---@return vim.api.keyset.hl_info
125128
function M.get_hl(name)
129+
-- TODO(0.11): return vim.api.keyset.get_hl_info
126130
return vim.api.nvim_get_hl(0, { name = name, link = false })
127131
end
128132

lua/render-markdown/core/conceal.lua

+3
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ function Conceal:compute(context)
9090
return
9191
end
9292
local parser = vim.treesitter.get_parser(self.buf)
93+
if parser == nil then
94+
return
95+
end
9396
context:parse(parser)
9497
parser:for_each_tree(function(tree, language_tree)
9598
self:compute_tree(context, language_tree:lang(), tree:root())

lua/render-markdown/core/ui.lua

+18-8
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,11 @@ function M.update(buf, win, event, change)
8181
return
8282
end
8383

84+
local parse = M.parse(buf, win, change)
8485
local config, buffer_state = state.get(buf), Cache.get(buf)
8586

86-
-- Need to parse when things change or we have not parsed the visible range yet
87-
local parse = change or not Context.contains_range(buf, win)
88-
8987
local update = function()
90-
M.run_update(buf, win, parse)
88+
M.run_update(buf, win, change)
9189
end
9290
if parse and state.log_runtime then
9391
update = util.wrap_runtime(update)
@@ -103,12 +101,23 @@ end
103101
---@private
104102
---@param buf integer
105103
---@param win integer
106-
---@param parse boolean
107-
function M.run_update(buf, win, parse)
104+
---@param change boolean
105+
---@return boolean
106+
function M.parse(buf, win, change)
107+
-- Need to parse when things change or we have not parsed the visible range yet
108+
return change or not Context.contains_range(buf, win)
109+
end
110+
111+
---@private
112+
---@param buf integer
113+
---@param win integer
114+
---@param change boolean
115+
function M.run_update(buf, win, change)
108116
if not util.valid(buf, win) then
109117
return
110118
end
111119

120+
local parse = M.parse(buf, win, change)
112121
local config, buffer_state = state.get(buf), Cache.get(buf)
113122
local mode, row = util.mode(), util.row(buf, win)
114123
local next_state = M.next_state(config, win, mode)
@@ -131,7 +140,8 @@ function M.run_update(buf, win, parse)
131140
}))
132141
end
133142
local hidden = config:hidden(mode, row)
134-
for _, extmark in ipairs(buffer_state:get_marks()) do
143+
local extmarks = buffer_state:get_marks()
144+
for _, extmark in ipairs(extmarks) do
135145
local mark = extmark:get_mark()
136146
if mark.conceal and hidden ~= nil and hidden:contains(mark.start_row, mark.start_row) then
137147
extmark:hide(M.namespace, buf)
@@ -175,7 +185,7 @@ end
175185
function M.parse_buffer(props)
176186
local buf = props.buf
177187
local has_parser, parser = pcall(vim.treesitter.get_parser, buf)
178-
if not has_parser then
188+
if not has_parser or parser == nil then
179189
log.buf('error', 'fail', buf, 'no treesitter parser found')
180190
return {}
181191
end

lua/render-markdown/core/util.lua

+3-4
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,10 @@ function M.file_name(buf)
148148
end
149149
end
150150

151-
---@param source string|integer
151+
---@param file string|integer
152152
---@return number
153-
function M.file_size_mb(source)
154-
local file = source
155-
if type(file) == 'number' then
153+
function M.file_size_mb(file)
154+
if type(file) ~= 'string' then
156155
file = vim.api.nvim_buf_get_name(file)
157156
end
158157
local ok, stats = pcall(function()

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.0.12'
8+
M.version = '8.0.13'
99

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

lua/render-markdown/integ/source.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ end
2828
---@return lsp.CompletionItem[]?
2929
function M.items(buf, row, col)
3030
local has_parser, parser = pcall(vim.treesitter.get_parser, buf)
31-
if not has_parser then
31+
if not has_parser or parser == nil then
3232
return nil
3333
end
3434

lua/render-markdown/manager.lua

+13-15
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ M.group = vim.api.nvim_create_augroup('RenderMarkdown', { clear = true })
1616
function M.setup()
1717
-- Lazy Loading: ignores current buffer as FileType event already executed
1818
if #util.lazy('ft') == 0 and #util.lazy('cmd') == 0 then
19-
M.attach_current()
19+
M.attach(util.current('buf'))
2020
end
2121
-- Attempt to attach to all buffers, cannot use pattern to support plugin directory
2222
vim.api.nvim_create_autocmd('FileType', {
@@ -52,15 +52,15 @@ end
5252
function M.set_all(enabled)
5353
-- Lazy Loading: all previously opened buffers have been ignored
5454
if #util.lazy('cmd') > 0 then
55-
M.attach_current()
55+
M.attach(util.current('buf'))
5656
end
5757
if enabled ~= nil then
5858
state.enabled = enabled
5959
else
6060
state.enabled = not state.enabled
6161
end
6262
for _, buf in ipairs(buffers) do
63-
M.trigger_update(buf)
63+
M.update(buf, 'UserCommand')
6464
end
6565
end
6666

@@ -74,21 +74,10 @@ function M.set_current(enabled)
7474
else
7575
config.enabled = not config.enabled
7676
end
77-
M.trigger_update(buf)
77+
M.update(buf, 'UserCommand')
7878
end
7979
end
8080

81-
---@private
82-
function M.attach_current()
83-
M.attach(util.current('buf'))
84-
end
85-
86-
---@private
87-
---@param buf integer
88-
function M.trigger_update(buf)
89-
ui.update(buf, vim.fn.bufwinid(buf), 'UserCommand', true)
90-
end
91-
9281
---@private
9382
---@param buf integer
9483
function M.attach(buf)
@@ -122,6 +111,15 @@ function M.attach(buf)
122111
ui.update(buf, win, event, vim.tbl_contains(change_events, event))
123112
end,
124113
})
114+
115+
M.update(buf, 'Initial')
116+
end
117+
118+
---@private
119+
---@param buf integer
120+
---@param event string
121+
function M.update(buf, event)
122+
ui.update(buf, vim.fn.bufwinid(buf), event, true)
125123
end
126124

127125
---@private

0 commit comments

Comments
 (0)