From ff760a8e94fe840b8520c2fc042319db9503a7ae Mon Sep 17 00:00:00 2001 From: Nigel Bosch Date: Wed, 2 Jul 2025 15:24:36 -0500 Subject: [PATCH] check FIM response for expected format --- autoload/llama.vim | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/autoload/llama.vim b/autoload/llama.vim index b8972be..004d738 100644 --- a/autoload/llama.vim +++ b/autoload/llama.vim @@ -685,6 +685,16 @@ function! s:fim_on_response(hashes, job_id, data, event = v:null) return endif + " ensure the response is valid JSON, starting with a fast check before full decode + if l:raw !~# '^\s*{' || l:raw !~# '\v"content"\s*:"' + return + endif + try + let l:response = json_decode(l:raw) + catch + return + endtry + " put the response in the cache for l:hash in a:hashes call s:cache_insert(l:hash, l:raw)