-
Notifications
You must be signed in to change notification settings - Fork 51
bug: doesn't render telescope previews of markdown files? #98
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
Comments
This is a limitation of how Telescope previews buffers. More details on that here: https://github.com/nvim-telescope/telescope.nvim?tab=readme-ov-file#previewers. The relevant bit is here:
As a result of this the filetype is never set. In fact using lazy with Will add this as a known limitation. |
Would it be possible to manually attach to a buffer? I tried calling the below on an fzf-lua preview window but it doesn't seem to do anything, are there any other conditions that need to be met for manual attachment to work? require("render-markdown.manager").attach(bufnr) |
Hmm, that would be one way to do it. The However I don't think you'll need to manually call the attach function. Most likely the problem is the require('render-markdown').setup({
file_types = { 'markdown', 'FzfPreview' },
}) If you do this it should also attach automatically since this plugin listens to the There can be some issues with preview windows that programmatically re-use the same buffer / window, since those don't trigger autocommands in the same way as user interactions. So there might be some gaps there. More than happy to help get this working! |
Fzf-lua preview works in the same manner as Telescope and thus doesn't trigger loading events, basically same issues as #98.
Fzf-lua will create a new preview buffer for different files, it will then be cached and reattached to the preview window as needed.
I'll take a look at
Ty very much :-) |
Ah, I see. I found the issue with manually calling attach. The filetype is the empty string so updating the config to: require('render-markdown').setup({
file_types = { 'markdown', '' },
}) Gets us passed the attach stage. Unfortunately beyond that the backbone of this plugin relies on autocommands on attached buffers to trigger updates. From the local events = { 'BufWinEnter', 'BufLeave', 'CmdlineChanged', 'CursorHold', 'CursorMoved', 'WinScrolled' }
local change_events = { 'DiffUpdated', 'ModeChanged', 'TextChanged' }
if config:render('i') then
vim.list_extend(events, { 'CursorHoldI', 'CursorMovedI' })
vim.list_extend(change_events, { 'TextChangedI' })
end
vim.api.nvim_create_autocmd(vim.list_extend(events, change_events), {
group = M.group,
buffer = buf,
callback = function(args)
if not state.enabled then
return
end
local win, windows = util.current('win'), util.windows(buf)
win = vim.tbl_contains(windows, win) and win or windows[1]
local event = args.event
ui.update(buf, win, event, vim.tbl_contains(change_events, event))
end,
}) The call to Alternatively you can bypass the lifecycle management part of this plugin and call the ui directly to force it to render extmarks on the preview window whenever a change event occurs: require("render-markdown.core.ui").update(preview_buf, preview_win, "Fzf", true) If I know this is being used externally I'll avoid any breaking changes on this function. |
I see, the issue with autocmds is that they are somewhat invasive when it comes to something you'd consider a scratch preview buffer, for example, not attaching an LSP client to the buffer.
These are good quesions, I'm not sure if I have a better answer than to offload the updates to the calling plugin upon scroll, etc. require("render-markdown.core.ui").update(preview_buf, preview_win, "Fzf", true) Tried the above, still didn't render. I'm going to leave this for now until we can perhaps come up with a different strategy that won't be as prone to error as reintroducing autocmds or relying on the caller to update (even though there probably aren't too many locations to call render, scrolling, resizing, etc). Btw, there's a similar issue/wish-list with displaying |
I definitely understand why you want to avoid all the default things that happen when you open a buffer for a preview buffer, especially to have any kind of decent performance. We do end up in this unfortunate state where the preview buffers kind of exist on their own and each feature you want to add needs to be a hand rolled integration.
Holding off make sense. Calling the ui As a thought for what we can actually do that's less hacky what do you think about the concept of preview buffer extensions? It would be something similar to |
It works and seems quite nice, I only needed to add a call in the initial buffer populate method and the scolling:
This is a great idea, shouldn't be a big deal to add a few callbacks to the previewer class, I'm debating with myself in the case such as this which party is the responsible party for the integration, fzf-lua for "integration with redner-markdown" or the opposite? :-) In any event the simple integration I just added is a mere 5 lines of code. |
@MeanderingProgrammer, if you wanna try it out yourself, try the latest fzf-lua commit ibhagwan/fzf-lua@e0c16c1, don't need to configure anything special, if render-nvim is loaded fzf-lua will attempt to call |
Oh that's awesome! Super glad it works and looks great! Does it cause a noticeable delay in opening the file, or is the performance pretty good?
I think following the existing patterns from nvim-cmp and telescope would work perfectly here. So it would be up to fzf-lua to add the ability to add extensions and call registered extensions' methods when appropriate and it would be up to plugins or interested 3rd parties to write the integrations and keep up with any changes. As a very rough sketch of what I had in mind: Types---@class fzf.preview.Context
---@field buf integer
---@field win integer
---@class fzf.preview.Extension
---@field name fun(self: fzf.preview.Extension): string
---@field update fun(self: fzf.preview.Extension, context: fzf.preview.Context) render-markdown Implementation---@class render.md.fzf.Extension: fzf.preview.Extension
local Extension = {}
Extension.__index = Extension
---@return fzf.preview.Extension
function Extension.new()
return setmetatable({}, Extension)
end
---@return string
function Extension:name()
return 'render-markdown'
end
---@param context fzf.preview.Context
function Extension:update(context)
require("render-markdown.core.ui").update(context.buf, context.win, "FzfPreview", true)
end
local M = {}
function M.setup()
local ok, fzf = pcall(require, 'fzf-lua')
if ok then
fzf.register(Extension.new())
end
end
return M Somewhere in the initialization of render-markdown I'll call setup on this module, likely gated behind a config flag in case users prefer to not run this plugin with fzf-lua. Can also make this something users do in their plugin configurations more akin to telescope's Changes in fzf-luaAdd In probably the same spots as the local context = { buf = preview_buf, win = preview_win }
for _, extension in pairs(config.extensions) do
extension:update(context)
end |
Tried it out and works exactly how I would want, thank you! Was a little surprised to see this I'll add a note to myself that the |
This is just out of caution :-) I learned the hard way that every meaningless change has someone somwhere doing something I didn't anticipate causing an unexpected error lol, for example ibhagwan/fzf-lua@a3f66ca#commitcomment-149465672 which ended up with a commit revert. I'm still trying to think of a downside for setting |
@MeanderingProgrammer, ty for the API suggested implementation, I’d have to think about it a bit more as not every window/previewer supports everything, for example some users use I think it will also be wise on my end to first refactor the window class code and separate each window object (native, tmux, neovim float, neovim split) to their corresponding classes, then the proper API will “reveal” itself to me :) However, I’m in no rush as the integration demand is currently fulfilled via the very simple
Not at all, it seems you’ve implement the rendering asynchronously which is great, first the preview buffer content is displayed, only then the rendering is triggered on its own free time. |
I would definitely not expect checking window is valid to break a filter function, that's a fun side effect.
I hadn't noticed that the FileType event is being triggered, that makes sense, I assumed events were suppressed at a buffer level. As a result this plugin is attaching to the buffers, but still not enough to work on its own since it's missing the change events. I definitely get where you're coming from with trying to limit any potential impact. I was curious why LSPs weren't being attached to the buffers as well, turns out it's because they have the
No problem! Definitely no rush and I get if you'd prefer to not expose something like this, was just a thought. The hard part is definitely all those edge cases with what should be called when. You'd probably want extensions to somehow specify which buffers they should run on and more of those finer details.
I wish :( Trying to make it async using something from Instead the main rendering is wrapped in a Glad it's working well! I've switched my config over from Thanks for the thoughtful responses I've enjoyed this chat, if there's any follow up definitely feel free to reach out! |
I’m complimented, ty @MeanderingProgrammer, likewise. |
Neovim version (nvim -v)
0.10.0
Operating system
MacOS
Terminal emulator / GUI
Wezterm
Describe the bug
I would like it to render markdown in telescope previews, currently it doesn't, even if I use a telescope callback to call
require('render-markdown').enable()
on the preview bufferExpected behavior
It renders markdown in telescope previews
Healthcheck output
Plugin configuration
Confirmations
Additional information
No response
The text was updated successfully, but these errors were encountered: