Skip to content

Commit 7a4b820

Browse files
committed
fim: apply fuzzy backtrack offset to all completions
Store the original (untrimmed) cached responses and the fuzzy backtrack offset. At render time, trim ALL completions by the same offset so that cycling through alternatives shows correctly trimmed suggestions instead of the full untrimmed content. Assisted-by: llama.cpp:local pi
1 parent 61f4320 commit 7a4b820

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

autoload/llama.vim

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,8 @@ function! s:fim_try_hint(pos_x, pos_y)
10091009
" Check if the completion is cached (and update LRU order)
10101010
let l:raw = s:cache_get(l:hash)
10111011
let l:selected = 0
1012+
let l:fuzzy_offset = -1
1013+
let l:fuzzy_typed = ''
10121014

10131015
" ... or if there is a cached completion nearby (128 characters behind)
10141016
" Looks at the previous 128 characters to see if a completion is cached. If one is found at (x,y)
@@ -1047,14 +1049,12 @@ function! s:fim_try_hint(pos_x, pos_y)
10471049
continue
10481050
endif
10491051

1050-
" build a modified responses list with the matched completion trimmed
1051-
let l:modified = copy(l:responses)
1052-
let l:modified[c_idx] = extend(copy(l:responses[c_idx]), {'content': l:remainder})
1053-
10541052
if len(l:remainder) > l:best_len
10551053
let l:best_len = len(l:remainder)
1056-
let l:best_raw = json_encode(l:modified)
1054+
let l:best_raw = l:response_cached " store original (untrimmed)
10571055
let l:best_selected = c_idx
1056+
let l:fuzzy_offset = i
1057+
let l:fuzzy_typed = l:removed
10581058
endif
10591059
endfor
10601060
endif
@@ -1073,11 +1073,20 @@ function! s:fim_try_hint(pos_x, pos_y)
10731073
let l:selected = 0
10741074
endif
10751075

1076+
" apply fuzzy offset: trim first (fuzzy_offset + 1) chars from each completion
10761077
let l:completions = []
10771078
for l:resp in l:responses
1078-
call add(l:completions, split(get(l:resp, 'content', ''), "\n", 1))
1079+
let l:content = get(l:resp, 'content', '')
1080+
if l:fuzzy_offset >= 0 && len(l:content) > l:fuzzy_offset
1081+
let l:content = l:content[l:fuzzy_offset + 1:]
1082+
endif
1083+
call add(l:completions, split(l:content, "\n", 1))
10791084
endfor
10801085

1086+
" store fuzzy info so cycling applies the same trimming
1087+
let s:fim_data['fuzzy_offset'] = l:fuzzy_offset
1088+
let s:fim_data['fuzzy_typed'] = l:fuzzy_typed
1089+
10811090
call s:fim_render(l:pos_x, l:pos_y, l:completions, l:selected, l:responses)
10821091

10831092
" run async speculative FIM in the background for this position

0 commit comments

Comments
 (0)