folke / noice.nvim

💥 Highly experimental plugin that completely replaces the UI for messages, cmdline and the popupmenu.
Apache License 2.0
4.29k stars 100 forks source link

bug: completion item documentation tables with no elements result in "Unknown markup" notification spam #819

Closed emilnymann closed 3 months ago

emilnymann commented 4 months ago

Did you check docs and existing issues?

Neovim version (nvim -v)

0.11.0-dev (nightly from apt PPA)

Operating system/version

Ubuntu 24.04 LTS

Describe the bug

Using a language server that does (apparently) not provide documentation causes an error notification every time the cmp (code completion) changes. The error is thrown in lua/noice/lsp/format.lua on line 33, since the format_markdown function only handles list-type tables.

This is occuring for me in an .sql file with the sqls LSP attached. I've inspected item.documentation from lua/noice/lsp/override's setup function, and concluded that it's an empty table. I don't know what's a good way to handle this from your point of view, hence the issue and not a pull request. If you can provide some thoughts on the issue I would be happy to fix it.

I also realise this is, at its core, an issue with the LSP not providing said documentation, but I don't think trying to format it every time and throwing an error is the endgame for that kind of case.

Steps To Reproduce

  1. Open an .sql file buffer
  2. Attach sqls LSP (installed with Mason, defaults-configured with lspconfig and mason_lspconfig)
  3. Start typing something like CREATE TABLE and see that the LSP does provide code completion suggestions, but also see a red error notification appear for every letter you type.

Expected Behavior

Graceful(?) handling of unprovided documentation data.

Repro

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath, })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  "folke/tokyonight.nvim",
  "folke/noice.nvim",
  -- add any other plugins here
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here
rodhash commented 4 months ago

this has been merged right? .. not sure why but I'm still getting this error.. I think commit f119045 is the one related to this, right? I'm currently using latest versions:

nvim v0.11.0-dev-158+g05435a915 noice 69c6ad5

folke commented 4 months ago

@rodhash when do you get this? Can you give me the steps to reproduce?

Gabriel2409 commented 3 months ago

I have the same issue when using nvim-dbee with cmp-dbee.

When I start type SELECT * FROM I get the following error:

   Error  12:07:35 msg_show.lua_error Error executing vim.schedule lua callback: ...im/nvim-lazyvim/lazy/noice.nvim/lua/noice/lsp/format.lua:35: Unknown markup {
  kind = "Markdown",
  value = "```\nname: free\ntype: keyword\n```"
}
stack traceback:
    [C]: in function 'error'
    ...im/nvim-lazyvim/lazy/noice.nvim/lua/noice/lsp/format.lua:35: in function 'format_markdown'
    .../nvim-lazyvim/lazy/noice.nvim/lua/noice/lsp/override.lua:17: in function 'get_documentation'
    ...im/nvim-lazyvim/lazy/nvim-cmp/lua/cmp/view/docs_view.lua:48: in function 'open'
    ...l/share/nvim/nvim-lazyvim/lazy/nvim-cmp/lua/cmp/view.lua:292: in function 'callback'
    .../nvim/nvim-lazyvim/lazy/nvim-cmp/lua/cmp/utils/async.lua:138: in function ''
    vim/_editor.lua: in function <vim/_editor.lua:0>
   Error  12:07:35 msg_show.lua_error Error executing vim.schedule lua callback: ...im/nvim-lazyvim/lazy/noice.nvim/lua/noice/lsp/format.lua:35: Unknown markup {
  kind = "Markdown",
  value = "```\nname: from\ntype: keyword\n```"
}

To investigate, i added print statements before line 35 in format.lua.

type(content) -- table
content.kind -- keyword
content.value -- "```\nname: free\ntype: keyword\n```"
content.language -- nil 
type(next(content)) -- string

We could fix the issue by adding

elseif type(content) == "table" and type(next(content)) == "string" then
      goto continue

or we could just remove
error("Unknown markup " .. vim.inspect(content)) but I am not sure what the correct course of action is here.

Here is my plugin config if you want to reproduce the issue.

-- plugins/dbee.lua
return {
  'kndndrj/nvim-dbee',
  dependencies = {
    'MunifTanjim/nui.nvim',
  },
  build = function()
    -- Install tries to automatically detect the install method.
    -- if it fails, try calling it with one of these parameters:
    --    "curl", "wget", "bitsadmin", "go"
    require('dbee').install()
  end,
  opts = {},
}

-- plugins/dbee-cmp.lua
return {
  'hrsh7th/nvim-cmp',
  dependencies = {
    {
      'MattiasMTS/cmp-dbee',
      -- commit = '0feabc1',
      dependencies = {
        { 'kndndrj/nvim-dbee' },
      },
      -- ft = 'sql', -- optional but good to have
      -- opts = {}, -- needed
      config = function()
        require('cmp-dbee').setup()
      end,
    },
  },
  opts = function(_, opts)
    table.insert(opts.sources, { name = 'cmp-dbee' })
  end,
}
emilnymann commented 3 months ago

@Gabriel2409 what version of noice are you using? #820 was merged and does almost the same thing as your suggestion, and it fixed my instance with sqls but of course I didn't check with other LSP implementations for SQL.