aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2022-03-06 12:19:39 +0100
committerWilliam Boman <william@redwill.se>2022-03-06 13:06:50 +0100
commita28297493810c30edf150cec78c02920e7112cb2 (patch)
tree165ae53a747423f990e3f79d298fe4edf74c8086 /lua
parentfix(solang): use llvm13 (diff)
downloadmason-a28297493810c30edf150cec78c02920e7112cb2.tar
mason-a28297493810c30edf150cec78c02920e7112cb2.tar.gz
mason-a28297493810c30edf150cec78c02920e7112cb2.tar.bz2
mason-a28297493810c30edf150cec78c02920e7112cb2.tar.lz
mason-a28297493810c30edf150cec78c02920e7112cb2.tar.xz
mason-a28297493810c30edf150cec78c02920e7112cb2.tar.zst
mason-a28297493810c30edf150cec78c02920e7112cb2.zip
fix(fetch): shift args to put callback arg last
Diffstat (limited to 'lua')
-rw-r--r--lua/nvim-lsp-installer/core/clients/github.lua28
-rw-r--r--lua/nvim-lsp-installer/core/fetch.lua11
2 files changed, 21 insertions, 18 deletions
diff --git a/lua/nvim-lsp-installer/core/clients/github.lua b/lua/nvim-lsp-installer/core/clients/github.lua
index 27352e8d..b78a8964 100644
--- a/lua/nvim-lsp-installer/core/clients/github.lua
+++ b/lua/nvim-lsp-installer/core/clients/github.lua
@@ -13,18 +13,18 @@ local M = {}
---@param callback fun(error: string|nil, data: GitHubRelease[]|nil)
function M.fetch_releases(repo, callback)
log.fmt_trace("Fetching GitHub releases for repo=%s", repo)
- fetch(("https://api.github.com/repos/%s/releases"):format(repo), function(err, response)
+ fetch(("https://api.github.com/repos/%s/releases"):format(repo), {
+ custom_fetcher = {
+ cmd = "gh",
+ args = { "api", ("repos/%s/releases"):format(repo) },
+ },
+ }, function(err, response)
if err then
log.fmt_error("Failed to fetch releases for repo=%s", repo)
return callback("Failed to fetch GitHub releases.", nil)
end
callback(nil, vim.json.decode(response))
- end, {
- custom_fetcher = {
- cmd = "gh",
- args = { "api", ("repos/%s/releases"):format(repo) },
- },
- })
+ end)
end
---@alias FetchLatestGithubReleaseOpts {tag_name_pattern:string}
@@ -61,18 +61,18 @@ end
---@param repo string The GitHub repo ("username/repo").
---@param callback fun(err: string|nil, tags: GitHubTag[]|nil)
function M.fetch_tags(repo, callback)
- fetch(("https://api.github.com/repos/%s/tags"):format(repo), function(err, response)
+ fetch(("https://api.github.com/repos/%s/tags"):format(repo), {
+ custom_fetcher = {
+ cmd = "gh",
+ args = { "api", ("repos/%s/tags"):format(repo) },
+ },
+ }, function(err, response)
if err then
log.fmt_error("Failed to fetch tags for repo=%s", err)
return callback("Failed to fetch tags.", nil)
end
callback(nil, vim.json.decode(response))
- end, {
- custom_fetcher = {
- cmd = "gh",
- args = { "api", ("repos/%s/tags"):format(repo) },
- },
- })
+ end)
end
---@param repo string The GitHub repo ("username/repo").
diff --git a/lua/nvim-lsp-installer/core/fetch.lua b/lua/nvim-lsp-installer/core/fetch.lua
index 9e5dc7f0..bd1a582d 100644
--- a/lua/nvim-lsp-installer/core/fetch.lua
+++ b/lua/nvim-lsp-installer/core/fetch.lua
@@ -17,11 +17,14 @@ local function with_headers(headers, args)
return result
end
+---@alias FetchCallback fun(err: string|nil, raw_data: string)
+
---@param url string The url to fetch.
----@param callback fun(err: string|nil, raw_data: string)
----@param opts {custom_fetcher: { cmd: string, args: string[] }}
-local function fetch(url, callback, opts)
- opts = opts or {}
+---@param callback_or_opts FetchCallback|{custom_fetcher: { cmd: string, args: string[] }}
+---@param callback FetchCallback
+local function fetch(url, callback_or_opts, callback)
+ local opts = type(callback_or_opts) == "table" and callback_or_opts or {}
+ callback = type(callback_or_opts) == "function" and callback_or_opts or callback
local stdio = process.in_memory_sink()
log.fmt_debug("Fetching URL %s", url)
local on_exit = function(success)