Skip to content

Commit a31ff44

Browse files
authored
Feat: Add command for toggling Codeium (Exafunction#283)
* Feat: Add command for toggling Codeium The newly added CodeiumToggle command makes it possible to achieve the same effects as the CodeiumEnable and CodeiumDisable commands but with a single keymap. * Feat: Add Toggle subcommand to the Codeium command --------- Co-authored-by: Jakub Bortlík <jakub.bortlik@phonexia.com>
1 parent 949f625 commit a31ff44

4 files changed

Lines changed: 34 additions & 2 deletions

File tree

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@ variable:
123123
let g:codeium_enabled = v:false
124124
```
125125

126+
or in Neovim:
127+
128+
```vim
129+
vim.g.codeium_enabled = false
130+
```
131+
126132
Instead, if you would like to just disable the automatic triggering of
127133
completions:
128134

@@ -132,8 +138,9 @@ let g:codeium_manual = v:true
132138

133139
### Show Codeium status in statusline
134140

135-
Codeium status can be generated by calling `codeium#GetStatusString()` function.
136-
It produce 3 char long string with status:
141+
Codeium status can be generated by calling the `codeium#GetStatusString()` function. In
142+
Neovim, you can use `vim.api.nvim_call_function("codeium#GetStatusString", {})` instead.
143+
It produces a 3 char long string with Codeium status:
137144
- `'3/8'` - third suggestion out of 8
138145
- `'0'` - Codeium returned no suggestions
139146
- `'*'` - waiting for Codeium response

autoload/codeium/command.vim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,14 @@ function! s:commands.EnableBuffer(...) abort
163163
call codeium#command#StartLanguageServer()
164164
endfunction
165165

166+
function! s:commands.Toggle(...) abort
167+
if exists('g:codeium_enabled') && g:codeium_enabled == v:false
168+
call s:commands.Enable()
169+
else
170+
call s:commands.Disable()
171+
endif
172+
endfunction
173+
166174
function! codeium#command#ApiKey() abort
167175
if s:api_key == ''
168176
echom 'Codeium: No API key found; maybe you need to run `:Codeium Auth`?'

doc/codeium.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ COMMANDS *:Codeium*
2626
:Codeium EnableBuffer Re-enable Codeium completions in the current
2727
buffer after running :Codeium DisableBuffer
2828

29+
*:Codeium_Toggle*
30+
:Codeium Toggle Enable Codeium completions if they are disabled.
31+
Disable Codeium completions if they are enabled. Does
32+
NOT enable completions for current buffer, if they are
33+
disabled with :Codeium DisableBuffer. However, still
34+
affects other buffers.
2935

3036
OPTIONS *codeium-options*
3137

plugin/codeium.vim

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,16 @@ endfun
8383

8484
command! CodeiumDisable :silent! call CodeiumDisable()
8585

86+
function! CodeiumToggle()
87+
if exists('g:codeium_enabled') && g:codeium_enabled == v:false
88+
call CodeiumEnable()
89+
else
90+
call CodeiumDisable()
91+
endif
92+
endfunction
93+
94+
command! CodeiumToggle :silent! call CodeiumToggle()
95+
8696
function! CodeiumManual() " Disable the automatic triggering of completions
8797
let g:codeium_manual = v:true
8898
endfun
@@ -99,3 +109,4 @@ command! CodeiumAuto :silent! call CodeiumAuto()
99109
:amenu Plugin.Codeium.Disable\ \Codeium\ \(\:CodeiumDisable\) :call CodeiumDisable() <Esc>
100110
:amenu Plugin.Codeium.Manual\ \Codeium\ \AI\ \Autocompletion\ \(\:CodeiumManual\) :call CodeiumManual() <Esc>
101111
:amenu Plugin.Codeium.Automatic\ \Codeium\ \AI\ \Completion\ \(\:CodeiumAuto\) :call CodeiumAuto() <Esc>
112+
:amenu Plugin.Codeium.Toggle\ \Codeium\ \(\:CodeiumToggle\) :call CodeiumToggle() <Esc>

0 commit comments

Comments
 (0)