Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 0 additions & 48 deletions lua/compiler-explorer/async.lua

This file was deleted.

9 changes: 5 additions & 4 deletions lua/compiler-explorer/health.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,29 @@ local ce = require("compiler-explorer.lazy")

local fn = vim.fn
local health = vim.health
local async = vim.async

local M = {}

local has_nvim_version, has_curl, is_reachable

local run_checks = ce.async.void(function()
local run_checks = async.run(function()
has_nvim_version = fn.has("nvim-0.10") > 0
has_curl = fn.executable("curl") > 0

-- TODO: proper cancellation
if not has_curl then
is_reachable = false
return
end

-- Ensure the next call is not cached.
ce.cache.delete()
is_reachable = pcall(ce.rest.languages_get)
is_reachable = async.pawait(ce.rest.languages_get)
end)

M.check = function()
run_checks()
vim.wait(2000, function() return is_reachable ~= nil end)
vim.await(run_checks)

health.start("compiler-explorer.nvim report")

Expand Down
28 changes: 16 additions & 12 deletions lua/compiler-explorer/http.lua
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
local ce = require("compiler-explorer.lazy")

local json = vim.json
local async = vim.async

local M = {}

M.get = ce.async.void(function(url)
local scheduler = async.wrap(1, vim.schedule)
local system = async.wrap(2, vim.system)
local request = async.wrap(4, vim.net.request)

M.get = function(url)
local data = ce.cache.get()[url]
if data ~= nil then return 200, data end

local args = {
"curl",
"-X",
"GET",
"-H",
Expand All @@ -18,11 +24,9 @@ M.get = ce.async.void(function(url)
url,
}

local ok, ret = pcall(ce.job.curl, args)
if not ok then error("curl executable not found") end
local ret = system(args, { text = true })

ce.async.scheduler()
if ret.exit ~= 0 then
if ret.code ~= 0 then
error(
("curl error:\ncommand: %s\nexit_code: %d\nstderr: %s"):format(
ret.cmd,
Expand All @@ -41,10 +45,11 @@ M.get = ce.async.void(function(url)
local resp, status = json.decode(split[1]), tonumber(split[2])
if status == 200 then ce.cache.get()[url] = resp end
return status, resp
end)
end

M.post = ce.async.void(function(url, body)
M.post = function(url, body)
local args = {
"curl",
"-s",
"-X",
"POST",
Expand All @@ -58,11 +63,10 @@ M.post = ce.async.void(function(url, body)
[[\n%{http_code}\n]],
url,
}
local ok, ret = pcall(ce.job.curl, args)
if not ok then error("curl executable not found") end

ce.async.scheduler()
if ret.exit ~= 0 then
local ret = system(args, { text = true })

if ret.code ~= 0 then
error(
("curl error:\n command: %s \n exit_code %d\n stderr: %s"):format(
ret.cmd,
Expand All @@ -80,6 +84,6 @@ M.post = ce.async.void(function(url, body)
end
local resp, status = json.decode(split[1]), tonumber(split[2])
return status, resp
end)
end

return M
Loading