Skip to content

Commit e206708

Browse files
committed
improve Codeium command
1 parent 83e531e commit e206708

3 files changed

Lines changed: 63 additions & 2 deletions

File tree

autoload/codeium.vim

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,26 @@ if !has('nvim')
1111
endif
1212
endif
1313

14+
let s:default_codeium_enabled = {
15+
\ 'help': 0,
16+
\ 'gitcommit': 0,
17+
\ 'gitrebase': 0,
18+
\ '.': 0}
19+
20+
function! codeium#Enabled() abort
21+
if !get(g:, 'codeium_enabled', v:true) || !get(b:, 'codeium_enabled', v:true)
22+
return v:false
23+
endif
24+
25+
let codeium_enabled_languages = s:default_codeium_enabled
26+
call extend(codeium_enabled_languages, get(g:, 'codeium_enabled_languages', {}))
27+
if !get(codeium_enabled_languages, &ft, 1)
28+
return v:false
29+
endif
30+
31+
return v:true
32+
endfunction
33+
1434
function! codeium#CompletionText() abort
1535
try
1636
return remove(s:, 'completion_text')
@@ -242,6 +262,10 @@ function! codeium#Complete(...) abort
242262
call timer_stop(remove(g:, '_codeium_timer'))
243263
endif
244264

265+
if !codeium#Enabled()
266+
return
267+
endif
268+
245269
let data = {
246270
\ "metadata": codeium#server#RequestMetadata(),
247271
\ "document": codeium#doc#GetCurrentDocument(),

autoload/codeium/command.vim

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ endfunction
4242

4343
let s:api_key = get(s:LoadConfig(), 'apiKey', '')
4444

45-
function! codeium#command#Auth() abort
45+
let s:commands = {}
46+
47+
function! s:commands.Auth(...) abort
4648
if !codeium#util#HasSupportedVersion()
4749
if has('nvim')
4850
let min_version = 'NeoVim 0.6'
@@ -107,6 +109,41 @@ function! codeium#command#Auth() abort
107109
endif
108110
endfunction
109111

112+
function! s:commands.Disable(...) abort
113+
let g:codeium_enabled = 0
114+
endfunction
115+
116+
function! s:commands.DisableBuffer(...) abort
117+
let b:codeium_enabled = 0
118+
endfunction
119+
120+
function! s:commands.Enable(...) abort
121+
let g:codeium_enabled = 1
122+
endfunction
123+
124+
function! s:commands.EnableBuffer(...) abort
125+
let b:codeium_enabled = 1
126+
endfunction
127+
110128
function! codeium#command#ApiKey() abort
111129
return s:api_key
112130
endfunction
131+
132+
function! codeium#command#Complete(arg, lead, pos) abort
133+
let args = matchstr(strpart(a:lead, 0, a:pos), 'C\%[odeium][! ] *\zs.*')
134+
return sort(filter(keys(s:commands), { k -> strpart(k, 0, len(a:arg)) ==# a:arg }))
135+
endfunction
136+
137+
function! codeium#command#Command(arg) abort
138+
let cmd = matchstr(a:arg, '^\%(\\.\|\S\)\+')
139+
let arg = matchstr(a:arg, '\s\zs\S.*')
140+
if !has_key(s:commands, cmd)
141+
return 'echoerr ' . string("Codeium: command '" . string(cmd) . "' not found")
142+
endif
143+
let res = s:commands[cmd](arg)
144+
if type(res) == v:t_string
145+
return res
146+
else
147+
return ''
148+
endif
149+
endfunction

plugin/codeium.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ if exists("g:loaded_codeium")
33
endif
44
let g:loaded_codeium = 1
55

6-
command! CodeiumAuth exe codeium#command#Auth()
6+
command! -nargs=? -complete=customlist,codeium#command#Complete Codeium exe codeium#command#Command(<q-args>)
77

88
if !codeium#util#HasSupportedVersion()
99
finish

0 commit comments

Comments
 (0)