Exafunction / codeium.nvim

A native neovim extension for Codeium
MIT License
647 stars 50 forks source link

Feature request: enable/disable filetypes via config #60

Closed leitdeux closed 1 year ago

leitdeux commented 1 year ago

@jcdickinson First, thanks so much for producing this great plugin.

It would be great to have more fine-grained control over the kinds of files which should have Codeium completions either enabled or disabled. For example, it would be a good reassurance privacy-wise if .env or other filetypes which customarily contain secrets or configuration could be ignored by Codeium.

Thanks again for putting your time and effort into this project.

neoeleatic commented 1 year ago

I personally think you are absolutely right. Fortunately, nvim-cmp can be configured to selectively use completion sources by filetype. You don't need to include Codeium for every file. Just omit Codeium from the global completion sources, then additionally do something like this (in this example for Rust files):

cmp.setup.filetype('rust', {
  sources = cmp.config.sources({
    { name = 'nvim_lsp' },
    { name = 'luasnip' },
    { name = 'codeium' },
  }, {
    { name = 'buffer' },
  })
})
leitdeux commented 1 year ago

Thanks for sharing that great tip, @neoeleatic! I hadn't realized nvim-cmp had that feature. I was able to get things working just as you described. Thanks again

00sapo commented 11 months ago

I'm not happy with this solution. I use it everywhere except for latex. I don't want to rewrite the shole nvim-cmp configuration just for Codeium...

alerque commented 9 months ago

@00sapo You don't have to rewrite the whole config, you have to add about 3 lines of code to the nvim-cmp configuration where it belongs. You can save a list of completions in a variable, then copy it to another table and drop the codeium entry, then use one table as the default and the other for latex. Alternatively if you have any plugins that load just for latex, you can also add a lite to their config function that changes the cmp setup for that buffer.

As an example of the latter approach, that's what I do to exclude Codeium and many other completions from running on Ledger files (which have sensitive financial info). I have a default cmp config that includes many completions, then in a plugin config that loads only for Ledger files I setup a new limited set of sources just for those buffers.

This is how these plugins are designed to work together. If you use cmp this is how it expects things to work. This plugin is not expected to re-implement a mechanism that is already there.

marvielb commented 3 months ago

Expanding the second solution of @alerque, if you don't have a plugin that loads only for the file you want to disable, you can just create a ftplugin. It's a script that will execute if the filetype of the buffer and the script name matches. In your config, just create a dir and file like this: after/ftplugin/<filetype_you_want_to_disable>.lua and then exclude the codium in the sources like so:

require("cmp").setup.buffer({
    sources = {
        { name = "nvim_lsp" },
        { name = "vsnip" },
        { name = "buffer" },
        { name = "path" },
        -- { name = "codeium" },
    },
})