Skip to content

Commit f7df8a0

Browse files
committed
refactor: improve codeium#Accept function and related mappings
1 parent 272c6e2 commit f7df8a0

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

autoload/codeium.vim

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,22 @@ function! s:CompletionInserter(current_completion, insert_text) abort
8787
return delete_range . insert_text . cursor_text
8888
endfunction
8989

90-
function! codeium#Accept() abort
90+
function! codeium#Accept(...) abort
9191
let current_completion = s:GetCurrentCompletionItem()
92-
return s:CompletionInserter(current_completion, current_completion is v:null ? '' : current_completion.completion.text)
92+
if current_completion is v:null
93+
let default = pumvisible() ? "\<C-N>" : "\t"
94+
if a:0 > 0 && type(a:1) == v:t_func
95+
try
96+
return call(a:1, [])
97+
catch
98+
return default
99+
endtry
100+
else
101+
return default
102+
endif
103+
else
104+
return s:CompletionInserter(current_completion, current_completion is v:null ? '' : current_completion.completion.text)
105+
endif
93106
endfunction
94107

95108
function! codeium#AcceptNextWord() abort

autoload/codeium/server.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ function! s:UnzipAndStart(status) abort
260260
call system('chmod +x ' . s:bin)
261261
endif
262262
if !filereadable(s:bin)
263-
call codeium#log#Error('Failed to download language server binary.')
263+
call codeium#log#Error('Failed to download language server binary. In '.s:bin)
264264
return ''
265265
endif
266266
call s:ActuallyStart()

plugin/codeium.vim

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,22 @@ endfunction
2020

2121
function! s:MapTab() abort
2222
if !get(g:, 'codeium_no_map_tab', v:false) && !get(g:, 'codeium_disable_bindings')
23-
imap <script><silent><nowait><expr> <Tab> codeium#Accept()
23+
let tab_map = maparg('<Tab>', 'i', 0, 1)
24+
if !has_key(tab_map, 'rhs')
25+
imap <script><silent><nowait><expr> <Tab> codeium#Accept()
26+
elseif tab_map.rhs !~# 'codeium'
27+
if tab_map.expr
28+
let tab_fallback = '{ -> ' . tab_map.rhs . ' }'
29+
else
30+
let tab_fallback = substitute(json_encode(tab_map.rhs), '<', '\\<', 'g')
31+
endif
32+
let tab_fallback = substitute(tab_fallback, '<SID>', '<SNR>' . get(tab_map, 'sid') . '_', 'g')
33+
if get(tab_map, 'noremap') || get(tab_map, 'script') || mapcheck('<Left>', 'i') || mapcheck('<Del>', 'i')
34+
exe 'imap <script><silent><nowait><expr> <Tab> codeium#Accept(' . tab_fallback . ')'
35+
else
36+
exe 'imap <silent><nowait><expr> <Tab> codeium#Accept(' . tab_fallback . ')'
37+
endif
38+
endif
2439
endif
2540
endfunction
2641

@@ -66,6 +81,7 @@ if !get(g:, 'codeium_disable_bindings')
6681
endif
6782
endif
6883

84+
call s:MapTab()
6985
call s:SetStyle()
7086

7187
let s:dir = expand('<sfile>:h:h')

0 commit comments

Comments
 (0)