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

Turn off cmp in TelescopePrompt buffer? #60

Closed
brandoncc opened this issue Aug 24, 2021 · 27 comments
Closed

Turn off cmp in TelescopePrompt buffer? #60

brandoncc opened this issue Aug 24, 2021 · 27 comments

Comments

@brandoncc
Copy link
Contributor

Hello,

Thanks for this awesome plugin. I could never get tab to navigate the menu compe and it does it out of the box with cmp. That alone is worth switching!

I apologize if this is the wrong place to ask, but is there an easy way to turn off compe suggestions while in a TelescopePrompt buffer?

Thanks

@uga-rosa
Copy link
Contributor

uga-rosa commented Aug 25, 2021

By default, when buftype is prompt, no completion will be shown.

ng = ng or vim.api.nvim_buf_get_option(0, 'buftype') == 'prompt'

@hrsh7th
Copy link
Owner

hrsh7th commented Aug 25, 2021

@uga-rosa is correct.

@brandoncc I think nvim-cmp already disabled if the buftype is `prompt.

So I want a more detailed explanation of this problem.

@brandoncc
Copy link
Contributor Author

Hello,

Thanks for the responses from both of you. As mentioned before, it is a TelescopePrompt buffer, not a prompt buffer. I promise the completion menu is popping up right now :-)

nvim-cmp

So, is there an easy way to turn it off?

@brandoncc
Copy link
Contributor Author

@abzcoding
Copy link
Contributor

abzcoding commented Aug 25, 2021

Hello,

Thanks for the responses from both of you. As mentioned before, it is a TelescopePrompt buffer, not a prompt buffer. I promise the completion menu is popping up right now :-)

So, is there an easy way to turn it off?

that seems to be sourced from tabnine ( due to the percentage showing), wanted to mention cause that might be related

@hrsh7th hrsh7th removed the no-info label Aug 25, 2021
@hrsh7th
Copy link
Owner

hrsh7th commented Aug 25, 2021

It seems to telescope add buftype=prompt if the prompt_prefix has provided.
https://github.com/nvim-telescope/telescope.nvim/blob/4f91ffcbab427503b1e3ebfb02e47400d6eb561a/lua/telescope/pickers.lua#L338

@hrsh7th
Copy link
Owner

hrsh7th commented Aug 25, 2021

@brandoncc You can set up like this.

autocmd FileType TelescopePrompt lua require'cmp'.setup.buffer {
\   completion = { autocomplete = false }
\ }

@hrsh7th hrsh7th closed this as completed Aug 25, 2021
@brandoncc
Copy link
Contributor Author

Ah, so the completion setting is what I need to change. Thank you! I tried messing with completeopt in a similar autocmd, but it didn't help.

@brandoncc
Copy link
Contributor Author

I'm getting this error:

image

If I change it to autocomplete = {} the error goes away but the completion menu still pops up. I also tried changing it to nil since the docs say it can be nil, but it changes the error to "expected table, got nil".

@hrsh7th
Copy link
Owner

hrsh7th commented Aug 25, 2021

Could you update nvim-cmp to the latest?

@brandoncc
Copy link
Contributor Author

Thanks, that fixed the error above but the menu still shows up. At this point, I have added all of these:

autocmd FileType TelescopePrompt lua print('In TelP')

autocmd FileType TelescopePrompt lua require'cmp'.setup.buffer {
\   completion = { autocomplete = false }
\ }

autocmd FileType TelescopePrompt lua require'cmp_tabnine.config'.setup {
\    max_lines = 0
\    max_num_results = 0
\ }

The menu still pops up, but as @abzcoding mentioned, they only seem to be sourced from tabnine for some reason. I thought the code might not be executing, so I added the print call. The message does show up in my :messages, so I know the code is executing.

I also tried hacking around the issue like this:

autocmd FileType TelescopePrompt set ft=prompt

as well as

autocmd FileType TelescopePrompt lua require'cmp'.setup.buffer {
\   completion = { sources = {} }
\ }

Those didn't fix the issue either.

If it helps, here is my config:

" Setup global configuration. More on configuration below.
lua <<EOF
  local cmp = require('cmp')
  cmp.setup {
    snippet = {
      expand = function(args)
        -- You must install `vim-vsnip` if you use the following as-is.
        vim.fn['vsnip#anonymous'](args.body)
      end
    },

    -- You must set mapping if you want.
    mapping = {
      ['<C-p>'] = cmp.mapping.select_prev_item(),
      ['<C-n>'] = cmp.mapping.select_next_item(),
      ['<C-d>'] = cmp.mapping.scroll_docs(-4),
      ['<C-f>'] = cmp.mapping.scroll_docs(4),
      ['<C-Space>'] = cmp.mapping.complete(),
      ['<C-e>'] = cmp.mapping.close(),
      ['<CR>'] = cmp.mapping.confirm({
        behavior = cmp.ConfirmBehavior.Insert,
        select = true,
      })
    },

    -- You should specify your *installed* sources.
    sources = {
      { name = 'buffer' },
      { name = 'nvim_lsp' },
      { name = 'cmp-tabnine' },
      { name = 'path' },
      { name = 'calc' }
    },
  }
EOF

" Setup buffer configuration (nvim-lua source only enables in Lua filetype).
autocmd FileType lua lua require'cmp'.setup.buffer {
\   sources = {
\     { name = 'buffer' },
\     { name = 'nvim_lua' },
\   },
\ }

autocmd FileType TelescopePrompt lua print('In TelP')

autocmd FileType TelescopePrompt lua require'cmp'.setup.buffer {
\   completion = { autocomplete = false }
\ }

autocmd FileType TelescopePrompt lua require'cmp_tabnine.config'.setup {
\    max_lines = 0
\    max_num_results = 0
\ }

@brandoncc
Copy link
Contributor Author

Even with the configuration pasted at the end of my last comment, I just experienced path completions in the telescope prompt.

@hrsh7th hrsh7th reopened this Aug 25, 2021
@uga-rosa
Copy link
Contributor

buftype is NOT filetype. Please see :h buftype

@brandoncc
Copy link
Contributor Author

I'm not sure anyone thought buftype and filetype were the same?

@uga-rosa
Copy link
Contributor

So, why this?

I also tried hacking around the issue like this:

autocmd FileType TelescopePrompt set ft=prompt

You have replaced filetype from TelescopePrompt to prompt...

@brandoncc
Copy link
Contributor Author

Ha, touché! I missed the fact that buftype was ever mentioned, and we just thinking about filetype. I didn't understand why you randomly said buftype is not filetype. Your comment makes a lot more sense now 👍

I'll try that hack again with it fixed to set buftype instead of filetype.

@brandoncc
Copy link
Contributor Author

autocmd FileType TelescopePrompt set bt=prompt

This didn't help.

@uga-rosa
Copy link
Contributor

We told that cmp looks at the buftype, not filetype, and disables itself by default. And telescope have done this setting properly.
I feel like there is a problem with the source implementation...

@brandoncc
Copy link
Contributor Author

I got completions for multiple sources when I have tried everything to turn it off. Thanks for your time, I think I'll move on at this point.

@brandoncc
Copy link
Contributor Author

I updated today and this is fixed, thank you!

@brandoncc
Copy link
Contributor Author

Actually, the problem still happens... I didn't have cmp-tabnine configured right so it wasn't working at all. One day I'll figure out how to fix it....

@hrsh7th
Copy link
Owner

hrsh7th commented Sep 16, 2021

@poctek
Copy link

poctek commented Oct 27, 2021

Try this https://github.com/hrsh7th/nvim-cmp#how-to-disable-nvim-cmp-on-the-specific-buffer

This one helped me. Thank you!

@palcalde
Copy link

This works:

cmp.setup({
	enabled = 
	  function ()
		     buftype = vim.api.nvim_buf_get_option(0, "buftype")
		     if buftype == "prompt" then return false end
          end
})

@dmartzol
Copy link

dmartzol commented Sep 15, 2022

for me the following worked a bit better:

cmp.setup({
    enabled = function ()
        buftype = vim.api.nvim_buf_get_option(0, "buftype")
        if buftype == "prompt" then return false end
        return true
    end
})

@palcalde
Copy link

palcalde commented Sep 15, 2022

for me the following worked a bit better:

cmp.setup({
    enabled = function ()
        buftype = vim.api.nvim_buf_get_option(0, "buftype")
        if buftype == "prompt" then return false end
        return true
    end
})

I also found annoying that cmp kept showing when writing comments in code, I disabled it as well using treesitter.

@asmodeus812
Copy link

asmodeus812 commented Nov 20, 2022

I also came across this issue, where in the telescope buffer we will get the cmp mappings on top of the telescope ones, and for telescope for example will get overriden by the cmp . There has been a change in the default method some 9 monts ago here - 801a9f9#diff-df823ce65cc2c7da6baceae5eeff942546e46b84c95571d897f0ba2f9f0385dd

Note that this also happens only in nvim 0.8, in 0.7 it works fine, which is weird, maybe something is broken upstream

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

8 participants