iamcco / markdown-preview.nvim

markdown preview plugin for (neo)vim
MIT License
6.67k stars 277 forks source link

Plugin loads only on first time #674

Open martin-braun opened 3 months ago

martin-braun commented 3 months ago

Describe the bug I managed to load the plugin, but it fails to load when nvim is opened at any given time after the first time. Only when the plugin just got installed, it will load properly.

To Reproduce I'm using NvChad which uses Lazy.nvim internally. Part of my plugins table is this plugin file:

local M = { "iamcco/markdown-preview.nvim" }

M.name = "markdown_preview_nvim"
M.lazy = true
M.cond = true

M.init = function()
    vim.g.mkdp_filetypes = { "markdown" }
end

M.config = function()
end

M.build = "cd app && yarn install"

M.cmd = { "MarkdownPreviewToggle", "MarkdownPreview", "MarkdownPreviewStop" }

return M

I require the above file and table.insert this into M.plugins in my chadrc.lua.

Expected behavior I can confirm this works just fine after adding my code. :MarkdownPreview opens the browser and I can see everything gets synced properly.

However, if I close nvim and reopen it, despite the plugin being load again, it will not work anymore.

The expected behavior is that this should work. If it works in the first session, it should also work in the 2nd session and so on.

"Command MarkdownPreview not found after loading markdown_preview_nvim"

Desktop (please complete the following information):

Log:

mkdp: health#mkdp#check

- Platform: macos
- Nvim Version: NVIM v0.10.0
  Build type: Release
  LuaJIT 2.1.1716656478
  Run "nvim -V1 -v" for more info
- Node version: v20.14.0
- Script: /Users/marty/.local/share/nvim/lazy/markdown_preview_nvim/app/server.js
- Script exists: 1
- OK Using node

v20.14.0

Additional comments

image
martin-braun commented 3 months ago

UPDATE:

I managed to get it to work, but there is still an issue. Apparently, after loading the plugin, I still have to leave and re-enter the buffer with the markdown to make the command available. This is obviously an issue.

So, it seems the issue is that it doesn't load something on initial load (except after being installed in the current session), but only when entering the markdown buffer.

martin-braun commented 3 months ago

Very good news: I found a fix!

Apparently the issue is solved if I tell Lazy.nvim to always load the plugin for "markdown" file types:

M.ft = { "markdown" }
M.cmd = nil

It seems this will cause the plugin to be load before BufEnter or whatever the event is that gets missed using M.cmd.

Obviously, the issue isn't solved, but this fix is good enough for me, so that I can move on.

Thanks.