Skip to content

Commit 1ba6fb7

Browse files
feat: handle possible issue with initial load when lazy loading
## Details Issue: #309 Depending on how the plugin manager implements lazy loading, this plugin can miss the initial buffer that triggered it to load. This is because we setup a `FileType` autocommand to check which buffers we should attach to. If the user configures this plugin to load based on a filetype that event will not be processed by the autocommand (since it has not been created yet). Instead everything will be setup but the current buffer will end up ignored. I'm unsure why this is not an issue with `lazy.nvim`, maybe it executes autocommands after the initial load. This would make sense, but I have not verified it. To get around this attempt to attach to the current buffer at the start, similar to the command based lazy loading edge case.
1 parent c85d682 commit 1ba6fb7

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

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

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

lua/render-markdown/manager.lua

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ M.group = vim.api.nvim_create_augroup('RenderMarkdown', { clear = true })
1414

1515
---Should only be called from plugin directory
1616
function M.setup()
17+
-- Lazy Loading: ignores current buffer as FileType event already executed
18+
M.attach(util.current('buf'))
1719
-- Attempt to attach to all buffers, cannot use pattern to support plugin directory
1820
vim.api.nvim_create_autocmd('FileType', {
1921
group = M.group,
@@ -40,7 +42,7 @@ end
4042

4143
---@param enabled boolean
4244
function M.set_all(enabled)
43-
-- Attempt to attach current buffer in case this is from a lazy load
45+
-- Lazy Loading: all previously opened buffers have been ignored
4446
M.attach(util.current('buf'))
4547
state.enabled = enabled
4648
for _, buf in ipairs(buffers) do

0 commit comments

Comments
 (0)