p00f / clangd_extensions.nvim

Clangd's off-spec features for neovim's LSP client. Use https://sr.ht/~p00f/clangd_extensions.nvim instead
MIT License
495 stars 18 forks source link

structure of inlayHint reply changed in newest clangd 19 #55

Closed ZhiyuanLck closed 3 months ago

ZhiyuanLck commented 7 months ago

Logs reply:textDocument/inlayHint

{
  "id": 2,
  "jsonrpc": "2.0",
  "result": [
    {
      "kind": 1,
      "label": [
        {
          "value": ": std::expected<int, int>"
        }
      ],
      "paddingLeft": false,
      "paddingRight": false,
      "position": {
        "character": 10,
        "line": 9
      }
    }
  ]
}

label of reply:textDocument/inlayHint is no longer string but an array of table. https://github.com/p00f/clangd_extensions.nvim/blob/2992ba8c13c2de41f91a7c7488bf1c48bcec31fe/lua/clangd_extensions/inlay_hints.lua#L246-L265

p00f commented 7 months ago

Can you make a PR? My distro is still on LLVM 17

lseman commented 3 months ago

This worked for me:

   for _, hint in pairs(result) do 
        local text = ""
        for _, labelPart in ipairs(hint.label) do
            text = text .. labelPart.value
        end
        if hint.paddingLeft then text = " " .. text end 
        if hint.paddingRight then text = text .. " " end 
        local line = hint.position.line 
        if line == current_line - 1 or not config.options.inlay_hints.only_current_line then 
            local col = hint.position.character 
            vim.api.nvim_buf_set_extmark(bufnr, namespace, line, col, { 
                virt_text_pos = "inline", 
                virt_text = { 
                    { text, config.options.inlay_hints.highlight }, 
                }, 
                hl_mode = "combine", 
                priority = config.options.inlay_hints.priority, 
            }) 
        end 
    end
p00f commented 3 months ago

neovim 0.10 has been released for quite a while now, which has inlay hints built-in. closing this