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

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

Closed
3 tasks done
emilnymann opened this issue May 23, 2024 · 4 comments · Fixed by #858
Closed
3 tasks done
Labels
bug Something isn't working

Comments

@emilnymann
Copy link
Contributor

Did you check docs and existing issues?

  • I have read all the noice.nvim docs
  • I have searched the existing issues of noice.nvim
  • I have searched the existing issues of plugins related to this issue

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
Copy link

rodhash commented Jun 3, 2024

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
Copy link
Owner

folke commented Jun 3, 2024

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

@Gabriel2409
Copy link

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
Copy link
Contributor Author

@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.

@folke folke closed this as completed in 59e633f Jun 16, 2024
adoyle-h added a commit to adoyle-h/noice.nvim that referenced this issue Jun 18, 2024
* up/main: (76 commits)
  fix(mini): update view options of underlying view. See folke#685
  chore(build): auto-generate vimdoc
  fix(scrollbar): fix scrollbar. Fixes folke#759. Fixes folke#727
  chore(main): release 4.2.2 (folke#858)
  chore(build): auto-generate vimdoc
  fix(hover): ignore invalid markup. Fixes folke#819
  fix(msg): clear existing confirm messages. Fixes folke#302
  chore(main): release 4.2.1 (folke#857)
  chore(build): auto-generate vimdoc
  fix(cmdline): only use cmdline_input for short prompts without newline. Fixes folke#856
  chore(main): release 4.2.0 (folke#850)
  chore(build): auto-generate vimdoc
  fix(cmdline): allow overriding title hl
  fix(cmdline): reset title when needed
  chore(build): auto-generate vimdoc
  fix(nui): redo layout when border changes
  fix(cmdline_input): put in same position as cmdline_popup
  feat(cmdline): icon for cmdline input
  fix(fzf): message id
  feat(cmdline): use cmdline prompt as title. Noice is now great for vim.ui.input out of the box
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants