Skip to content

Commit 78dc4e9

Browse files
committed
llama.vim : do not auto-fim when far from the end of the line [no ci]
1 parent c02981d commit 78dc4e9

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

examples/llama.vim

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ highlight llama_hl_info guifg=#77ff2f
4848
" t_max_predict_ms: max alloted time for the prediction
4949
" show_info: show extra info about the inference (0 - disabled, 1 - statusline, 2 - inline)
5050
" auto_fim: trigger FIM completion automatically on cursor movement
51+
" max_line_suffix: do not auto-trigger FIM completion if there are more than this number of characters to the right of the cursor
5152
"
5253
" ring buffer of chunks, accumulated with time upon:
5354
"
@@ -70,6 +71,7 @@ let s:default_config = {
7071
\ 't_max_predict_ms': 200,
7172
\ 'show_info': 2,
7273
\ 'auto_fim': v:true,
74+
\ 'max_line_suffix': 8,
7375
\ 'ring_n_chunks': 32,
7476
\ 'ring_chunk_size': 128,
7577
\ 'ring_scope': 1024,
@@ -124,6 +126,9 @@ function! llama#init()
124126
" gather chunks upon entering/leaving a buffer
125127
autocmd BufEnter * call timer_start(100, {-> s:pick_chunk(getline(max([1, line('.') - g:llama_config.ring_chunk_size/2]), min([line('.') + g:llama_config.ring_chunk_size/2, line('$')])), v:true, v:true)})
126128
autocmd BufLeave * call s:pick_chunk(getline(max([1, line('.') - g:llama_config.ring_chunk_size/2]), min([line('.') + g:llama_config.ring_chunk_size/2, line('$')])), v:true, v:true)
129+
130+
" gather chunk upon saving the file
131+
autocmd BufWritePost * call s:pick_chunk(getline(max([1, line('.') - g:llama_config.ring_chunk_size/2]), min([line('.') + g:llama_config.ring_chunk_size/2, line('$')])), v:true, v:true)
127132
augroup END
128133

129134
silent! call llama#fim_cancel()
@@ -225,6 +230,10 @@ function! llama#fim(is_auto) abort
225230
let s:line_cur_prefix = strpart(s:line_cur, 0, s:pos_x0)
226231
let s:line_cur_suffix = strpart(s:line_cur, s:pos_x0)
227232

233+
if a:is_auto && len(s:line_cur_suffix) > g:llama_config.max_line_suffix
234+
return
235+
endif
236+
228237
let l:prefix = ""
229238
\ . join(l:lines_prefix, "\n")
230239
\ . "\n"

0 commit comments

Comments
 (0)