Skip to content

Commit

Permalink
feat: Add Codeium Toggle command
Browse files Browse the repository at this point in the history
Add possibility to enable/disable Codeium completion
  • Loading branch information
aliaksandr-trush committed Oct 29, 2024
1 parent dddaee0 commit 35ab2d8
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 7 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ your browser and pasting it into API token request.
To use Codeium Chat, execute the `:Codeium Chat` command. The chat will be opened
in your default browser using the xdg-open command.

You can globaly enable or disable Codeium Completion with `:Codeium Toggle` command.

## Options

- `config_path`: the path to the config file, used to store the API key.
Expand Down
22 changes: 22 additions & 0 deletions lua/codeium/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ function Server:new()
local healthy = false
local last_heartbeat = nil
local last_heartbeat_error = nil
local enabled = true

local function request(fn, payload, callback)
local url = "http://127.0.0.1:" .. port .. "/exa.language_server_pb.LanguageServerService/" .. fn
Expand Down Expand Up @@ -336,6 +337,9 @@ function Server:new()

local pending_request = { 0, noop }
function m.request_completion(document, editor_options, other_documents, callback)
if enabled == false then
return
end
pending_request[2](true)

local metadata = get_request_metadata()
Expand Down Expand Up @@ -529,6 +533,24 @@ function Server:new()
end
end

function m.enable()
enabled = true
notify.info("Codeium enabled")
end

function m.disable()
enabled = false
notify.info("Codeium disabled")
end

function m.toggle()
if enabled then
m.disable()
else
m.enable()
end
end

m.__index = m
return o
end
Expand Down
37 changes: 30 additions & 7 deletions lua/codeium/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,32 @@ function M.setup(options)
local health = require("codeium.health")
require("codeium.config").setup(options)

local s = Server:new()
M.s = Server:new()
update.download(function(err)
if not err then
Server.load_api_key()
s.start()
M.s.start()
end
end)
health.register(s.checkhealth)
health.register(M.s.checkhealth)

vim.api.nvim_create_user_command("Codeium", function(opts)
local args = opts.fargs
if args[1] == "Auth" then
Server.authenticate()
end
if args[1] == "Chat" then
s.refresh_context()
s.get_chat_ports()
s.add_workspace()
M.s.refresh_context()
M.s.get_chat_ports()
M.s.add_workspace()
end
if args[1] == "Toggle" then
M.s.toggle()
end
end, {
nargs = 1,
complete = function()
local commands = { "Auth" }
local commands = { "Auth", "Toggle" }
if require("codeium.config").options.enable_chat then
commands = vim.list_extend(commands, { "Chat" })
end
Expand All @@ -45,4 +48,24 @@ function M.setup(options)
require("codeium.virtual_text").setup(s)
end

--- Open Codeium Chat
function M.chat()
M.s.refresh_context()
M.s.get_chat_ports()
M.s.add_workspace()
end

--- Toggle the Codeium plugin
function M.toggle()
M.s.toggle()
end

function M.enable()
M.s.enable()
end

function M.disable()
M.s.disable()
end

return M

0 comments on commit 35ab2d8

Please sign in to comment.