aboutsummaryrefslogtreecommitdiffstats
path: root/lua/nvim-lsp-installer/installers
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2022-04-11 17:19:01 +0200
committerGitHub <noreply@github.com>2022-04-11 17:19:01 +0200
commit88f590ce0e01767bcc8dfdc862a456efde77d4a0 (patch)
tree2f5faaffa76b9147a873b2adc3286b6624144976 /lua/nvim-lsp-installer/installers
parentfix(verible): use correct unpacked directory name on Windows (#589) (diff)
downloadmason-88f590ce0e01767bcc8dfdc862a456efde77d4a0.tar
mason-88f590ce0e01767bcc8dfdc862a456efde77d4a0.tar.gz
mason-88f590ce0e01767bcc8dfdc862a456efde77d4a0.tar.bz2
mason-88f590ce0e01767bcc8dfdc862a456efde77d4a0.tar.lz
mason-88f590ce0e01767bcc8dfdc862a456efde77d4a0.tar.xz
mason-88f590ce0e01767bcc8dfdc862a456efde77d4a0.tar.zst
mason-88f590ce0e01767bcc8dfdc862a456efde77d4a0.zip
more async refactor (#587)
Diffstat (limited to 'lua/nvim-lsp-installer/installers')
-rw-r--r--lua/nvim-lsp-installer/installers/context.lua45
-rw-r--r--lua/nvim-lsp-installer/installers/std.lua13
2 files changed, 38 insertions, 20 deletions
diff --git a/lua/nvim-lsp-installer/installers/context.lua b/lua/nvim-lsp-installer/installers/context.lua
index 3dda0ab2..da002ea8 100644
--- a/lua/nvim-lsp-installer/installers/context.lua
+++ b/lua/nvim-lsp-installer/installers/context.lua
@@ -1,10 +1,11 @@
+local a = require "nvim-lsp-installer.core.async"
local log = require "nvim-lsp-installer.log"
local process = require "nvim-lsp-installer.process"
local installers = require "nvim-lsp-installer.installers"
local platform = require "nvim-lsp-installer.platform"
local fs = require "nvim-lsp-installer.fs"
local path = require "nvim-lsp-installer.path"
-local github = require "nvim-lsp-installer.core.clients.github"
+local github_client = require "nvim-lsp-installer.core.managers.github.client"
local M = {}
@@ -22,16 +23,21 @@ function M.use_github_latest_tag(repo)
return callback(true)
end
context.stdio_sink.stdout "Fetching tags from GitHub API...\n"
- github.fetch_latest_tag(repo, function(err, latest_tag)
- if err then
- context.stdio_sink.stderr(tostring(err) .. "\n")
- callback(false)
- return
+ a.run(github_client.fetch_latest_tag, function(success, result)
+ if not success then
+ context.stdio_sink.stderr(tostring(result) .. "\n")
+ return callback(false)
end
-
- context.requested_server_version = latest_tag.name
- callback(true)
- end)
+ result
+ :on_success(function(latest_tag)
+ context.requested_server_version = latest_tag.name
+ callback(true)
+ end)
+ :on_failure(function(failure)
+ context.stdio_sink.stderr(tostring(failure) .. "\n")
+ callback(false)
+ end)
+ end, repo)
end
end
@@ -51,14 +57,21 @@ function M.use_github_release(repo, opts)
return callback(true)
end
context.stdio_sink.stdout "Fetching latest release version from GitHub API...\n"
- github.fetch_latest_release(repo, opts, function(err, latest_release)
- if err then
- context.stdio_sink.stderr(tostring(err) .. "\n")
+ a.run(github_client.fetch_latest_release, function(success, result)
+ if not success then
+ context.stdio_sink.stderr(tostring(result) .. "\n")
return callback(false)
end
- context.requested_server_version = latest_release.tag_name
- callback(true)
- end)
+ result
+ :on_success(function(latest_release)
+ context.requested_server_version = latest_release.tag_name
+ callback(true)
+ end)
+ :on_failure(function(failure)
+ context.stdio_sink.stderr(tostring(failure) .. "\n")
+ callback(false)
+ end)
+ end, repo, opts)
end
end
diff --git a/lua/nvim-lsp-installer/installers/std.lua b/lua/nvim-lsp-installer/installers/std.lua
index dfa34c0d..34383810 100644
--- a/lua/nvim-lsp-installer/installers/std.lua
+++ b/lua/nvim-lsp-installer/installers/std.lua
@@ -5,10 +5,11 @@ local platform = require "nvim-lsp-installer.platform"
local installers = require "nvim-lsp-installer.installers"
local shell = require "nvim-lsp-installer.installers.shell"
local Data = require "nvim-lsp-installer.data"
-local fetch = require "nvim-lsp-installer.core.fetch"
local list_not_nil, when = Data.list_not_nil, Data.when
+local USER_AGENT = "nvim-lsp-installer (+https://github.com/williamboman/nvim-lsp-installer)"
+
local M = {}
---@param url string @The url to download.
@@ -21,12 +22,12 @@ function M.download_file(url, out_file)
process.attempt {
jobs = {
process.lazy_spawn("wget", {
- args = fetch.with_headers(fetch.HEADERS.wget, { "-nv", "-O", out_file, url }),
+ args = { "--header", ("User-Agent: %s"):format(USER_AGENT), "-nv", "-O", out_file, url },
cwd = context.install_dir,
stdio_sink = context.stdio_sink,
}),
process.lazy_spawn("curl", {
- args = fetch.with_headers(fetch.HEADERS.curl, { "-fsSL", "-o", out_file, url }),
+ args = { "-H", ("User-Agent: %s"):format(USER_AGENT), "-fsSL", "-o", out_file, url },
cwd = context.install_dir,
stdio_sink = context.stdio_sink,
}),
@@ -35,7 +36,11 @@ function M.download_file(url, out_file)
}
end,
win = shell.powershell(
- ("iwr %s -UseBasicParsing -Uri %q -OutFile %q"):format(fetch.HEADERS.iwr, url, out_file)
+ ("iwr -Headers @{'User-Agent' = '%s'} -UseBasicParsing -Uri %q -OutFile %q"):format(
+ USER_AGENT,
+ url,
+ out_file
+ )
),
}
end