Skip to content

Commit 35ab2d8

Browse files
feat: Add Codeium Toggle command
Add possibility to enable/disable Codeium completion
1 parent dddaee0 commit 35ab2d8

File tree

3 files changed

+54
-7
lines changed

3 files changed

+54
-7
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ your browser and pasting it into API token request.
7171
To use Codeium Chat, execute the `:Codeium Chat` command. The chat will be opened
7272
in your default browser using the xdg-open command.
7373

74+
You can globaly enable or disable Codeium Completion with `:Codeium Toggle` command.
75+
7476
## Options
7577

7678
- `config_path`: the path to the config file, used to store the API key.

lua/codeium/api.lua

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ function Server:new()
166166
local healthy = false
167167
local last_heartbeat = nil
168168
local last_heartbeat_error = nil
169+
local enabled = true
169170

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

337338
local pending_request = { 0, noop }
338339
function m.request_completion(document, editor_options, other_documents, callback)
340+
if enabled == false then
341+
return
342+
end
339343
pending_request[2](true)
340344

341345
local metadata = get_request_metadata()
@@ -529,6 +533,24 @@ function Server:new()
529533
end
530534
end
531535

536+
function m.enable()
537+
enabled = true
538+
notify.info("Codeium enabled")
539+
end
540+
541+
function m.disable()
542+
enabled = false
543+
notify.info("Codeium disabled")
544+
end
545+
546+
function m.toggle()
547+
if enabled then
548+
m.disable()
549+
else
550+
m.enable()
551+
end
552+
end
553+
532554
m.__index = m
533555
return o
534556
end

lua/codeium/init.lua

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,32 @@ function M.setup(options)
77
local health = require("codeium.health")
88
require("codeium.config").setup(options)
99

10-
local s = Server:new()
10+
M.s = Server:new()
1111
update.download(function(err)
1212
if not err then
1313
Server.load_api_key()
14-
s.start()
14+
M.s.start()
1515
end
1616
end)
17-
health.register(s.checkhealth)
17+
health.register(M.s.checkhealth)
1818

1919
vim.api.nvim_create_user_command("Codeium", function(opts)
2020
local args = opts.fargs
2121
if args[1] == "Auth" then
2222
Server.authenticate()
2323
end
2424
if args[1] == "Chat" then
25-
s.refresh_context()
26-
s.get_chat_ports()
27-
s.add_workspace()
25+
M.s.refresh_context()
26+
M.s.get_chat_ports()
27+
M.s.add_workspace()
28+
end
29+
if args[1] == "Toggle" then
30+
M.s.toggle()
2831
end
2932
end, {
3033
nargs = 1,
3134
complete = function()
32-
local commands = { "Auth" }
35+
local commands = { "Auth", "Toggle" }
3336
if require("codeium.config").options.enable_chat then
3437
commands = vim.list_extend(commands, { "Chat" })
3538
end
@@ -45,4 +48,24 @@ function M.setup(options)
4548
require("codeium.virtual_text").setup(s)
4649
end
4750

51+
--- Open Codeium Chat
52+
function M.chat()
53+
M.s.refresh_context()
54+
M.s.get_chat_ports()
55+
M.s.add_workspace()
56+
end
57+
58+
--- Toggle the Codeium plugin
59+
function M.toggle()
60+
M.s.toggle()
61+
end
62+
63+
function M.enable()
64+
M.s.enable()
65+
end
66+
67+
function M.disable()
68+
M.s.disable()
69+
end
70+
4871
return M

0 commit comments

Comments
 (0)