hrsh7th / nvim-cmp

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

Cmp configured with cmdline breaks scoped working directories #1425

Open asmodeus812 opened 1 year ago

asmodeus812 commented 1 year 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'
Plug 'hrsh7th/cmp-cmdline'
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 = {
    ['<CR>'] = cmp.mapping.confirm({ select = true })
  },

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

                cmp.setup.cmdline(':', {
                    sources = cmp.config.sources({
                        { name = 'path' }
                    }, {
                        {
                            name = 'cmdline',
                            option = {
                                ignore_cmds = { 'Man', '!' }
                            }
                        }
                    })
                })
EOF

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

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

Description

Strange issue / interaction with scoped working directories when using cmp with cmp.cmdline.

Steps to reproduce

open nvim with provided config above. :e :tcd /home/user/.local :vsp :verbose pwd ([tabpage] /home/user/.local) - correct, the tab working directory is as it is :enew | lcd /home/user/.config :verbose pwd ([window] /home/user/.local) - whereas it should be /home/user/.config, also note verbose prints [window] in front of it which is correct.

NOTE: getcwd() also prints the wrong tab directory (tcd) instead of the local directory (lcd)

Expected behavior

The lcd should be returned as expected.

Actual behavior

The working directory returned is incorrect.

Additional context

No response

asmodeus812 commented 1 year ago

Hi, any idea on that one ?

hrsh7th commented 1 year ago

I have no idea. As far as I know, nvim-cmp does not set cwd.

asmodeus812 commented 1 year ago

Indeed, i did grep the source for 'cd' like commands, nothing popped up very strange, i have no idea what might be causing that, it could a bug upstream, that somehow interacts with some functionality of nvim cmp or cmdline but thats the best i got.

hrsh7th commented 1 year ago

I suspect nvim_parse_cmd or vim.fn.getcompletion is the culprit.

asmodeus812 commented 1 year ago

@hrsh7th not sure if this needs to get prio, but can easily cause havoc on new users, the bug is so obscure, yet it breaks a very important feature, the cwd context.

Shougo commented 1 year ago

Hm.... It seems not getcompletion() problem. Because ddc.vim command line completion works as expected.