aboutsummaryrefslogtreecommitdiffstats
path: root/lua/nvim-lsp-installer/installers/context.lua
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2022-01-03 15:12:53 +0100
committerGitHub <noreply@github.com>2022-01-03 15:12:53 +0100
commite8530f4059279a0d6b5e5f8891d04ffb1ade29a3 (patch)
treeb90ddf4479314af49e1eca3325262ef45e5f630d /lua/nvim-lsp-installer/installers/context.lua
parenthealth: add neovim version check (diff)
downloadmason-e8530f4059279a0d6b5e5f8891d04ffb1ade29a3.tar
mason-e8530f4059279a0d6b5e5f8891d04ffb1ade29a3.tar.gz
mason-e8530f4059279a0d6b5e5f8891d04ffb1ade29a3.tar.bz2
mason-e8530f4059279a0d6b5e5f8891d04ffb1ade29a3.tar.lz
mason-e8530f4059279a0d6b5e5f8891d04ffb1ade29a3.tar.xz
mason-e8530f4059279a0d6b5e5f8891d04ffb1ade29a3.tar.zst
mason-e8530f4059279a0d6b5e5f8891d04ffb1ade29a3.zip
write install receipts (#379)
Diffstat (limited to 'lua/nvim-lsp-installer/installers/context.lua')
-rw-r--r--lua/nvim-lsp-installer/installers/context.lua73
1 files changed, 16 insertions, 57 deletions
diff --git a/lua/nvim-lsp-installer/installers/context.lua b/lua/nvim-lsp-installer/installers/context.lua
index 7889e544..6032df18 100644
--- a/lua/nvim-lsp-installer/installers/context.lua
+++ b/lua/nvim-lsp-installer/installers/context.lua
@@ -1,66 +1,15 @@
-local Data = require "nvim-lsp-installer.data"
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 fetch = require "nvim-lsp-installer.core.fetch"
+local Data = require "nvim-lsp-installer.data"
-local M = {}
-
----@param url string @The url to fetch.
----@param callback fun(err: string|nil, raw_data: string)
-local function fetch(url, callback)
- local stdio = process.in_memory_sink()
- log.fmt_debug("Fetching URL %s", url)
- local on_exit = function(success)
- if success then
- log.fmt_debug("Successfully fetched URL %s", url)
- callback(nil, table.concat(stdio.buffers.stdout, ""))
- else
- local stderr = table.concat(stdio.buffers.stderr, "")
- log.fmt_warn("Failed to fetch URL %s. stderr=%s", url, stderr)
- callback(("Failed to fetch url %q.\n%s"):format(url, stderr), nil)
- end
- end
-
- local job_variants = {
- process.lazy_spawn("wget", {
- args = { "-nv", "-O", "-", url },
- stdio_sink = stdio.sink,
- }),
- process.lazy_spawn("curl", {
- args = { "-fsSL", url },
- stdio_sink = stdio.sink,
- }),
- }
-
- if platform.is_win then
- local ps_script = {
- "$ProgressPreference = 'SilentlyContinue'",
- ("Write-Output (iwr -UseBasicParsing -Uri %q).Content"):format(url),
- }
- table.insert(
- job_variants,
- 1,
- process.lazy_spawn("powershell.exe", {
- args = { "-NoProfile", "-Command", table.concat(ps_script, ";") },
- stdio_sink = stdio.sink,
- env = process.graft_env({}, { "PSMODULEPATH" }),
- })
- )
- end
+local list_find_first = Data.list_find_first
- process.attempt {
- jobs = job_variants,
- on_iterate = function()
- log.debug "Flushing stdout/stderr buffers."
- stdio.buffers.stdout = {}
- stdio.buffers.stderr = {}
- end,
- on_finish = on_exit,
- }
-end
+local M = {}
---@param repo string @The GitHub repo ("username/repo").
function M.use_github_latest_tag(repo)
@@ -84,13 +33,14 @@ function M.use_github_latest_tag(repo)
return
end
- local data = Data.json_decode(raw_data)
+ local data = vim.json.decode(raw_data)
if vim.tbl_count(data) == 0 then
context.stdio_sink.stderr("No tags found for GitHub repo %s.\n", repo)
callback(false)
return
end
context.requested_server_version = data[1].name
+ context.github_repo = repo
callback(true)
end)
)
@@ -123,7 +73,7 @@ function M.use_github_release(repo, opts)
return callback(false)
end
- local latest_release = Data.list_find_first(Data.json_decode(response), function(release)
+ local latest_release = list_find_first(vim.json.decode(response), function(release)
local is_stable_release = not release.prerelease and not release.draft
if opts.tag_name_pattern then
return is_stable_release and release.tag_name:match(opts.tag_name_pattern)
@@ -138,6 +88,7 @@ function M.use_github_release(repo, opts)
end
log.debug("Resolved latest version", server.name, repo, latest_release.tag_name)
context.requested_server_version = latest_release.tag_name
+ context.github_repo = repo
callback(true)
end)
)
@@ -211,6 +162,14 @@ function M.capture(fn)
end
end
+---@param fn fun(receipt_builder: InstallReceiptBuilder, ctx: ServerInstallContext)
+function M.receipt(fn)
+ return M.capture(function(ctx)
+ fn(ctx.receipt, ctx)
+ return installers.noop
+ end)
+end
+
---Update the context object.
---@param fn fun(context: ServerInstallContext): ServerInstallerFunction
function M.set(fn)