hrsh7th / cmp-path

nvim-cmp source for path
MIT License
628 stars 60 forks source link

Support for fnamemodified paths (specifically %:h) #32

Closed Julian closed 2 years ago

Julian commented 2 years ago

It would be great if e.g. :e %:h/foo suggested completions for the expanded %:h (i.e. the parent directory of the current file name). Right now I either get no completion suggestions when paths include %, or I get incorrectly expanded paths (where the %:h is still present after confirming the completion). A minimal init is:

```lua vim.cmd [[set runtimepath=$VIMRUNTIME]] vim.cmd [[set packpath=/tmp/nvim/site]] local package_root = '/tmp/nvim/site/pack' local install_path = package_root .. '/packer/start/packer.nvim' local function load_plugins() require('packer').startup { { 'hrsh7th/nvim-cmp', 'hrsh7th/cmp-path', 'hrsh7th/cmp-cmdline, 'wbthomason/packer.nvim', }, config = { package_root = package_root, compile_path = install_path .. '/plugin/packer_compiled.lua', }, } end if vim.fn.isdirectory(install_path) == 0 then vim.fn.system { 'git', 'clone', 'https://github.com/wbthomason/packer.nvim', install_path } load_plugins() require('packer').sync() else load_plugins() require('packer').sync() end local cmp = require'cmp' cmp.setup({ mapping = { [''] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }), [''] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }), [''] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }), [''] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `` mapping. [''] = cmp.mapping({ i = cmp.mapping.abort(), c = cmp.mapping.close(), }), [''] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. }, sources = cmp.config.sources({ { name = 'nvim_lsp' }, { name = 'path' }, { name = 'vsnip' }, -- For vsnip users. }, { { name = 'buffer' }, }) }) -- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore). cmp.setup.cmdline('/', { sources = { { name = 'buffer' } } }) -- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore). cmp.setup.cmdline(':', { sources = cmp.config.sources({ { name = 'path' } }, { { name = 'cmdline' } }) }) ```

Which seems to exhibit the first behavior (no completion suggestions). My full config exhibits the latter, I have to bisect why, but neither seems to support the expansion. Let me know if this makes sense for cmp-path! (And thanks for making cmp)

hrsh7th commented 2 years ago

I think it should be supported by cmp-cmdline source side.

Julian commented 2 years ago

Should I reopen in that repo? (Or are you saying you think this is functionality already present there? In my own config I have both enabled)

Julian commented 2 years ago

Ah, it appears https://github.com/hrsh7th/cmp-cmdline/issues/15 is maybe related (or the same issue).