Skip to content

core : fix indent termination logic #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 25 additions & 11 deletions autoload/llama.vim
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ let s:default_config = {
\ 'n_suffix': 64,
\ 'n_predict': 128,
\ 't_max_prompt_ms': 500,
\ 't_max_predict_ms': 1000,
\ 't_max_predict_ms': 500,
\ 'show_info': 2,
\ 'auto_fim': v:true,
\ 'max_line_suffix': 8,
Expand Down Expand Up @@ -196,6 +196,15 @@ function! llama#init()
if g:llama_config.ring_n_chunks > 0
call s:ring_update()
endif

" for debugging
call timer_start(100, {-> s:update_status()})
endfunction

function! s:update_status()
let &statusline = 'indent = ' . s:indent_last

call timer_start(100, {-> s:update_status()})
endfunction

" compute how similar two chunks of text are
Expand Down Expand Up @@ -397,15 +406,13 @@ function! s:fim_ctx_local(pos_x, pos_y, prev)
let l:lines_prefix = getline(max([1, a:pos_y - g:llama_config.n_prefix]), a:pos_y - 1)
let l:lines_suffix = getline(a:pos_y + 1, min([l:max_y, a:pos_y + g:llama_config.n_suffix]))

" the indentation of the current line
let l:indent = strlen(matchstr(l:line_cur, '^\s*'))

" special handling of lines full of whitespaces - start from the beginning of the line
if match(l:line_cur, '^\s*$') >= 0
let l:indent = 0

let l:line_cur_prefix = ""
let l:line_cur_suffix = ""
else
" the indentation of the current line
let l:indent = strlen(matchstr(l:line_cur, '^\s*'))
endif
else
if len(a:prev) == 1
Expand Down Expand Up @@ -515,9 +522,9 @@ function! llama#fim(pos_x, pos_y, is_auto, prev, use_cache) abort
endif

let l:t_max_predict_ms = g:llama_config.t_max_predict_ms
if empty(a:prev)
" the first request is quick - we will launch a speculative request after this one is displayed
let l:t_max_predict_ms = 250
if !empty(a:prev)
" give more time for the speculative FIM
let l:t_max_predict_ms = min([3*g:llama_config.t_max_predict_ms, 3000])
endif

" compute multiple hashes that can be used to generate a completion for which the
Expand Down Expand Up @@ -547,8 +554,10 @@ function! llama#fim(pos_x, pos_y, is_auto, prev, use_cache) abort
endfor
endif

" TODO: this might be incorrect
let s:indent_last = l:indent
" update only for non-speculative fims
if empty(a:prev)
let s:indent_last = l:indent
endif

" TODO: refactor in a function
let l:text = getline(max([1, line('.') - g:llama_config.ring_chunk_size/2]), min([line('.') + g:llama_config.ring_chunk_size/2, line('$')]))
Expand Down Expand Up @@ -877,6 +886,11 @@ function! s:fim_render(pos_x, pos_y, data)
let l:content = [""]
endif

" truncate the last line if it repeats the next line
if len(l:content) > 1 && l:content[-1] == getline(l:pos_y + 1)
let l:content = l:content[0:-2]
endif

" find the first non-empty line (strip whitespace)
let l:cmp_y = l:pos_y + 1
while l:cmp_y < line('$') && getline(l:cmp_y) =~? '^\s*$'
Expand Down