Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin loads only on first time #674

Open
martin-braun opened this issue Jun 2, 2024 · 2 comments
Open

Plugin loads only on first time #674

martin-braun opened this issue Jun 2, 2024 · 2 comments

Comments

@martin-braun
Copy link

martin-braun commented Jun 2, 2024

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):

  • OS: macos

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

  • I tried different methods, such as using the vim.fn build method, but this wouldn't work at all, not even at the first time, although I get no errors and everything looks alright
  • I noticed this plugin also updates the syntax highlighting of markdowns, well not so much from the 2nd session on, which is on par with the fact that the plugin doesn't get load anymore
  • I can reproduce the issue by removing the plugin from my configuration and adding it back in
  • The plugin gets loaded, but it's still not working:
image
@martin-braun
Copy link
Author

martin-braun commented Jun 2, 2024

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
Copy link
Author

martin-braun commented Jun 2, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant