diff options
| author | Iván Giovanazzi <43305758+ivano9@users.noreply.github.com> | 2021-10-12 18:13:44 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-12 23:13:44 +0200 |
| commit | cb36bb9837e7ee2b1b1207ecde0c9c3a74a12d71 (patch) | |
| tree | a943675db8045597e40dd8f7f7e23c5b33358bcc /lua/nvim-lsp-installer/installers/context.lua | |
| parent | ui: show installer log file path in help window (diff) | |
| download | mason-cb36bb9837e7ee2b1b1207ecde0c9c3a74a12d71.tar mason-cb36bb9837e7ee2b1b1207ecde0c9c3a74a12d71.tar.gz mason-cb36bb9837e7ee2b1b1207ecde0c9c3a74a12d71.tar.bz2 mason-cb36bb9837e7ee2b1b1207ecde0c9c3a74a12d71.tar.lz mason-cb36bb9837e7ee2b1b1207ecde0c9c3a74a12d71.tar.xz mason-cb36bb9837e7ee2b1b1207ecde0c9c3a74a12d71.tar.zst mason-cb36bb9837e7ee2b1b1207ecde0c9c3a74a12d71.zip | |
add-erlangls (#144)
Co-authored-by: William Boman <william@redwill.se>
Diffstat (limited to 'lua/nvim-lsp-installer/installers/context.lua')
| -rw-r--r-- | lua/nvim-lsp-installer/installers/context.lua | 69 |
1 files changed, 38 insertions, 31 deletions
diff --git a/lua/nvim-lsp-installer/installers/context.lua b/lua/nvim-lsp-installer/installers/context.lua index e75f089d..3e36b6b5 100644 --- a/lua/nvim-lsp-installer/installers/context.lua +++ b/lua/nvim-lsp-installer/installers/context.lua @@ -1,6 +1,7 @@ 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 M = {} @@ -56,34 +57,12 @@ local function fetch(url, callback) } end -function M.github_release_file(repo, file) +function M.latest_github_release(repo) return function(server, callback, context) - local function get_download_url(version) - local target_file = type(file) == "function" and file(version) or file - if not target_file then - log.fmt_error( - "Unable to find which release file to download. server_name=%s, repo=%s", - server.name, - repo - ) - context.stdio_sink.stderr( - ( - "Could not find which release file to download. Most likely, the current operating system or architecture (%s) is not supported.\n" - ):format(platform.arch) - ) - return nil - end - - return ("https://github.com/%s/releases/download/%s/%s"):format(repo, version, target_file) - end + context.github_repo = repo if context.requested_server_version then -- User has already provided a version - don't fetch the latest version from GitHub - local download_url = get_download_url(context.requested_server_version) - if not download_url then - return callback(false) - end - context.github_release_file = download_url - callback(true) + return callback(true) else context.stdio_sink.stdout "Fetching latest release version from GitHub API...\n" fetch( @@ -94,13 +73,8 @@ function M.github_release_file(repo, file) return callback(false) end local version = Data.json_decode(response).tag_name - log.debug("Resolved latest version", server.name, version) + log.debug("Resolved latest version", server.name, repo, version) context.requested_server_version = version - local download_url = get_download_url(version) - if not download_url then - return callback(false) - end - context.github_release_file = download_url callback(true) end) ) @@ -108,6 +82,39 @@ function M.github_release_file(repo, file) end end +function M.github_release_file(repo, file) + return installers.pipe { + M.latest_github_release(repo), + function(server, callback, context) + local function get_download_url(version) + local target_file = type(file) == "function" and file(version) or file + if not target_file then + log.fmt_error( + "Unable to find which release file to download. server_name=%s, repo=%s", + server.name, + repo + ) + context.stdio_sink.stderr( + ( + "Could not find which release file to download. Most likely, the current operating system or architecture (%s) is not supported.\n" + ):format(platform.arch) + ) + return nil + end + + return ("https://github.com/%s/releases/download/%s/%s"):format(repo, version, target_file) + end + + local download_url = get_download_url(context.requested_server_version) + if not download_url then + return callback(false) + end + context.github_release_file = download_url + callback(true) + end, + } +end + function M.capture(fn) return function(server, callback, context, ...) local installer = fn(context) |
