Skip to content

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

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

Closed
abulwafa opened this issue Jul 11, 2024 · 10 comments
Labels
bug Something isn't working

Comments

@abulwafa
Copy link

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 fb7f81e

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] ~

  • OK valid

markdown.nvim [nvim-treesitter] ~

  • OK installed
  • OK markdown: parser installed
  • OK markdown_inline: parser installed
  • WARNING latex: parser not installed
    • ADVICE:
      • Disable LaTeX support to avoid this warning by setting { latex = { enabled = false } }
  • OK highlights enabled

markdown.nvim [executables] ~

  • WARNING latex2text: not installed
    • ADVICE:
      • Disable LaTeX support to avoid this warning by setting { latex = { enabled = false } }

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 abulwafa added the bug Something isn't working label Jul 11, 2024
@abulwafa
Copy link
Author

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

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: a416b61.

@abulwafa
Copy link
Author

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

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

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

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

abulwafa commented Jul 12, 2024

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

I've made this part of the plugin itself as part of this change: d398f3e

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

@kmoschcau
Copy link

kmoschcau commented Jul 12, 2024

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

@abulwafa
Copy link
Author

@MeanderingProgrammer confirmed working as expected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants