Open thubtenrigzin opened 5 months ago
yes you can with
vim.api.nvim_set_keymap('n', '<leader>tC', ':CodeiumToggle<CR>', { noremap = true })
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?
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
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.
Thanks for the example, I expanded on it to allow for buffer/global toggles :+1:
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
Is there a way to do that with
vim.g.codeium_enabled = false
or a command:codeium disable
or:codeium toggle
? thanks