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

Better Hover Experience - Feature Request #36

Closed
tuliopaim opened this issue Aug 22, 2024 · 13 comments
Closed

Better Hover Experience - Feature Request #36

tuliopaim opened this issue Aug 22, 2024 · 13 comments

Comments

@tuliopaim
Copy link

In the "original" repo EnochMtzR opened a PR (jmederosalvarado#30) to improve the hover experience by adding markdown support and replacing some characters. Before switching to this repo I used a fork with his commits and it was great.

Yesterday I tried to adapt it to this new code base, but I have no idea how. If someone could point me in the right direction I could try to do it myself.

@seblyng
Copy link
Owner

seblyng commented Aug 22, 2024

Doesn't this just work out of the box for you?

@tuliopaim
Copy link
Author

Doesn't this just work out of the box for you?

image

@seblyng
Copy link
Owner

seblyng commented Aug 22, 2024

Are you sure you are using treesitter and have the markdown inline parser? It should just work

@tuliopaim
Copy link
Author

I confess that I didn't have markdown_inline, but now I do and the behavior is the same, what am I missing?

:TSInstallInfo

markdown           [✓] installed
markdown_inline    [✓] installed

@seblyng
Copy link
Owner

seblyng commented Aug 22, 2024

What version og neovim do you have?

@tuliopaim
Copy link
Author

What version og neovim do you have?

NVIM v0.10.1

@tuliopaim
Copy link
Author

Someone else commented in that PR asking him to re-implement it here, so it's not only me.

@seblyng
Copy link
Owner

seblyng commented Aug 22, 2024

I know, but it should just work. So we need to figure out why it doesn't for you. It works for me at least in my config.

I can test with a very minimal config when I have some time

@seblyng
Copy link
Owner

seblyng commented Aug 22, 2024

image
for name, url in pairs({
	roslyn = "https://github.com/seblj/roslyn.nvim",
	cattpuccin = "https://github.com/catppuccin/nvim",
	treesitter = "https://github.com/nvim-treesitter/nvim-treesitter",
}) do
	local install_path = vim.fn.fnamemodify("roslyn_minimal/" .. name, ":p")
	if vim.fn.isdirectory(install_path) == 0 then
		vim.fn.system({ "git", "clone", "--depth=1", url, install_path })
	end
	vim.opt.runtimepath:append(install_path)
end

local path = vim.fs.normalize("~/.local/share/nvim/roslyn/Microsoft.CodeAnalysis.LanguageServer.dll")

require("roslyn").setup({
	exe = { "dotnet", path },
})

require("nvim-treesitter.configs").setup({
	ensure_installed = { "c_sharp" },
})

require("catppuccin").setup()

vim.cmd.colorscheme("catppuccin")

This is the default experience with this minimal config.

It is using treesitter markdown_inline parser and setting conceallevel to 2 automatically. However, if you set the conceallevel to 0 (which is the default in all other buffers), then it will look like this:

image

So this must be a config issue

@drzbida
Copy link

drzbida commented Aug 22, 2024

Content format is indeed already markdown and it should work as expected. This can be tested by attaching such a handler in the setup config

handlers = {
    ["textDocument/hover"] = function(err, result, ctx, config)
        vim.notify(vim.inspect(result.contents.kind), vim.log.levels.INFO)
        vim.lsp.handlers["textDocument/hover"](err, result, ctx, config)
    end,
},

That being said, something is definitely wrong with the \ characters that appear before some symbols (even in the first screenshot from last comment).

image
or
image

This is the markdown value intercepted like this:

  ["textDocument/hover"] = function(err, result, ctx, config)
      vim.notify(vim.inspect(result.contents.value), vim.log.levels.INFO)
      vim.lsp.handlers["textDocument/hover"](err, result, ctx, config)
  end,
```csharp\r\nreadonly struct System.Single\r\n```\r\n\r\nRepresents a single\\-precision floating\\-point number\\.\r\n

It seems that the server probably sends escapes in code using four \ instead of two. I'm not entirely sure this should be fixed by this plugin as it is outside the scope and most likely a bug in roslyn, although it definitely is weird to leave it like this.

Here is a temporary fix you can use in your configs:

return {
    "seblj/roslyn.nvim",
    config = function()
        require("roslyn").setup {
            config = {
                on_init = function(client)
                    client.offset_encoding = "utf-8"
                end,
                handlers = { -- this is what matters
                    ["textDocument/hover"] = function(err, result, ctx, config)
                        if result and result.contents and result.contents.value then
                            result.contents.value = result.contents.value:gsub("\\([^%w])", "%1")
                        end
                        vim.lsp.handlers["textDocument/hover"](err, result, ctx, config)
                    end,
                },
            },
        }
    end,
    lazy = false,
}

@seblyng
Copy link
Owner

seblyng commented Aug 22, 2024

Yeah, I will not be adding a hack for this, as this should be fixed either in the markdown parser queries or in roslyn

@tuliopaim
Copy link
Author

I appreciate the time spent on this, I'll try to do some research and revisit all my plugins to see if anything could be getting in the middle of this, I tried @drzbida approach, and it's indeed printing "markdown" as the kind.
I also tried to set the conceallevel to 2 by hand, but with no success.

@tuliopaim
Copy link
Author

Ok, the issue was the treesitter version, working as expected after updating from v0.9.1 to v0.9.2.

Thanks again @seblj and @drzbida

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

3 participants