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

vim.lsp.buf.hover don't have any syntax highlight in C file #27563

Closed
HalmondD opened this issue Feb 21, 2024 · 20 comments
Closed

vim.lsp.buf.hover don't have any syntax highlight in C file #27563

HalmondD opened this issue Feb 21, 2024 · 20 comments
Labels
closed:invalid Issues that are closed as "invalid"

Comments

@HalmondD
Copy link

Problem

The vim.lsp.buf.hover work nicely with Lua language.
image

However, when using it with C file, the feature doesn't have any syntax coloring and look bad.
image

I try using lspsaga plugin and use the command :Lspsaga hover_doc, also doesn't work. Of course I also download markdown, markdown_inline on treesitter, but still nothing change.
image

Steps to reproduce using "nvim -u minimal_init.lua"

I don't really know how to do this step, there seem don't have any guide for me to follow since I am not really good with Lua.

Expected behavior

It should have the syntax highlight and format like the one in Lua file but for C file.
image

Neovim version (nvim -v)

NVIM v0.8.3 installed via appimage since Unbuntu apt don't have the latest version.

Language server name/version

clangd version 17.0.3 install via zip file since Ubuntu apt don't have the latest version.

Operating system/version

Ubuntu 22.04.4 LTS.

Log file

no log.

@HalmondD HalmondD added bug issues reporting wrong behavior lsp labels Feb 21, 2024
@clason
Copy link
Member

clason commented Feb 21, 2024

Your Neovim version is much too old. Please test the latest nightly.

@zeertzjq
Copy link
Member

Not an Nvim issue. The hover content comes from the language server and the highlights are provided by your colorscheme.

@zeertzjq zeertzjq closed this as not planned Won't fix, can't repro, duplicate, stale Feb 21, 2024
@zeertzjq zeertzjq added closed:invalid Issues that are closed as "invalid" and removed bug issues reporting wrong behavior lsp labels Feb 21, 2024
@HalmondD
Copy link
Author

No it seem that the colorscheme is not the issue here, I change it from dracula to catppuccin - which a very popular colorscheme and you tell me that it does not have the syntax highlight for vim.lsp.buf.hover?

@clason
Copy link
Member

clason commented Feb 21, 2024

Who knows; we don't maintain these. (There's a reason the issue template requests reproduction steps with nvim --clean.)

@HalmondD
Copy link
Author

And how I can I do that step, can you guide me please?

@clason
Copy link
Member

clason commented Feb 21, 2024

@HalmondD
Copy link
Author

Continue this thread, I have gone to the clangd issue and have some progress:
After reading the lsp.log, they find out that:

  • clangd is indeed sending plain-text hover information instead of markdown
  • the reason for this in turn is that the client does not indicate support for markdown in its client capabilities

So the first conclusion is that this is the client issue.

and after extracting the lsp.log, they say this.

Here is my lsp capabilities and attatch:

local lsp_servers = {
  'clangd',
  'lua_ls',
}


local lspconfig_status_ok, lspconfig = pcall(require, "lspconfig")
if not lspconfig_status_ok then
	return
end

local my_on_attatch = function(client)
  -- function lsp_highlight_document
  if client.server_capabilities.documentHighlight then
    vim.api.nvim_exec(
      [[
      augroup lsp_document_highlight
        autocmd! * <buffer>
        autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()
        autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()
      augroup END
    ]],
      false
    )
  end

  client.server_capabilities.documentFormattingProvider = true

  -- import lsp_keymaps function
  require('user.configs.nvim_keymap').lsp_keymaps()
end

local my_capabilities = {
  require('cmp_nvim_lsp').default_capabilities(),
}

for _, lsp_server in pairs(lsp_servers) do
	local opts = {
		on_attach = my_on_attatch,
    capabilities = my_capabilities,
	}

	lsp_server = vim.split(lsp_server, "@")[1]

	local require_ok, conf_opts = pcall(require, "user.configs.plugin_lsp.settings." .. lsp_server)
	if require_ok then
		opts = vim.tbl_deep_extend("force", conf_opts, opts)
	end

	lspconfig[lsp_server].setup(opts)
end

vim.lsp.set_log_level("DEBUG")

My apologize, gently ping @clason.

@clason
Copy link
Member

clason commented Feb 23, 2024

Please try the latest development version; the hover support has been extensively rewritten.

@HalmondD
Copy link
Author

Ok I change my nvim to 0.9.5, if this is not the version you want me to change to please tell me, here is the lsp.log.

@clason
Copy link
Member

clason commented Feb 23, 2024

I meant the latest nightly (which you can download as an appimage from our releases page).

@HalmondD
Copy link
Author

NVIM v0.10.0-dev-2427+geb4783fb6
Build type: RelWithDebInfo
LuaJIT 2.1.1707061634

this one?

@clason
Copy link
Member

clason commented Feb 23, 2024

Yes.

@HalmondD
Copy link
Author

HalmondD commented Feb 23, 2024

Here is the lsp.log for nvim 0.10.0 nightly. The hover still don't work on this version.

@clason
Copy link
Member

clason commented Feb 23, 2024

Works for me. So please create a minimal reproducible example (without plugins) I can test with nvim --clean -u test.lua together with a C file.

@clason
Copy link
Member

clason commented Feb 23, 2024

And your log is full of ERRORs; I'd recommend looking at and fixing those first.

@HighCommander4
Copy link

Here is the lsp.log for nvim 0.10.0 nightly. The hover still don't work on this version.

The log still shows the client sending broken client capabilities.

I'm pretty sure the issue is related to the lines mentioning capabilities in your config.

@HalmondD
Copy link
Author

HalmondD commented Feb 23, 2024

Ok the issue fix somewhat thanks to @HighCommander4, I change:

local my_capabilities = {
  require('cmp_nvim_lsp').default_capabilities(),
}

to:

local my_capabilities = require('cmp_nvim_lsp').default_capabilities()

but the format not the syntax color still don't work like I want:
The hover still don't show any comment of the function, it did have syntax highlight but it should have more information like the next image. This only happen when I'm in main.c.
image

Like this, this is when I'm in the file the function is define:
image

However it should separate the @param and the brief comment of the function. Something like how the vscode is showing:
image

The function it self:

/*
 * The function creates a GPIO driver object and initializes it with the specified device driver.
 *
 * @param dev_driver The dev_driver parameter is a pointer to a structure of type gpio_dt_spec. This
 * structure contains the necessary information for initializing the GPIO driver, such as pin
 * configurations and other settings.
 *  
 * @return a pointer to a gpio_driver_t structure.
 */
gpio_driver_t *GPIO_DRIVER_Create(const struct gpio_dt_spec *dev_driver){
    gpio_driver_t *dev = malloc(sizeof(gpio_driver_t));
    dev->driver = dev_driver;
    if (dev != NULL)
    {
        GPIO_DRIVER_Init(dev, GPIO_CONFIG_Input, GPIO_CONFIG_Output,
                    GPIO_SET, GPIO_RESET);
    }
    return dev;
}

Here is the lsp.log.

@clason
Copy link
Member

clason commented Feb 23, 2024

Works for me:

Screenshot 2024-02-23 at 10 08 53

Again, your setup is broken, as your log clearly shows. Clangd needs a project database to get cross-file information.

And we don't care what VS Code does; we implement the LSP specification, and nothing else.

@HalmondD
Copy link
Author

Thanks clason for your help.

@HighCommander4
Copy link

However it should separate the @param and the brief comment of the function. Something like how the vscode is showing:

This part is a missing feature in clangd (parsing doxygen the way vscode's default c++ language server does it). We have clangd/clangd#529 on file about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed:invalid Issues that are closed as "invalid"
Projects
None yet
Development

No branches or pull requests

4 participants