hrsh7th / nvim-cmp

A completion plugin for neovim coded in Lua.
MIT License
7.47k stars 370 forks source link

Markdown stylization of completion documentation throws error (pylsp) #1974

Open yutanagano opened 4 days ago

yutanagano commented 4 days ago

FAQ

Announcement

Minimal reproducible full config

if has('vim_starting')
  set encoding=utf-8
endif
scriptencoding utf-8

if &compatible
  set nocompatible
endif

let s:plug_dir = expand('/tmp/plugged/vim-plug')
if !filereadable(s:plug_dir .. '/plug.vim')
  execute printf('!curl -fLo %s/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim', s:plug_dir)
end

execute 'set runtimepath+=' . s:plug_dir
call plug#begin(s:plug_dir)
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/vim-vsnip'
Plug 'neovim/nvim-lspconfig'
call plug#end()
PlugInstall | quit

" Setup global configuration. More on configuration below.
lua << EOF
local cmp = require "cmp"
cmp.setup {
  snippet = {
    expand = function(args)
      vim.fn["vsnip#anonymous"](args.body)
    end,
  },

  mapping = cmp.mapping.preset.insert({
    ['<CR>'] = cmp.mapping.confirm({ select = true })
  }),

  sources = cmp.config.sources({
    { name = "nvim_lsp" },
    { name = "buffer" },
  }),
}
EOF

lua << EOF
local capabilities = require('cmp_nvim_lsp').default_capabilities()

require'lspconfig'.pylsp.setup {
  capabilities = capabilities,
}
EOF

Description

Firstly thank you to all the maintainers and particularly hrsh7th for all your hard work. Much appreciated.

I discovered today that when using nvim-cmp with pylsp to write Python, scrolling through certain completion options will result in the error stack below. It looks like perhaps some completion options have associated markdown documentation, and its stylization during rendering is failing. I have attached a screenshot of this happening with the minimal config above.

Error executing vim.schedule lua callback: /usr/share/nvim/runtime/lua/vim/lsp/util.lua:1409: attempt to index a
 nil value                                                                                                      
stack traceback:                                                                                                
        /usr/share/nvim/runtime/lua/vim/lsp/util.lua:1409: in function 'stylize_markdown'                       
        /tmp/plugged/vim-plug/nvim-cmp/lua/cmp/view/docs_view.lua:64: in function 'open'                        
        /tmp/plugged/vim-plug/nvim-cmp/lua/cmp/view.lua:292: in function 'callback'                             
        /tmp/plugged/vim-plug/nvim-cmp/lua/cmp/utils/async.lua:138: in function ''                              
        vim/_editor.lua: in function <vim/_editor.lua:0>

image

Steps to reproduce

  1. Ensure the language server pylsp is installed (I installed via dnf on Fedora, you can also install via mason.nvim, pip, conda, or I think also homebrew) (I used pylsp v1.11.0)
  2. Create minimal Python environment (I used python3.11 on Fedora when reproducing issue)
  3. Install Pandas (For me it was pandas==2.2.2)
  4. Activate environment
  5. Open a new python file (e.g. test.py) with nvim using minimal config
  6. Write the following in the file:
import pandas as pd

x = pd.r
  1. Wait until completion options appear, then cycle through options (see screenshot above)
  2. At some point, the error shown above in the screenshot will appear

Expected behavior

I should be able to cycle through completion options without any errors, and any associated documentation with completion options should be rendered properly.

Actual behavior

At certain completion options, the rendering of the associated documentation fails (or at least this is what it looks like).

Additional context

Interestingly I can only reproduce with completions using the pandas package. I have tried cycling through some random completion options on other similar packages with long docstrings like numpy and torch, but so far they seem okay.