Exafunction / codeium.nvim

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

How do I temporarily disable/toggle Codeium? #136

Open thubtenrigzin opened 5 months ago

thubtenrigzin commented 5 months ago

Is there a way to do that withvim.g.codeium_enabled = false or a command :codeium disable or :codeium toggle? thanks

samarth-nagar commented 5 months ago

yes you can with

vim.api.nvim_set_keymap('n', '<leader>tC', ':CodeiumToggle<CR>', { noremap = true })
thubtenrigzin commented 5 months ago

yes you can with

vim.api.nvim_set_keymap('n', '<leader>tC', ':CodeiumToggle<CR>', { noremap = true })

The command :CodeiumToggle does not exist, I can't use this command. The only command I can use is :Codeium auth Did I miss something?

samarth-nagar commented 5 months ago

ohh sorry you didnt miss anything, i confused the codeium.vim with codeium.nvim you can enable or dissable in the codeium.vim which i use, you might want to give it an try

amadanmath commented 2 months ago

I have patched it in my config like this:

local Source = require("codeium.source")

local function is_codeium_enabled()
  local enabled = vim.b["codeium_enabled"]
  if enabled == nil then
    enabled = vim.g["codeium_enabled"]
    if enabled == nil then
      enabled = true -- enable by default
    end
  end
  return enabled
end

---@diagnostic disable-next-line: duplicate-set-field
function Source:is_available()
  local enabled = is_codeium_enabled()
  ---@diagnostic disable-next-line: undefined-field
  return enabled and self.server.is_healthy()
end

vim.api.nvim_set_keymap('n', '<leader>tC', '', {
  callback = function()
    local new_enabled = not is_codeium_enabled()
    vim.b["codeium_enabled"] = new_enabled
    if new_enabled then
      vim.notify("Codeium enabled in buffer")
    else
      vim.notify("Codeium disabled in buffer")
    end
  end,
  noremap = true
})

With that you can set a global default with vim.g.codeium_enabled = true/false, and override per buffer with vim.b.codeium_enabled = true/false. An example toggling keymap is included.

seanbreckenridge commented 1 month ago

Thanks for the example, I expanded on it to allow for buffer/global toggles :+1:

https://github.com/seanbreckenridge/dotfiles/blob/e513888861612330ccf50c5c796ac59786990d1c/.config/nvim/lua/plugins/codeium.lua

To overwrite the is_available, this seems to work as well, and may be more resilient incase the content of the is_available function changes in the future

        --- save reference to library available function
        local superclass_is_available = Source.is_available
        --- overwrite the library built-in is_available function
        --- so that I can disable when I want to
        ---@diagnostic disable-next-line: duplicate-set-field
        function Source:is_available()
            return is_codeium_enabled() and superclass_is_available(self)
        end