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.buf.lsp.hover don't have any syntax highlight for C file #1943

Closed
HalmondD opened this issue Feb 22, 2024 · 17 comments
Closed

vim.buf.lsp.hover don't have any syntax highlight for C file #1943

HalmondD opened this issue Feb 22, 2024 · 17 comments

Comments

@HalmondD
Copy link

HalmondD commented Feb 22, 2024

Please describe the 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

Other information

The file that I use to show the problem also have this issue with the stdio.h library, maybe or maybe not it the cause or symptom to identify the problem.
image

Logs

lsp.log

System information

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

Editor/LSP plugin:
NVIM v0.8.3 installed via appimage since Unbuntu apt don't have the latest version.

Operating system:
Ubuntu 22.04.4 LTS.

@HighCommander4
Copy link

Logs

No log.

Please attach logs, they will show whether the server is sending markdown or not.

@HalmondD
Copy link
Author

lsp.log
Hope this is the one.

@HalmondD
Copy link
Author

lsp.log
Here is the new one, with verbose, hope I set this up right.

@HalmondD HalmondD changed the title vim.buf.lsp.hover don't have any syntax highlight for C file 'vim.buf.lsp.hover' don't have any syntax highlight for C file Feb 22, 2024
@HalmondD HalmondD changed the title 'vim.buf.lsp.hover' don't have any syntax highlight for C file vim.buf.lsp.hover don't have any syntax highlight for C file Feb 22, 2024
@HalmondD HalmondD changed the title vim.buf.lsp.hover don't have any syntax highlight for C file vim.buf.lsp.hover don't have any syntax highlight for C file Feb 22, 2024
@HalmondD
Copy link
Author

gently ping @HighCommander4

@HighCommander4
Copy link

gently ping @HighCommander4

I'm sorry, but it's not reasonable to expect a 3-hour turnaround time to questions. I'll take a look when I get a chance. (I often respond within 1 day, but no guarantees.)

@HighCommander4
Copy link

What I'm seeing in the log is:

  • 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

Therefore, this is an issue on the client side. Please file it in your client's issue tracker.

@HalmondD
Copy link
Author

wait, if so how can the Lua one working fine, if the problem is the client, the Lua should not work properly too right?

@HighCommander4
Copy link

I'm not sure how the client decides what to put into the client capabilities. Maybe it's reporting different capabilities to different servers?

To be more specific about what the client should be doing: the relevant line from the log is this one, which shows the initialize message (which includes the client capabilities) that the server receives from the client:

V[17:30:30.636] <<< {"id":1,"jsonrpc":"2.0","method":"initialize","params":{"capabilities":{"1":{"textDocument":{"completion":{"completionItem":{"commitCharactersSupport":true,"deprecatedSupport":true,"insertReplaceSupport":true,"insertTextModeSupport":{"valueSet":[1,2]},"labelDetailsSupport":true,"preselectSupport":true,"resolveSupport":{"properties":["documentation","detail","additionalTextEdits","sortText","filterText","insertText","textEdit","insertTextFormat","insertTextMode"]},"snippetSupport":true,"tagSupport":{"valueSet":[1]}},"completionList":{"itemDefaults":["commitCharacters","editRange","insertTextFormat","insertTextMode","data"]},"contextSupport":true,"dynamicRegistration":false,"insertTextMode":1}}},"workspace":{"configuration":true}},"clientInfo":{"name":"Neovim","version":"0.8.3"},"initializationOptions":{},"processId":30117,"rootPath":null,"rootUri":null,"trace":"off","workspaceFolders":null}}

Formatting the JSON content of that message for readability, it's:

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "initialize",
  "params": {
    "capabilities": {
      "1": {
        "textDocument": {
          "completion": {
            "completionItem": {
              "commitCharactersSupport": true,
              "deprecatedSupport": true,
              "insertReplaceSupport": true,
              "insertTextModeSupport": {
                "valueSet": [
                  1,
                  2
                ]
              },
              "labelDetailsSupport": true,
              "preselectSupport": true,
              "resolveSupport": {
                "properties": [
                  "documentation",
                  "detail",
                  "additionalTextEdits",
                  "sortText",
                  "filterText",
                  "insertText",
                  "textEdit",
                  "insertTextFormat",
                  "insertTextMode"
                ]
              },
              "snippetSupport": true,
              "tagSupport": {
                "valueSet": [
                  1
                ]
              }
            },
            "completionList": {
              "itemDefaults": [
                "commitCharacters",
                "editRange",
                "insertTextFormat",
                "insertTextMode",
                "data"
              ]
            },
            "contextSupport": true,
            "dynamicRegistration": false,
            "insertTextMode": 1
          }
        }
      },
      "workspace": {
        "configuration": true
      }
    },
    "clientInfo": {
      "name": "Neovim",
      "version": "0.8.3"
    },
    "initializationOptions": {},
    "processId": 30117,
    "rootPath": null,
    "rootUri": null,
    "trace": "off",
    "workspaceFolders": null
  }
}

Note that under "textDocument", there is no "hover" to specify any hover-related capabilities such as markdown support.

By contrast, here is an example initialize message sent by the VSCode client:

{
  "id": 0,
  "jsonrpc": "2.0",
  "method": "initialize",
  "params": {
    "capabilities": {
      "general": {
        "markdown": {
          "parser": "marked",
          "version": "1.1.0"
        },
        "positionEncodings": [
          "utf-16"
        ],
        "regularExpressions": {
          "engine": "ECMAScript",
          "version": "ES2020"
        },
        "staleRequestSupport": {
          "cancel": true,
          "retryOnContentModified": [
            "textDocument/semanticTokens/full",
            "textDocument/semanticTokens/range",
            "textDocument/semanticTokens/full/delta"
          ]
        }
      },
      "notebookDocument": {
        "synchronization": {
          "dynamicRegistration": true,
          "executionSummarySupport": true
        }
      },
      "textDocument": {
        "callHierarchy": {
          "dynamicRegistration": true
        },
        "codeAction": {
          "codeActionLiteralSupport": {
            "codeActionKind": {
              "valueSet": [
                "",
                "quickfix",
                "refactor",
                "refactor.extract",
                "refactor.inline",
                "refactor.rewrite",
                "source",
                "source.organizeImports"
              ]
            }
          },
          "dataSupport": true,
          "disabledSupport": true,
          "dynamicRegistration": true,
          "honorsChangeAnnotations": false,
          "isPreferredSupport": true,
          "resolveSupport": {
            "properties": [
              "edit"
            ]
          }
        },
        "codeLens": {
          "dynamicRegistration": true
        },
        "colorProvider": {
          "dynamicRegistration": true
        },
        "completion": {
          "completionItem": {
            "commitCharactersSupport": true,
            "deprecatedSupport": true,
            "documentationFormat": [
              "markdown",
              "plaintext"
            ],
            "insertReplaceSupport": true,
            "insertTextModeSupport": {
              "valueSet": [
                1,
                2
              ]
            },
            "labelDetailsSupport": true,
            "preselectSupport": true,
            "resolveSupport": {
              "properties": [
                "documentation",
                "detail",
                "additionalTextEdits"
              ]
            },
            "snippetSupport": true,
            "tagSupport": {
              "valueSet": [
                1
              ]
            }
          },
          "completionItemKind": {
            "valueSet": [
              1,
              2,
              3,
              4,
              5,
              6,
              7,
              8,
              9,
              10,
              11,
              12,
              13,
              14,
              15,
              16,
              17,
              18,
              19,
              20,
              21,
              22,
              23,
              24,
              25
            ]
          },
          "completionList": {
            "itemDefaults": [
              "commitCharacters",
              "editRange",
              "insertTextFormat",
              "insertTextMode"
            ]
          },
          "contextSupport": true,
          "dynamicRegistration": true,
          "editsNearCursor": true,
          "insertTextMode": 2
        },
        "declaration": {
          "dynamicRegistration": true,
          "linkSupport": true
        },
        "definition": {
          "dynamicRegistration": true,
          "linkSupport": true
        },
        "diagnostic": {
          "dynamicRegistration": true,
          "relatedDocumentSupport": false
        },
        "documentHighlight": {
          "dynamicRegistration": true
        },
        "documentLink": {
          "dynamicRegistration": true,
          "tooltipSupport": true
        },
        "documentSymbol": {
          "dynamicRegistration": true,
          "hierarchicalDocumentSymbolSupport": true,
          "labelSupport": true,
          "symbolKind": {
            "valueSet": [
              1,
              2,
              3,
              4,
              5,
              6,
              7,
              8,
              9,
              10,
              11,
              12,
              13,
              14,
              15,
              16,
              17,
              18,
              19,
              20,
              21,
              22,
              23,
              24,
              25,
              26
            ]
          },
          "tagSupport": {
            "valueSet": [
              1
            ]
          }
        },
        "foldingRange": {
          "dynamicRegistration": true,
          "foldingRange": {
            "collapsedText": false
          },
          "foldingRangeKind": {
            "valueSet": [
              "comment",
              "imports",
              "region"
            ]
          },
          "lineFoldingOnly": true,
          "rangeLimit": 5000
        },
        "formatting": {
          "dynamicRegistration": true
        },
        "hover": {
          "contentFormat": [
            "markdown",
            "plaintext"
          ],
          "dynamicRegistration": true
        },
        "implementation": {
          "dynamicRegistration": true,
          "linkSupport": true
        },
        "inactiveRegionsCapabilities": {
          "inactiveRegions": true
        },
        "inlayHint": {
          "dynamicRegistration": true,
          "resolveSupport": {
            "properties": [
              "tooltip",
              "textEdits",
              "label.tooltip",
              "label.location",
              "label.command"
            ]
          }
        },
        "inlineValue": {
          "dynamicRegistration": true
        },
        "linkedEditingRange": {
          "dynamicRegistration": true
        },
        "onTypeFormatting": {
          "dynamicRegistration": true
        },
        "publishDiagnostics": {
          "codeDescriptionSupport": true,
          "dataSupport": true,
          "relatedInformation": true,
          "tagSupport": {
            "valueSet": [
              1,
              2
            ]
          },
          "versionSupport": false
        },
        "rangeFormatting": {
          "dynamicRegistration": true
        },
        "references": {
          "dynamicRegistration": true
        },
        "rename": {
          "dynamicRegistration": true,
          "honorsChangeAnnotations": true,
          "prepareSupport": true,
          "prepareSupportDefaultBehavior": 1
        },
        "selectionRange": {
          "dynamicRegistration": true
        },
        "semanticTokens": {
          "augmentsSyntaxTokens": true,
          "dynamicRegistration": true,
          "formats": [
            "relative"
          ],
          "multilineTokenSupport": false,
          "overlappingTokenSupport": false,
          "requests": {
            "full": {
              "delta": true
            },
            "range": true
          },
          "serverCancelSupport": true,
          "tokenModifiers": [
            "declaration",
            "definition",
            "readonly",
            "static",
            "deprecated",
            "abstract",
            "async",
            "modification",
            "documentation",
            "defaultLibrary"
          ],
          "tokenTypes": [
            "namespace",
            "type",
            "class",
            "enum",
            "interface",
            "struct",
            "typeParameter",
            "parameter",
            "variable",
            "property",
            "enumMember",
            "event",
            "function",
            "method",
            "macro",
            "keyword",
            "modifier",
            "comment",
            "string",
            "number",
            "regexp",
            "operator",
            "decorator"
          ]
        },
        "signatureHelp": {
          "contextSupport": true,
          "dynamicRegistration": true,
          "signatureInformation": {
            "activeParameterSupport": true,
            "documentationFormat": [
              "markdown",
              "plaintext"
            ],
            "parameterInformation": {
              "labelOffsetSupport": true
            }
          }
        },
        "synchronization": {
          "didSave": true,
          "dynamicRegistration": true,
          "willSave": true,
          "willSaveWaitUntil": true
        },
        "typeDefinition": {
          "dynamicRegistration": true,
          "linkSupport": true
        },
        "typeHierarchy": {
          "dynamicRegistration": true
        }
      },
      "window": {
        "showDocument": {
          "support": true
        },
        "showMessage": {
          "messageActionItem": {
            "additionalPropertiesSupport": true
          }
        },
        "workDoneProgress": true
      },
      "workspace": {
        "applyEdit": true,
        "codeLens": {
          "refreshSupport": true
        },
        "configuration": true,
        "diagnostics": {
          "refreshSupport": true
        },
        "didChangeConfiguration": {
          "dynamicRegistration": true
        },
        "didChangeWatchedFiles": {
          "dynamicRegistration": true,
          "relativePatternSupport": true
        },
        "executeCommand": {
          "dynamicRegistration": true
        },
        "fileOperations": {
          "didCreate": true,
          "didDelete": true,
          "didRename": true,
          "dynamicRegistration": true,
          "willCreate": true,
          "willDelete": true,
          "willRename": true
        },
        "inlayHint": {
          "refreshSupport": true
        },
        "inlineValue": {
          "refreshSupport": true
        },
        "semanticTokens": {
          "refreshSupport": true
        },
        "symbol": {
          "dynamicRegistration": true,
          "resolveSupport": {
            "properties": [
              "location.range"
            ]
          },
          "symbolKind": {
            "valueSet": [
              1,
              2,
              3,
              4,
              5,
              6,
              7,
              8,
              9,
              10,
              11,
              12,
              13,
              14,
              15,
              16,
              17,
              18,
              19,
              20,
              21,
              22,
              23,
              24,
              25,
              26
            ]
          },
          "tagSupport": {
            "valueSet": [
              1
            ]
          }
        },
        "workspaceEdit": {
          "changeAnnotationSupport": {
            "groupsOnLabel": true
          },
          "documentChanges": true,
          "failureHandling": "textOnlyTransactional",
          "normalizesLineEndings": true,
          "resourceOperations": [
            "create",
            "rename",
            "delete"
          ]
        },
        "workspaceFolders": true
      }
    },
    "clientInfo": {
      "name": "Visual Studio Code",
      "version": "1.85.2"
    },
    "initializationOptions": {
      "clangdFileStatus": true,
      "fallbackFlags": []
    },
    "locale": "en-us",
    "processId": 9881,
    "rootPath": "<path>",
    "rootUri": "<path>",
    "trace": "off",
    "workspaceFolders": [
      {
        "name": "<project>",
        "uri": "<path>"
      }
    ]
  }
}

Notice there is a lot more in there, including this section:

        "hover": {
          "contentFormat": [
            "markdown",
            "plaintext"
          ],
          "dynamicRegistration": true
        },

@HighCommander4
Copy link

Note that under "textDocument", there is no "hover" to specify any hover-related capabilities such as markdown support.

Actually, the contents of the initialize request seem to be broken in more fundamental ways:

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "initialize",
  "params": {
    "capabilities": {
      "1": {
        "textDocument": {
          "completion": {

What is that "1" key doing there? "textDocument" is supposed to be a direct child of "capabilities".

@HalmondD
Copy link
Author

HalmondD commented Feb 23, 2024

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")

I'm thinking could all of this problem because I copy paste config from other person, could you take a look at my attach and capabilities set up for the lsp.

@HighCommander4
Copy link

Sorry, I'm not familiar with neovim (I use the VSCode client). You are more likely to find answers about your config in the neovim issue tracker or another neovim-related forum.

@HalmondD
Copy link
Author

Ah, and I thought I come so close to fix my problem, you don't mind me copy your message to the nvim team to help me fix this issue right?

@HighCommander4
Copy link

you don't mind me copy your message to the nvim team to help me fix this issue right?

Of course, that's fine. This comment should hopefully contain all the detail a client developer needs to understand what the client is doing wrong.

@HalmondD
Copy link
Author

Thank you, and should I close this issue on this end, or just keep open until I find the solution to this?

@HighCommander4
Copy link

I will say, even without being familiar with the details of neovim's config, this line looks suspicious:

capabilities = my_capabilities,

It looks to me like it may be replacing the good/working client capabilities that neovim would normally send, with a custom one that may be broken. Maybe try to remove that line?

@HalmondD
Copy link
Author

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

It was this one, every config I see they all use that require, I just being extra so I put it under my_capabilities.

@HalmondD
Copy link
Author

Close this issue, the solution is on the nvim side.

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

2 participants