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

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

Closed
Julian opened this issue Jan 14, 2022 · 3 comments
Closed

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

Julian opened this issue Jan 14, 2022 · 3 comments

Comments

@Julian
Copy link

Julian commented Jan 14, 2022

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:

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 = {
    ['<C-b>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }),
    ['<C-f>'] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }),
    ['<C-Space>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }),
    ['<C-y>'] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `<C-y>` mapping.
    ['<C-e>'] = cmp.mapping({
      i = cmp.mapping.abort(),
      c = cmp.mapping.close(),
    }),
    ['<CR>'] = 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
Copy link
Owner

hrsh7th commented Jan 14, 2022

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

@Julian
Copy link
Author

Julian commented Jan 14, 2022

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

Julian commented Jan 14, 2022

Ah, it appears hrsh7th/cmp-cmdline#15 is maybe related (or the same issue).

@Julian Julian closed this as completed Jan 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants