MeanderingProgrammer / render-markdown.nvim

Plugin to improve viewing Markdown files in Neovim
MIT License
1.39k stars 33 forks source link

bug: Plugin stopped rendering markdown in floating windows (Hover doc) after specific commit #61

Closed abulwafa closed 2 months ago

abulwafa commented 2 months ago

Neovim version (nvim -v)

0.11.0

Operating system

Linux

Terminal emulator / GUI

Kitty

Describe the bug

First of all, I want to extend my gratitude for creating such an amazing plugin!

I've encountered an issue where the plugin stopped rendering markdown correctly in floating windows, such as Hover doc, after a specific commit. The plugin continues to work perfectly in markdown files themselves.

Steps to Reproduce:

Open a markdown file to confirm the plugin is working. Use a feature that triggers a floating window (e.g., Hover doc). Observe that the markdown rendering is not applied in the floating window.

The commit fb7f81e14942ed8814ac5bb26b7cfa90795d21de

Expected behavior

The plugin should render markdown with the same quality and visual enhancements in floating windows as it does in markdown files.

Healthcheck output (:checkhealth render-markdown)

markdown.nvim [configuration] ~

markdown.nvim [nvim-treesitter] ~

markdown.nvim [executables] ~

Additional information

I override the default open float handler, by setting a filetype

local orig_util_open_floating_preview = vim.lsp.util.open_floating_preview

function vim.lsp.util.open_floating_preview(contents, syntax, opts, ...)
  local bufnr, winnr =
    orig_util_open_floating_preview(contents, syntax, opts, ...)
  vim.api.nvim_set_option_value("signcolumn", "no", { win = winnr })
  vim.api.nvim_set_option_value("filetype", "markdown", { buf = bufnr })
  return bufnr, winnr
end

Before

20240711_13h27m52s_grim

After

20240711_13h29m01s_grim

abulwafa commented 2 months ago

Update: I've figured out the cause of the issue. It was related to a new config option that I had overlooked. After updating my configuration, the plugin works perfectly in both markdown files and floating windows.

    exclude = {
      -- Buftypes ignored by this plugin, see :h 'buftype'
      buftypes = {"nofile},
    },

Thank you once again for your amazing plugin and your support!

MeanderingProgrammer commented 2 months ago

Thank you for the kind words :) I'm glad you've been liking the plugin!

I added the option because I did not like the sign column in LSP docs, but disabling the signcolumn there is a good idea.

I should have made it opt in in either case, have changed the default to be the empty list rather than defaulting to nofile: https://github.com/MeanderingProgrammer/markdown.nvim/commit/a416b61a96544baf8f2c6c8de978e45c39612e12.

abulwafa commented 2 months ago

Hi @MeanderingProgrammer,

Thank you for the prompt response and the update!

I can confirm that removing the sign column has made the experience a whole lot better. Rendering the docs and diagnostics using the plugin has significantly improved the readability and usability of the content. Specifically, the ability to conceal URLs in diagnostics is a great feature. It makes the diagnostic messages shorter and more concise, while still allowing the user to open the URLs in a browser when needed.

Once again, thank you for your amazing work

kmoschcau commented 2 months ago

Hi, I just found this issue. I'm currently banging my head against the wall, trying to find a way to disable the signcolumn only for hover windows, because I still want to use this plugin in hover windows. @abulwafa have you found a way to do that?

abulwafa commented 2 months ago

@kmoschcau Here it is

This line : vim.api.nvim_set_option_value("signcolumn", "no", { win = winnr })

local orig_util_open_floating_preview = vim.lsp.util.open_floating_preview
function vim.lsp.util.open_floating_preview(contents, syntax, opts, ...)
  local bufnr, winnr =
    orig_util_open_floating_preview(contents, syntax, opts, ...)
  vim.api.nvim_set_option_value("signcolumn", "no", { win = winnr })
  vim.api.nvim_set_option_value("filetype", "markdown", { buf = bufnr })
  return bufnr, winnr
end
kmoschcau commented 2 months ago

Ah a bit of monkey patching. :D I was trying to do it via events. But maybe I can achieve something similar with LSP handlers, so that it doesn't affect all floating windows.

abulwafa commented 2 months ago

Hi @kmoschcau,

I haven't found a way to override window/buffer options through the ["textDocument/hover"] handler, the only opts available are:

      • {opts}      (`table?`) with optional fields (additional keys are
                    filtered with |vim.lsp.util.make_floating_popup_options()|
                    before they are passed on to |nvim_open_win()|)
                    • {height}? (`integer`) Height of floating window
                    • {width}? (`integer`) Width of floating window
                    • {wrap}? (`boolean`, default: `true`) Wrap long lines
                    • {wrap_at}? (`integer`) Character to wrap at for
                      computing height when wrap is enabled
                    • {max_width}? (`integer`) Maximal width of floating
                      window
                    • {max_height}? (`integer`) Maximal height of floating
                      window
                    • {focus_id}? (`string`) If a popup with this id is
                      opened, then focus it
                    • {close_events}? (`table`) List of events that closes the
                      floating window
                    • {focusable}? (`boolean`, default: `true`) Make float
                      focusable.
                    • {focus}? (`boolean`, default: `true`) If `true`, and if
                      {focusable} is also `true`, focus an existing floating
                      window with the same {focus_id}

You can check for the syntax parameter, to only target hover doc

ex. check if syntax == 'markdown'

or check for opts.focus_id = "textDocument/hover"

MeanderingProgrammer commented 2 months ago

I've made this part of the plugin itself as part of this change: https://github.com/MeanderingProgrammer/markdown.nvim/commit/d398f3e9f21d88e1de51594cd4a78f56a3a3eb9e

Since I needed to globally change the signs the plugin creates anyway

kmoschcau commented 2 months ago

@abulwafa the new fix now addresses this without any hacks. image

abulwafa commented 2 months ago

@MeanderingProgrammer confirmed working as expected