@@ -586,30 +586,35 @@ function! s:insert_cache(key, value)
586586 let l: hash = l: keys [rand () % len (l: keys )]
587587 call remove (g: result_cache , l: hash )
588588 endif
589- let g: result_cache [a: key ] = a: value
589+ " put just the raw content in the cache without metrics
590+ let l: parsed_value = json_decode (a: value )
591+ let l: stripped_content = get (l: parsed_value , ' content' , ' ' )
592+ let g: result_cache [a: key ] = json_encode ({' content' : l: stripped_content })
590593endfunction
591594
592595" callback that processes the FIM result from the server and displays the suggestion
593596function ! s: fim_on_stdout (hash, cache, pos_x, pos_y, is_auto, job_id, data, event = v: null )
597+ " make sure cursor position hasn't changed since fim_on_stdout was triggered
598+ if a: pos_x != col (' .' ) - 1 || a: pos_y != line (' .' )
599+ return
600+ endif
601+
602+ " show the suggestion only in insert mode
603+ if mode () !=# ' i'
604+ return
605+ endif
606+
594607 " Retrieve the FIM result from cache
595608 if a: cache && has_key (g: result_cache , a: hash )
596609 let l: raw = get (g: result_cache , a: hash )
610+ let l: is_cached = v: true
597611 else
598612 if s: ghost_text_nvim
599613 let l: raw = join (a: data , " \n " )
600614 elseif s: ghost_text_vim
601615 let l: raw = a: data
602616 endif
603- call s: insert_cache (a: hash , l: raw )
604- endif
605-
606- if a: pos_x != col (' .' ) - 1 || a: pos_y != line (' .' )
607- return
608- endif
609-
610- " show the suggestion only in insert mode
611- if mode () !=# ' i'
612- return
617+ let l: is_cached = v: false
613618 endif
614619
615620 " TODO: this does not seem to work as expected, so disabling for now
@@ -623,6 +628,10 @@ function! s:fim_on_stdout(hash, cache, pos_x, pos_y, is_auto, job_id, data, even
623628 return
624629 endif
625630
631+ if ! l: is_cached
632+ call s: insert_cache (a: hash , l: raw )
633+ endif
634+
626635 let s: pos_x = a: pos_x
627636 let s: pos_y = a: pos_y
628637
@@ -669,6 +678,11 @@ function! s:fim_on_stdout(hash, cache, pos_x, pos_y, is_auto, job_id, data, even
669678 let l: t_predict_ms = get (l: timings , ' predicted_ms' , 1 )
670679 let l: s_predict = get (l: timings , ' predicted_per_second' , 0 )
671680 endif
681+
682+ " if response was pulled from cache
683+ if l: is_cached
684+ let l: has_info = v: true
685+ endif
672686 endif
673687
674688 if len (s: content ) == 0
@@ -759,6 +773,12 @@ function! s:fim_on_stdout(hash, cache, pos_x, pos_y, is_auto, job_id, data, even
759773 \ g: llama_config .show_info == 2 ? l: prefix : ' llama.vim' ,
760774 \ l: n_cached , l: n_ctx
761775 \ )
776+ elseif l: is_cached
777+ let l: info = printf (" %s | C: %d / %d, | t: %.2f ms" ,
778+ \ g: llama_config .show_info == 2 ? l: prefix : ' llama.vim' ,
779+ \ len (keys (g: result_cache )), g: llama_config .max_cache_keys,
780+ \ 1000.0 * reltimefloat (reltime (s: t_fim_start ))
781+ \ )
762782 else
763783 let l: info = printf (" %s | c: %d / %d, r: %d / %d, e: %d, q: %d / 16 | p: %d (%.2f ms, %.2f t/s) | g: %d (%.2f ms, %.2f t/s) | t: %.2f ms" ,
764784 \ g: llama_config .show_info == 2 ? l: prefix : ' llama.vim' ,
0 commit comments