Skip to content

Commit

Permalink
Object 89
Browse files Browse the repository at this point in the history
  • Loading branch information
luozhiya committed Jan 3, 2025
1 parent a804285 commit 9a97e14
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
27 changes: 14 additions & 13 deletions lua/fittencode/http/curl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -174,21 +174,21 @@ local function _post(url, options)
end
end

function M.post(url, opts)
local _, body = pcall(vim.fn.json_encode, opts.body)
function M.post(url, options)
local _, body = pcall(vim.fn.json_encode, options.body)
if not _ then
Fn.schedule_call(opts.on_error, { error = body })
Fn.schedule_call(options.on_error, { error = body })
return
end
if not opts.compress then
opts.body = body
_post(url, opts)
if not options.compress then
options.body = body
_post(url, options)
else
Promise:new(function(resolve)
local tmpfile = vim.fn.tempname()
vim.uv.fs_open(tmpfile, 'w', 438, function(e_open, fd)
if e_open then
Fn.schedule_call(opts.on_error, { error = e_open, })
Fn.schedule_call(options.on_error, { error = e_open, })
else
assert(fd ~= nil)
resolve({ fd = fd, tmpfile = tmpfile })
Expand All @@ -198,7 +198,7 @@ function M.post(url, opts)
return Promise:new(function(resolve)
vim.uv.fs_write(data.fd, body, -1, function(e_write, _)
if e_write then
Fn.schedule_call(opts.on_error, { error = e_write, })
Fn.schedule_call(options.on_error, { error = e_write, })
else
vim.uv.fs_close(data.fd, function(_, _) end)
resolve(data.tmpfile)
Expand All @@ -213,14 +213,15 @@ function M.post(url, opts)
local go = {
on_exit = function()
local gz = tmpfile .. '.gz'
opts.body = gz
opts.on_exit = function()
Fn.schedule_call(opts.on_exit)
local co = vim.deepcopy(options)
co.body = gz
co.on_exit = function()
Fn.schedule_call(options.on_exit)
vim.uv.fs_unlink(gz, function(_, _) end)
end
_post(url, opts)
_post(url, co)
end,
on_error = opts.on_error,
on_error = options.on_error,
}
spawn(executables.gzip, args, go)
end)
Expand Down
2 changes: 0 additions & 2 deletions lua/fittencode/inline/controller.lua
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ function Controller:triggering_completion(options)
self.generate_one_stage(gos_options)
end)
end, function()
Log.debug('Failed to get completion version')
Fn.schedule_call(options.on_error)
end):forward(function(completion)
local model = Model:new({
Expand All @@ -313,7 +312,6 @@ function Controller:triggering_completion(options)
Log.debug('New session created {}', self.session)
Fn.schedule_call(options.on_success)
end, function()
Log.debug('Failed to generate completion')
Fn.schedule_call(options.on_error)
end)
end
Expand Down

0 comments on commit 9a97e14

Please sign in to comment.