File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -710,11 +710,13 @@ function Client:ask(prompt, opts)
710710
711711 local response , err = utils .curl_post (provider .get_url (options ), args )
712712
713- if self .current_job ~= job_id then
714- return
715- end
713+ if not opts .headless then
714+ if self .current_job ~= job_id then
715+ return
716+ end
716717
717- self .current_job = nil
718+ self .current_job = nil
719+ end
718720
719721 log .debug (' Response status:' , response .status )
720722 log .debug (' Response body:\n ' , response .body )
Original file line number Diff line number Diff line change @@ -895,13 +895,11 @@ function M.ask(prompt, config)
895895 agent = selected_agent ,
896896 temperature = config .temperature ,
897897 on_progress = vim .schedule_wrap (function (token )
898- local to_print = not config .headless and token
899- if to_print and config .stream then
900- local out = config .stream (token , state .source )
901- if out ~= nil then
902- to_print = out
903- end
898+ local out = config .stream and config .stream (token , state .source ) or nil
899+ if out == nil then
900+ out = token
904901 end
902+ local to_print = not config .headless and out
905903 if to_print and to_print ~= ' ' then
906904 M .chat :append (token )
907905 end
@@ -924,13 +922,11 @@ function M.ask(prompt, config)
924922 end
925923
926924 -- Call the callback function and store to history
927- local to_store = not config .headless and response
928- if to_store and config .callback then
929- local out = config .callback (response , state .source )
930- if out ~= nil then
931- to_store = out
932- end
925+ local out = config .callback and config .callback (response , state .source ) or nil
926+ if out == nil then
927+ out = response
933928 end
929+ local to_store = not config .headless and out
934930 if to_store and to_store ~= ' ' then
935931 table.insert (client .history , {
936932 content = prompt ,
Original file line number Diff line number Diff line change @@ -334,26 +334,20 @@ end
334334function M .filetype (filename )
335335 local ft = vim .filetype .match ({ filename = filename })
336336
337- if not ft and vim .endswith (filename , ' .sh' ) then
338- return ' sh'
339- end
340-
341- -- weird TypeScript bug for vim.filetype.match
342- -- see: https://github.com/neovim/neovim/issues/27265
343- if not ft then
344- local base_name = vim .fs .basename (filename )
345- local split_name = vim .split (base_name , ' %.' )
346- if # split_name > 1 then
347- local ext = split_name [# split_name ]
348- if ext == ' ts' then
349- ft = ' typescript'
350- end
337+ if not ft or ft == ' ' then
338+ if vim .endswith (filename , ' .sh' ) then
339+ return ' sh'
340+ end
341+
342+ -- weird TypeScript bug for vim.filetype.match
343+ -- see: https://github.com/neovim/neovim/issues/27265
344+ if vim .endswith (filename , ' .ts' ) then
345+ return ' typescript'
351346 end
352- end
353347
354- if ft == ' ' then
355348 return nil
356349 end
350+
357351 return ft
358352end
359353
You can’t perform that action at this time.
0 commit comments