aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2022-01-02 15:11:07 +0100
committerGitHub <noreply@github.com>2022-01-02 15:11:07 +0100
commit451587d3a891e596ecfce1e9b0e77747d9d4d7cb (patch)
treee465c0f49b13bba8db7e8498c6a9e7833b6c6897 /lua
parentadd taplo (#373) (diff)
downloadmason-451587d3a891e596ecfce1e9b0e77747d9d4d7cb.tar
mason-451587d3a891e596ecfce1e9b0e77747d9d4d7cb.tar.gz
mason-451587d3a891e596ecfce1e9b0e77747d9d4d7cb.tar.bz2
mason-451587d3a891e596ecfce1e9b0e77747d9d4d7cb.tar.lz
mason-451587d3a891e596ecfce1e9b0e77747d9d4d7cb.tar.xz
mason-451587d3a891e596ecfce1e9b0e77747d9d4d7cb.tar.zst
mason-451587d3a891e596ecfce1e9b0e77747d9d4d7cb.zip
fix(taplo): use github release files instead (#377)
Diffstat (limited to 'lua')
-rw-r--r--lua/nvim-lsp-installer/installers/cargo.lua30
-rw-r--r--lua/nvim-lsp-installer/installers/context.lua33
-rw-r--r--lua/nvim-lsp-installer/servers/taplo/init.lua31
3 files changed, 54 insertions, 40 deletions
diff --git a/lua/nvim-lsp-installer/installers/cargo.lua b/lua/nvim-lsp-installer/installers/cargo.lua
deleted file mode 100644
index 8f4bf0ed..00000000
--- a/lua/nvim-lsp-installer/installers/cargo.lua
+++ /dev/null
@@ -1,30 +0,0 @@
-local process = require "nvim-lsp-installer.process"
-local path = require "nvim-lsp-installer.path"
-
-local M = {}
-
----@param crates string[] The crates to install.
-function M.crates(crates)
- ---@type ServerInstallerFunction
- return function(_, callback, ctx)
- local args = { "install", "--root", ".", "--locked" }
- if ctx.requested_server_version then
- vim.list_extend(args, { "--version", ctx.requested_server_version })
- end
- vim.list_extend(args, crates)
-
- process.spawn("cargo", {
- cwd = ctx.install_dir,
- args = args,
- stdio_sink = ctx.stdio_sink,
- }, callback)
- end
-end
-
----@param root_dir string The directory to resolve the executable from.
----@param executable string
-function M.executable(root_dir, executable)
- return path.concat { root_dir, "bin", executable }
-end
-
-return M
diff --git a/lua/nvim-lsp-installer/installers/context.lua b/lua/nvim-lsp-installer/installers/context.lua
index 99f679de..7889e544 100644
--- a/lua/nvim-lsp-installer/installers/context.lua
+++ b/lua/nvim-lsp-installer/installers/context.lua
@@ -97,8 +97,12 @@ function M.use_github_latest_tag(repo)
end
end
+---@alias UseGithubReleaseOpts {tag_name_pattern:string}
+
---@param repo string @The GitHub repo ("username/repo").
-function M.use_github_release(repo)
+---@param opts UseGithubReleaseOpts|nil
+function M.use_github_release(repo, opts)
+ opts = opts or {}
---@type ServerInstallerFunction
return function(server, callback, context)
if context.requested_server_version then
@@ -111,15 +115,29 @@ function M.use_github_release(repo)
end
context.stdio_sink.stdout "Fetching latest release version from GitHub API...\n"
fetch(
- ("https://api.github.com/repos/%s/releases/latest"):format(repo),
+ ("https://api.github.com/repos/%s/releases"):format(repo),
vim.schedule_wrap(function(err, response)
if err then
+ log.fmt_error("Failed to fetch releases for repo=%s", repo)
context.stdio_sink.stderr(tostring(err) .. "\n")
return callback(false)
end
- local version = Data.json_decode(response).tag_name
- log.debug("Resolved latest version", server.name, repo, version)
- context.requested_server_version = version
+
+ local latest_release = Data.list_find_first(Data.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)
+ end
+ return is_stable_release
+ end)
+
+ if not latest_release then
+ log.fmt_info("Failed to find latest release. repo=%s, opts=%s", repo, opts)
+ callback(false)
+ return
+ end
+ log.debug("Resolved latest version", server.name, repo, latest_release.tag_name)
+ context.requested_server_version = latest_release.tag_name
callback(true)
end)
)
@@ -128,9 +146,10 @@ end
---@param repo string @The GitHub report ("username/repo").
---@param file string|fun(resolved_version: string): string @The name of a file available in the provided repo's GitHub releases.
-function M.use_github_release_file(repo, file)
+---@param opts UseGithubReleaseOpts
+function M.use_github_release_file(repo, file, opts)
return installers.pipe {
- M.use_github_release(repo),
+ M.use_github_release(repo, opts),
function(server, callback, context)
local function get_download_url(version)
local target_file
diff --git a/lua/nvim-lsp-installer/servers/taplo/init.lua b/lua/nvim-lsp-installer/servers/taplo/init.lua
index 2aacdaef..cb4de20a 100644
--- a/lua/nvim-lsp-installer/servers/taplo/init.lua
+++ b/lua/nvim-lsp-installer/servers/taplo/init.lua
@@ -1,5 +1,12 @@
local server = require "nvim-lsp-installer.server"
-local cargo = require "nvim-lsp-installer.installers.cargo"
+local context = require "nvim-lsp-installer.installers.context"
+local platform = require "nvim-lsp-installer.platform"
+local installers = require "nvim-lsp-installer.installers"
+local Data = require "nvim-lsp-installer.data"
+local std = require "nvim-lsp-installer.installers.std"
+local path = require "nvim-lsp-installer.path"
+
+local coalesce, when = Data.coalesce, Data.when
return function(name, root_dir)
return server.Server:new {
@@ -7,9 +14,27 @@ return function(name, root_dir)
root_dir = root_dir,
languages = { "toml" },
homepage = "https://taplo.tamasfe.dev/lsp/",
- installer = cargo.crates { "taplo-lsp" },
+ installer = {
+ context.use_github_release_file(
+ "tamasfe/taplo",
+ coalesce(
+ when(platform.is_mac, "taplo-lsp-x86_64-apple-darwin-gnu.tar.gz"),
+ when(platform.is_linux and platform.arch == "x64", "taplo-lsp-x86_64-unknown-linux.tar.gz"),
+ when(platform.is_win and platform.arch == "x64", "taplo-lsp-windows-x86_64.zip")
+ ),
+ {
+ tag_name_pattern = "^release%-lsp%-",
+ }
+ ),
+ context.capture(function(ctx)
+ return installers.when {
+ unix = std.untargz_remote(ctx.github_release_file),
+ win = std.unzip_remote(ctx.github_release_file),
+ }
+ end),
+ },
default_options = {
- cmd = { cargo.executable(root_dir, "taplo-lsp"), "run" },
+ cmd = { path.concat { root_dir, "taplo-lsp" }, "run" },
},
}
end