From 88f590ce0e01767bcc8dfdc862a456efde77d4a0 Mon Sep 17 00:00:00 2001 From: William Boman Date: Mon, 11 Apr 2022 17:19:01 +0200 Subject: more async refactor (#587) --- lua/nvim-lsp-installer/core/async/uv.lua | 2 +- lua/nvim-lsp-installer/core/clients/crates.lua | 23 ----- lua/nvim-lsp-installer/core/clients/eclipse.lua | 12 +-- lua/nvim-lsp-installer/core/clients/github.lua | 92 -------------------- lua/nvim-lsp-installer/core/fetch.lua | 98 +++++----------------- lua/nvim-lsp-installer/core/installer/context.lua | 3 +- .../core/managers/cargo/client.lua | 14 ++++ .../core/managers/cargo/init.lua | 32 ++++--- lua/nvim-lsp-installer/core/managers/gem/init.lua | 4 +- .../core/managers/github/client.lua | 88 +++++++++++++++++++ lua/nvim-lsp-installer/core/managers/npm/init.lua | 2 +- .../core/managers/powershell/init.lua | 46 ++++++++++ lua/nvim-lsp-installer/core/managers/std/init.lua | 44 ++++++++++ lua/nvim-lsp-installer/installers/context.lua | 45 ++++++---- lua/nvim-lsp-installer/installers/std.lua | 13 ++- .../jobs/outdated-servers/github_release_file.lua | 28 +++---- .../jobs/outdated-servers/github_tag.lua | 29 +++---- .../jobs/outdated-servers/init.lua | 2 +- .../jobs/outdated-servers/jdtls.lua | 7 +- lua/nvim-lsp-installer/jobs/version-check/init.lua | 2 +- lua/nvim-lsp-installer/servers/dartls/init.lua | 16 +--- lua/nvim-lsp-installer/servers/efm/init.lua | 3 +- .../servers/golangci_lint_ls/init.lua | 3 +- lua/nvim-lsp-installer/servers/gopls/init.lua | 3 +- lua/nvim-lsp-installer/servers/groovyls/init.lua | 31 +++---- .../servers/haxe_language_server/init.lua | 28 +++---- lua/nvim-lsp-installer/servers/jdtls/init.lua | 7 +- lua/nvim-lsp-installer/servers/jsonnet_ls/init.lua | 5 +- lua/nvim-lsp-installer/servers/mm0_ls/init.lua | 24 ++---- lua/nvim-lsp-installer/servers/nimls/init.lua | 23 ++--- lua/nvim-lsp-installer/servers/scry/init.lua | 40 ++++----- lua/nvim-lsp-installer/servers/solargraph/init.lua | 3 +- lua/nvim-lsp-installer/servers/sorbet/init.lua | 3 +- lua/nvim-lsp-installer/servers/sourcekit/init.lua | 16 +--- lua/nvim-lsp-installer/servers/sourcery/init.lua | 3 +- lua/nvim-lsp-installer/servers/spectral/init.lua | 34 ++++---- lua/nvim-lsp-installer/servers/sqls/init.lua | 3 +- .../servers/theme_check/init.lua | 3 +- .../ui/status-win/components/settings-schema.lua | 2 +- 39 files changed, 404 insertions(+), 432 deletions(-) delete mode 100644 lua/nvim-lsp-installer/core/clients/crates.lua delete mode 100644 lua/nvim-lsp-installer/core/clients/github.lua create mode 100644 lua/nvim-lsp-installer/core/managers/cargo/client.lua create mode 100644 lua/nvim-lsp-installer/core/managers/github/client.lua create mode 100644 lua/nvim-lsp-installer/core/managers/powershell/init.lua create mode 100644 lua/nvim-lsp-installer/core/managers/std/init.lua (limited to 'lua') diff --git a/lua/nvim-lsp-installer/core/async/uv.lua b/lua/nvim-lsp-installer/core/async/uv.lua index a2249be9..a25aeb0b 100644 --- a/lua/nvim-lsp-installer/core/async/uv.lua +++ b/lua/nvim-lsp-installer/core/async/uv.lua @@ -1,6 +1,6 @@ local a = require "nvim-lsp-installer.core.async" ----@type Record +---@type table local M = setmetatable({}, { __index = function(_, method) ---@async diff --git a/lua/nvim-lsp-installer/core/clients/crates.lua b/lua/nvim-lsp-installer/core/clients/crates.lua deleted file mode 100644 index f12a8356..00000000 --- a/lua/nvim-lsp-installer/core/clients/crates.lua +++ /dev/null @@ -1,23 +0,0 @@ -local fetch = require "nvim-lsp-installer.core.fetch" -local M = {} - ----@alias Crate {crate: {id: string, max_stable_version: string, max_version: string, newest_version: string}} - ----@param crate string ----@param callback fun(err: string|nil, data: Crate|nil) -function M.fetch_crate(crate, callback) - fetch(("https://crates.io/api/v1/crates/%s"):format(crate), function(err, data) - if err then - callback(err, nil) - return - end - local ok, response = pcall(vim.json.decode, data) - if not ok then - callback("Failed to deserialize crates.io API response.", nil) - return - end - callback(nil, response) - end) -end - -return M diff --git a/lua/nvim-lsp-installer/core/clients/eclipse.lua b/lua/nvim-lsp-installer/core/clients/eclipse.lua index a788f2e2..0d169d9d 100644 --- a/lua/nvim-lsp-installer/core/clients/eclipse.lua +++ b/lua/nvim-lsp-installer/core/clients/eclipse.lua @@ -7,15 +7,9 @@ function M._parse_jdtls_version_string(version) return vim.trim(version):gsub("^jdt%-language%-server%-", ""):gsub("%.tar%.gz$", "") end ----@param callback fun(err: string|nil, data: string|nil) -function M.fetch_latest_jdtls_version(callback) - fetch("https://download.eclipse.org/jdtls/snapshots/latest.txt", function(err, data) - if err then - callback(err, nil) - else - callback(nil, M._parse_jdtls_version_string(data)) - end - end) +---@async +function M.fetch_latest_jdtls_version() + return fetch("https://download.eclipse.org/jdtls/snapshots/latest.txt"):map(M._parse_jdtls_version_string) end return M diff --git a/lua/nvim-lsp-installer/core/clients/github.lua b/lua/nvim-lsp-installer/core/clients/github.lua deleted file mode 100644 index b78a8964..00000000 --- a/lua/nvim-lsp-installer/core/clients/github.lua +++ /dev/null @@ -1,92 +0,0 @@ -local fetch = require "nvim-lsp-installer.core.fetch" -local Data = require "nvim-lsp-installer.data" -local log = require "nvim-lsp-installer.log" - -local list_find_first = Data.list_find_first - -local M = {} - ----@alias GitHubRelease {tag_name:string, prerelease: boolean, draft: boolean} ----@alias GitHubTag {name: string} - ----@param repo string The GitHub repo ("username/repo"). ----@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), { - 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) -end - ----@alias FetchLatestGithubReleaseOpts {tag_name_pattern:string} ----@param repo string The GitHub repo ("username/repo"). ----@param opts FetchLatestGithubReleaseOpts|nil ----@param callback fun(error: string|nil, data: GitHubRelease|nil) -function M.fetch_latest_release(repo, opts, callback) - M.fetch_releases(repo, function(err, releases) - if err then - callback(err, nil) - return - end - - local latest_release = list_find_first(releases, function(_release) - ---@type GitHubRelease - local release = _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) - return callback("Failed to find latest release.", nil) - end - - log.fmt_debug("Resolved latest version repo=%s, tag_name=%s", repo, latest_release.tag_name) - callback(nil, latest_release) - end) -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), { - 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) -end - ----@param repo string The GitHub repo ("username/repo"). ----@param callback fun(err: string|nil, latest_tag: GitHubTag|nil) -function M.fetch_latest_tag(repo, callback) - M.fetch_tags(repo, function(err, tags) - if err then - return callback(err, nil) - end - if vim.tbl_count(tags) == 0 then - return callback("No tags found.", nil) - end - callback(nil, tags[1]) - end) -end - -return M diff --git a/lua/nvim-lsp-installer/core/fetch.lua b/lua/nvim-lsp-installer/core/fetch.lua index bd1a582d..d97da59b 100644 --- a/lua/nvim-lsp-installer/core/fetch.lua +++ b/lua/nvim-lsp-installer/core/fetch.lua @@ -1,6 +1,8 @@ local log = require "nvim-lsp-installer.log" -local process = require "nvim-lsp-installer.process" local platform = require "nvim-lsp-installer.platform" +local Result = require "nvim-lsp-installer.core.result" +local spawn = require "nvim-lsp-installer.core.spawn" +local powershell = require "nvim-lsp-installer.core.managers.powershell" local USER_AGENT = "nvim-lsp-installer (+https://github.com/williamboman/nvim-lsp-installer)" @@ -10,89 +12,29 @@ local HEADERS = { iwr = ("-Headers @{'User-Agent' = '%s'}"):format(USER_AGENT), } -local function with_headers(headers, args) - local result = {} - vim.list_extend(result, headers) - vim.list_extend(result, args) - return result -end - ----@alias FetchCallback fun(err: string|nil, raw_data: string) - ----@param url string The url to fetch. ----@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() +---@async +---@param url string @The url to fetch. +local function fetch(url) 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 = with_headers(HEADERS.wget, { "-nv", "-O", "-", url }), - stdio_sink = stdio.sink, - }), - process.lazy_spawn("curl", { - args = with_headers(HEADERS.curl, { "-fsSL", url }), - stdio_sink = stdio.sink, - }), - } + local platform_specific = Result.failure() if platform.is_win then - local ps_script = { - "$ProgressPreference = 'SilentlyContinue';", - "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;", - ("Write-Output (iwr %s -UseBasicParsing -Uri %q).Content"):format(HEADERS.iwr, 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 - - if opts.custom_fetcher then - table.insert( - job_variants, - 1, - process.lazy_spawn(opts.custom_fetcher.cmd, { - args = opts.custom_fetcher.args, - stdio_sink = stdio.sink, - }) + platform_specific = powershell.command( + ([[Write-Output (iwr %s -UseBasicParsing -Uri %q).Content;]]):format(HEADERS.iwr, url) ) end - 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, - } + return platform_specific + :recover_catching(function() + return spawn.wget({ HEADERS.wget, "-nv", "-O", "-", url }):get_or_throw() + end) + :recover_catching(function() + return spawn.curl({ HEADERS.curl, "-fsSL", url }):get_or_throw() + end) + :map(function(result) + return result.stdout + end) end -return setmetatable({ - with_headers = with_headers, - HEADERS = HEADERS, -}, { - __call = function(_, ...) - return fetch(...) - end, -}) +return fetch diff --git a/lua/nvim-lsp-installer/core/installer/context.lua b/lua/nvim-lsp-installer/core/installer/context.lua index 0b13859b..5705fa41 100644 --- a/lua/nvim-lsp-installer/core/installer/context.lua +++ b/lua/nvim-lsp-installer/core/installer/context.lua @@ -76,7 +76,8 @@ function CwdManager.new(boundary_path, cwd) end function CwdManager:get() - return assert(self.cwd, "Tried to access cwd before it was set.") + assert(self.cwd ~= nil, "Tried to access cwd before it was set.") + return self.cwd end ---@param new_cwd string diff --git a/lua/nvim-lsp-installer/core/managers/cargo/client.lua b/lua/nvim-lsp-installer/core/managers/cargo/client.lua new file mode 100644 index 00000000..7e69cdf4 --- /dev/null +++ b/lua/nvim-lsp-installer/core/managers/cargo/client.lua @@ -0,0 +1,14 @@ +local fetch = require "nvim-lsp-installer.core.fetch" + +local M = {} + +---@alias CrateResponse {crate: {id: string, max_stable_version: string, max_version: string, newest_version: string}} + +---@async +---@param crate string +---@return Result @of [Crate] +function M.fetch_crate(crate) + return fetch(("https://crates.io/api/v1/crates/%s"):format(crate)):map_catching(vim.json.decode) +end + +return M diff --git a/lua/nvim-lsp-installer/core/managers/cargo/init.lua b/lua/nvim-lsp-installer/core/managers/cargo/init.lua index 5d74e010..84beaf1e 100644 --- a/lua/nvim-lsp-installer/core/managers/cargo/init.lua +++ b/lua/nvim-lsp-installer/core/managers/cargo/init.lua @@ -3,11 +3,8 @@ local path = require "nvim-lsp-installer.path" local spawn = require "nvim-lsp-installer.core.spawn" local a = require "nvim-lsp-installer.core.async" local Optional = require "nvim-lsp-installer.core.optional" -local crates = require "nvim-lsp-installer.core.clients.crates" -local Result = require "nvim-lsp-installer.core.result" local installer = require "nvim-lsp-installer.core.installer" - -local fetch_crate = a.promisify(crates.fetch_crate, true) +local client = require "nvim-lsp-installer.core.managers.cargo.client" ---@param crate string local function with_receipt(crate) @@ -58,7 +55,7 @@ function M.install(crate, opts) end ---@param output string @The `cargo install --list` output. ----@return Record @Key is the crate name, value is its version. +---@return table @Key is the crate name, value is its version. function M.parse_installed_crates(output) local installed_crates = {} for _, line in ipairs(vim.split(output, "\n")) do @@ -74,18 +71,19 @@ end ---@param receipt InstallReceipt ---@param install_dir string function M.check_outdated_primary_package(receipt, install_dir) - local installed_version = M.get_installed_primary_package_version(receipt, install_dir):get_or_throw() - - local response = fetch_crate(receipt.primary_source.package) - if installed_version ~= response.crate.max_stable_version then - return Result.success { - name = receipt.primary_source.package, - current_version = installed_version, - latest_version = response.crate.max_stable_version, - } - else - return Result.failure "Primary package is not outdated." - end + return M.get_installed_primary_package_version(receipt, install_dir):map_catching(function(installed_version) + ---@type CrateResponse + local crate_response = client.fetch_crate(receipt.primary_source.package):get_or_throw() + if installed_version ~= crate_response.crate.max_stable_version then + return { + name = receipt.primary_source.package, + current_version = installed_version, + latest_version = crate_response.crate.max_stable_version, + } + else + error "Primary package is not outdated." + end + end) end ---@async diff --git a/lua/nvim-lsp-installer/core/managers/gem/init.lua b/lua/nvim-lsp-installer/core/managers/gem/init.lua index f40cb736..4191d587 100644 --- a/lua/nvim-lsp-installer/core/managers/gem/init.lua +++ b/lua/nvim-lsp-installer/core/managers/gem/init.lua @@ -75,10 +75,10 @@ function M.parse_outdated_gem(outdated_gem) return outdated_package end ----Parses the stdout of the `gem list` command into a Record +---Parses the stdout of the `gem list` command into a table ---@param output string function M.parse_gem_list_output(output) - ---@type Record + ---@type table local gem_versions = {} for _, line in ipairs(vim.split(output, "\n")) do local gem_package, version = line:match "^(%S+) %((%S+)%)$" diff --git a/lua/nvim-lsp-installer/core/managers/github/client.lua b/lua/nvim-lsp-installer/core/managers/github/client.lua new file mode 100644 index 00000000..a8766748 --- /dev/null +++ b/lua/nvim-lsp-installer/core/managers/github/client.lua @@ -0,0 +1,88 @@ +local Data = require "nvim-lsp-installer.data" +local log = require "nvim-lsp-installer.log" +local fetch = require "nvim-lsp-installer.core.fetch" +local spawn = require "nvim-lsp-installer.core.spawn" + +local list_find_first = Data.list_find_first + +local M = {} + +---@alias GitHubRelease {tag_name:string, prerelease: boolean, draft: boolean} +---@alias GitHubTag {name: string} + +---@async +---@param repo string The GitHub repo ("username/repo"). +function M.fetch_releases(repo) + log.fmt_trace("Fetching GitHub releases for repo=%s", repo) + local path = ("repos/%s/releases"):format(repo) + return spawn.gh({ "api", path }) + :map(function(result) + return result.stdout + end) + :recover_catching(function() + return fetch(("https://api.github.com/%s"):format(path)):get_or_throw() + end) + :map_catching(vim.json.decode) +end + +---@alias FetchLatestGithubReleaseOpts {tag_name_pattern:string} + +---@async +---@param repo string The GitHub repo ("username/repo"). +---@param opts FetchLatestGithubReleaseOpts|nil +---@return Result @of GitHubRelease +function M.fetch_latest_release(repo, opts) + opts = opts or {} + return M.fetch_releases(repo):map_catching( + ---@param releases GitHubRelease[] + function(releases) + ---@type GitHubRelease|nil + local latest_release = list_find_first( + releases, + ---@param release GitHubRelease + 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) + error "Failed to find latest release." + end + + log.fmt_debug("Resolved latest version repo=%s, tag_name=%s", repo, latest_release.tag_name) + return latest_release + end + ) +end + +---@async +---@param repo string The GitHub repo ("username/repo"). +function M.fetch_tags(repo) + local path = ("repos/%s/tags"):format(repo) + return spawn.gh({ "api", path }) + :map(function(result) + return result.stdout + end) + :recover_catching(function() + return fetch(("https://api.github.com/%s"):format(path)):get_or_throw() + end) + :map_catching(vim.json.decode) +end + +---@async +---@param repo string The GitHub repo ("username/repo"). +function M.fetch_latest_tag(repo) + return M.fetch_tags(repo):map_catching(function(tags) + if vim.tbl_count(tags) == 0 then + error "No tags found." + end + return tags[1] + end) +end + +return M diff --git a/lua/nvim-lsp-installer/core/managers/npm/init.lua b/lua/nvim-lsp-installer/core/managers/npm/init.lua index a4631e42..94d8b2ee 100644 --- a/lua/nvim-lsp-installer/core/managers/npm/init.lua +++ b/lua/nvim-lsp-installer/core/managers/npm/init.lua @@ -69,7 +69,7 @@ end ---@param exec_args string[] @The arguments to pass to npm exec. function M.exec(exec_args) local ctx = installer.context() - ctx.spawn.npm { "exec", "--yes", exec_args } + ctx.spawn.npm { "exec", "--yes", "--", exec_args } end ---@async diff --git a/lua/nvim-lsp-installer/core/managers/powershell/init.lua b/lua/nvim-lsp-installer/core/managers/powershell/init.lua new file mode 100644 index 00000000..a246e24c --- /dev/null +++ b/lua/nvim-lsp-installer/core/managers/powershell/init.lua @@ -0,0 +1,46 @@ +local spawn = require "nvim-lsp-installer.core.spawn" +local process = require "nvim-lsp-installer.process" + +local M = {} + +local PWSHOPT = { + progress_preference = [[ $ProgressPreference = 'SilentlyContinue'; ]], -- https://stackoverflow.com/a/63301751 + security_protocol = [[ [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; ]], +} + +---@param script string +---@param opts JobSpawnOpts +---@param custom_spawn JobSpawn +function M.script(script, opts, custom_spawn) + opts = opts or {} + ---@type JobSpawn + local spawner = custom_spawn or spawn + return spawner.powershell(vim.tbl_extend("keep", { + "-NoProfile", + on_spawn = function(_, stdio) + local stdin = stdio[1] + stdin:write(PWSHOPT.progress_preference) + stdin:write(PWSHOPT.security_protocol) + stdin:write(script) + stdin:close() + end, + env = process.graft_env(opts.env or {}, { "PSMODULEPATH" }), + }, opts)) +end + +---@param command string +---@param opts JobSpawnOpts +---@param custom_spawn JobSpawn +function M.command(command, opts, custom_spawn) + opts = opts or {} + ---@type JobSpawn + local spawner = custom_spawn or spawn + return spawner.powershell(vim.tbl_extend("keep", { + "-NoProfile", + "-Command", + PWSHOPT.progress_preference .. PWSHOPT.security_protocol .. command, + env = process.graft_env(opts.env or {}, { "PSMODULEPATH" }), + }, opts)) +end + +return M diff --git a/lua/nvim-lsp-installer/core/managers/std/init.lua b/lua/nvim-lsp-installer/core/managers/std/init.lua new file mode 100644 index 00000000..49a7f53d --- /dev/null +++ b/lua/nvim-lsp-installer/core/managers/std/init.lua @@ -0,0 +1,44 @@ +local a = require "nvim-lsp-installer.core.async" +local installer = require "nvim-lsp-installer.core.installer" + +local M = {} + +local function with_system_executable_receipt(executable) + return function() + local ctx = installer.context() + ctx.receipt:with_primary_source(ctx.receipt.system(executable)) + end +end + +---@async +---@param executable string +---@param opts {help_url:string|nil} +function M.system_executable(executable, opts) + return function() + M.ensure_executable(executable, opts).with_receipt() + end +end + +---@async +---@param executable string +---@param opts {help_url:string|nil} +function M.ensure_executable(executable, opts) + local ctx = installer.context() + opts = opts or {} + if vim.in_fast_event() then + a.scheduler() + end + if vim.fn.executable(executable) ~= 1 then + ctx.stdio_sink.stderr(("%s was not found in path.\n"):format(executable)) + if opts.help_url then + ctx.stdio_sink.stderr(("See %s for installation instructions.\n"):format(opts.help_url)) + end + error("Installation failed: system executable was not found.", 0) + end + + return { + with_receipt = with_system_executable_receipt(executable), + } +end + +return M 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 diff --git a/lua/nvim-lsp-installer/jobs/outdated-servers/github_release_file.lua b/lua/nvim-lsp-installer/jobs/outdated-servers/github_release_file.lua index 527a37ff..66523a23 100644 --- a/lua/nvim-lsp-installer/jobs/outdated-servers/github_release_file.lua +++ b/lua/nvim-lsp-installer/jobs/outdated-servers/github_release_file.lua @@ -1,22 +1,20 @@ -local a = require "nvim-lsp-installer.core.async" -local Result = require "nvim-lsp-installer.core.result" -local github = require "nvim-lsp-installer.core.clients.github" - -local fetch_latest_release = a.promisify(github.fetch_latest_release, true) +local github_client = require "nvim-lsp-installer.core.managers.github.client" ---@async ---@param receipt InstallReceipt return function(receipt) local source = receipt.primary_source - return Result.run_catching(function() - local latest_release = fetch_latest_release(source.repo, { tag_name_pattern = source.tag_name_pattern }) - if source.release ~= latest_release.tag_name then - return { - name = source.repo, - current_version = source.release, - latest_version = latest_release.tag_name, - } + return github_client.fetch_latest_release(source.repo, { tag_name_pattern = source.tag_name_pattern }):map_catching( + ---@param latest_release GitHubRelease + function(latest_release) + if source.release ~= latest_release.tag_name then + return { + name = source.repo, + current_version = source.release, + latest_version = latest_release.tag_name, + } + end + error "Primary package is not outdated." end - error "Primary package is not outdated." - end) + ) end diff --git a/lua/nvim-lsp-installer/jobs/outdated-servers/github_tag.lua b/lua/nvim-lsp-installer/jobs/outdated-servers/github_tag.lua index f9df2438..d9d3d9d7 100644 --- a/lua/nvim-lsp-installer/jobs/outdated-servers/github_tag.lua +++ b/lua/nvim-lsp-installer/jobs/outdated-servers/github_tag.lua @@ -1,23 +1,20 @@ -local a = require "nvim-lsp-installer.core.async" -local Result = require "nvim-lsp-installer.core.result" -local github = require "nvim-lsp-installer.core.clients.github" - -local fetch_latest_tag = a.promisify(github.fetch_latest_tag, true) +local github_client = require "nvim-lsp-installer.core.managers.github.client" ---@async ---@param receipt InstallReceipt return function(receipt) local source = receipt.primary_source - return Result.run_catching(function() - local latest_tag = fetch_latest_tag(source.repo) - - if source.tag ~= latest_tag.name then - return { - name = source.repo, - current_version = source.tag, - latest_version = latest_tag.name, - } + return github_client.fetch_latest_tag(source.repo):map_catching( + ---@param latest_tag GitHubTag + function(latest_tag) + if source.tag ~= latest_tag.name then + return { + name = source.repo, + current_version = source.tag, + latest_version = latest_tag.name, + } + end + error "Primary package is not outdated." end - error "Primary package is not outdated." - end) + ) end diff --git a/lua/nvim-lsp-installer/jobs/outdated-servers/init.lua b/lua/nvim-lsp-installer/jobs/outdated-servers/init.lua index e50ca9fd..8ea36b9a 100644 --- a/lua/nvim-lsp-installer/jobs/outdated-servers/init.lua +++ b/lua/nvim-lsp-installer/jobs/outdated-servers/init.lua @@ -20,7 +20,7 @@ local jobpool = JobExecutionPool:new { size = 4, } ----@type Record +---@type table local checkers = { ["npm"] = npm.check_outdated_primary_package, ["pip3"] = pip3.check_outdated_primary_package, diff --git a/lua/nvim-lsp-installer/jobs/outdated-servers/jdtls.lua b/lua/nvim-lsp-installer/jobs/outdated-servers/jdtls.lua index 3b10f42a..0e3d68fc 100644 --- a/lua/nvim-lsp-installer/jobs/outdated-servers/jdtls.lua +++ b/lua/nvim-lsp-installer/jobs/outdated-servers/jdtls.lua @@ -1,14 +1,9 @@ -local a = require "nvim-lsp-installer.core.async" -local Result = require "nvim-lsp-installer.core.result" local eclipse = require "nvim-lsp-installer.core.clients.eclipse" -local fetch_latest_jdtls_version = a.promisify(eclipse.fetch_latest_jdtls_version, true) - ---@async ---@param receipt InstallReceipt return function(receipt) - return Result.run_catching(function() - local latest_version = fetch_latest_jdtls_version() + return eclipse.fetch_latest_jdtls_version():map_catching(function(latest_version) if receipt.primary_source.version ~= latest_version then return { name = "jdtls", diff --git a/lua/nvim-lsp-installer/jobs/version-check/init.lua b/lua/nvim-lsp-installer/jobs/version-check/init.lua index ef36fefa..85ac8b26 100644 --- a/lua/nvim-lsp-installer/jobs/version-check/init.lua +++ b/lua/nvim-lsp-installer/jobs/version-check/init.lua @@ -25,7 +25,7 @@ local function noop() return Result.failure "Unable to detect version." end ----@type Record +---@type table local version_checker = { ["npm"] = function(server, receipt) return npm.get_installed_primary_package_version(receipt, server.root_dir) diff --git a/lua/nvim-lsp-installer/servers/dartls/init.lua b/lua/nvim-lsp-installer/servers/dartls/init.lua index 433b5667..8f0437fe 100644 --- a/lua/nvim-lsp-installer/servers/dartls/init.lua +++ b/lua/nvim-lsp-installer/servers/dartls/init.lua @@ -1,6 +1,5 @@ local server = require "nvim-lsp-installer.server" -local std = require "nvim-lsp-installer.installers.std" -local context = require "nvim-lsp-installer.installers.context" +local std = require "nvim-lsp-installer.core.managers.std" return function(name, root_dir) return server.Server:new { @@ -8,17 +7,8 @@ return function(name, root_dir) root_dir = root_dir, homepage = "https://github.com/dart-lang/sdk", languages = { "dart" }, - installer = { - std.ensure_executables { - { - "dart", - "dart was not found in path. Refer to https://dart.dev/get-dart for installation instructions.", - }, - }, - context.receipt(function(receipt) - receipt:with_primary_source(receipt.system "dart") - end), - }, + async = true, + installer = std.system_executable("dart", { help_url = "https://dart.dev/get-dart" }), default_options = {}, } end diff --git a/lua/nvim-lsp-installer/servers/efm/init.lua b/lua/nvim-lsp-installer/servers/efm/init.lua index c665df7a..0077b66e 100644 --- a/lua/nvim-lsp-installer/servers/efm/init.lua +++ b/lua/nvim-lsp-installer/servers/efm/init.lua @@ -1,5 +1,5 @@ local server = require "nvim-lsp-installer.server" -local go = require "nvim-lsp-installer.installers.go" +local go = require "nvim-lsp-installer.core.managers.go" return function(name, root_dir) return server.Server:new { @@ -7,6 +7,7 @@ return function(name, root_dir) root_dir = root_dir, homepage = "https://github.com/mattn/efm-langserver", languages = {}, + async = true, installer = go.packages { "github.com/mattn/efm-langserver" }, default_options = { cmd_env = go.env(root_dir), diff --git a/lua/nvim-lsp-installer/servers/golangci_lint_ls/init.lua b/lua/nvim-lsp-installer/servers/golangci_lint_ls/init.lua index 7dc0156c..3a0e8db7 100644 --- a/lua/nvim-lsp-installer/servers/golangci_lint_ls/init.lua +++ b/lua/nvim-lsp-installer/servers/golangci_lint_ls/init.lua @@ -1,5 +1,5 @@ local server = require "nvim-lsp-installer.server" -local go = require "nvim-lsp-installer.installers.go" +local go = require "nvim-lsp-installer.core.managers.go" return function(name, root_dir) return server.Server:new { @@ -7,6 +7,7 @@ return function(name, root_dir) root_dir = root_dir, homepage = "https://github.com/nametake/golangci-lint-langserver", languages = { "go" }, + async = true, installer = go.packages { "github.com/nametake/golangci-lint-langserver", "github.com/golangci/golangci-lint/cmd/golangci-lint", diff --git a/lua/nvim-lsp-installer/servers/gopls/init.lua b/lua/nvim-lsp-installer/servers/gopls/init.lua index 9b1f8c09..a540a856 100644 --- a/lua/nvim-lsp-installer/servers/gopls/init.lua +++ b/lua/nvim-lsp-installer/servers/gopls/init.lua @@ -1,5 +1,5 @@ local server = require "nvim-lsp-installer.server" -local go = require "nvim-lsp-installer.installers.go" +local go = require "nvim-lsp-installer.core.managers.go" return function(name, root_dir) return server.Server:new { @@ -7,6 +7,7 @@ return function(name, root_dir) root_dir = root_dir, homepage = "https://pkg.go.dev/golang.org/x/tools/gopls", languages = { "go" }, + async = true, installer = go.packages { "golang.org/x/tools/gopls" }, default_options = { cmd_env = go.env(root_dir), diff --git a/lua/nvim-lsp-installer/servers/groovyls/init.lua b/lua/nvim-lsp-installer/servers/groovyls/init.lua index 8dbb1b5c..a40dc32e 100644 --- a/lua/nvim-lsp-installer/servers/groovyls/init.lua +++ b/lua/nvim-lsp-installer/servers/groovyls/init.lua @@ -1,7 +1,8 @@ local server = require "nvim-lsp-installer.server" local path = require "nvim-lsp-installer.path" -local std = require "nvim-lsp-installer.installers.std" -local context = require "nvim-lsp-installer.installers.context" +local std = require "nvim-lsp-installer.core.managers.std" +local git = require "nvim-lsp-installer.core.managers.git" +local process = require "nvim-lsp-installer.process" return function(name, root_dir) return server.Server:new { @@ -9,19 +10,19 @@ return function(name, root_dir) root_dir = root_dir, languages = { "groovy" }, homepage = "https://github.com/GroovyLanguageServer/groovy-language-server", - installer = { - std.ensure_executables { { "javac", "javac was not found in path." } }, - std.git_clone "https://github.com/GroovyLanguageServer/groovy-language-server", - context.promote_install_dir(), - std.gradlew { - args = { "build" }, - }, - context.receipt(function(receipt) - receipt:with_primary_source( - receipt.git_remote "https://github.com/GroovyLanguageServer/groovy-language-server" - ) - end), - }, + async = true, + ---@param ctx InstallContext + installer = function(ctx) + std.ensure_executable "javac" + git.clone({ "https://github.com/GroovyLanguageServer/groovy-language-server" }).with_receipt() + ctx:promote_cwd() + ctx.spawn.gradlew { + "build", + env = process.graft_env { + PATH = process.extend_path { ctx.cwd:get() }, + }, + } + end, default_options = { cmd = { "java", "-jar", path.concat { root_dir, "build", "libs", "groovyls-all.jar" } }, }, diff --git a/lua/nvim-lsp-installer/servers/haxe_language_server/init.lua b/lua/nvim-lsp-installer/servers/haxe_language_server/init.lua index 25c77cb0..f07cdd33 100644 --- a/lua/nvim-lsp-installer/servers/haxe_language_server/init.lua +++ b/lua/nvim-lsp-installer/servers/haxe_language_server/init.lua @@ -1,8 +1,8 @@ local server = require "nvim-lsp-installer.server" -local std = require "nvim-lsp-installer.installers.std" -local npm = require "nvim-lsp-installer.installers.npm" local path = require "nvim-lsp-installer.path" -local context = require "nvim-lsp-installer.installers.context" +local std = require "nvim-lsp-installer.core.managers.std" +local git = require "nvim-lsp-installer.core.managers.git" +local npm = require "nvim-lsp-installer.core.managers.npm" return function(name, root_dir) return server.Server:new { @@ -10,20 +10,14 @@ return function(name, root_dir) root_dir = root_dir, homepage = "https://github.com/vshaxe/haxe-language-server", languages = { "haxe" }, - installer = { - std.ensure_executables { - { - "haxelib", - "haxelib was not found in path. Refer to https://haxe.org/ for installation instructions.", - }, - }, - std.git_clone "https://github.com/vshaxe/haxe-language-server", - npm.install(), - npm.exec("lix", { "run", "vshaxe-build", "-t", "language-server" }), - context.receipt(function(receipt) - receipt:with_primary_source(receipt.git_remote "https://github.com/vshaxe/haxe-language-server") - end), - }, + async = true, + ---@param ctx InstallContext + installer = function(ctx) + std.ensure_executable("haxelib", { help_url = "https://haxe.org" }) + git.clone({ "https://github.com/vshaxe/haxe-language-server" }).with_receipt() + ctx.spawn.npm { "install" } + npm.exec { "lix", "run", "vshaxe-build", "-t", "language-server" } + end, default_options = { cmd = { "node", path.concat { root_dir, "bin", "server.js" } }, }, diff --git a/lua/nvim-lsp-installer/servers/jdtls/init.lua b/lua/nvim-lsp-installer/servers/jdtls/init.lua index 6acc4995..1e466c85 100644 --- a/lua/nvim-lsp-installer/servers/jdtls/init.lua +++ b/lua/nvim-lsp-installer/servers/jdtls/init.lua @@ -1,4 +1,5 @@ local server = require "nvim-lsp-installer.server" +local a = require "nvim-lsp-installer.core.async" local path = require "nvim-lsp-installer.path" local std = require "nvim-lsp-installer.installers.std" local context = require "nvim-lsp-installer.installers.context" @@ -61,12 +62,12 @@ return function(name, root_dir) callback(true) return end - eclipse.fetch_latest_jdtls_version(function(err, latest_version) - if err then + a.run(eclipse.fetch_latest_jdtls_version, function(success, latest_version) + if not success or latest_version:is_failure() then ctx.stdio_sink.stderr "Failed to fetch latest verison.\n" callback(false) else - ctx.requested_server_version = latest_version + ctx.requested_server_version = latest_version:get_or_nil() callback(true) end end) diff --git a/lua/nvim-lsp-installer/servers/jsonnet_ls/init.lua b/lua/nvim-lsp-installer/servers/jsonnet_ls/init.lua index 0acbe9d4..7a20d8c7 100644 --- a/lua/nvim-lsp-installer/servers/jsonnet_ls/init.lua +++ b/lua/nvim-lsp-installer/servers/jsonnet_ls/init.lua @@ -1,12 +1,13 @@ -local server = require "nvim-lsp-installer.server" -local go = require "nvim-lsp-installer.installers.go" local path = require "nvim-lsp-installer.path" +local server = require "nvim-lsp-installer.server" +local go = require "nvim-lsp-installer.core.managers.go" return function(name, root_dir) return server.Server:new { name = name, root_dir = root_dir, homepage = "https://github.com/grafana/jsonnet-language-server", + async = true, installer = go.packages { "github.com/grafana/jsonnet-language-server" }, default_options = { -- TODO: use env instead of cmd once https://github.com/neovim/nvim-lspconfig/pull/1559 is merged diff --git a/lua/nvim-lsp-installer/servers/mm0_ls/init.lua b/lua/nvim-lsp-installer/servers/mm0_ls/init.lua index 14ec1bc9..a50c7879 100644 --- a/lua/nvim-lsp-installer/servers/mm0_ls/init.lua +++ b/lua/nvim-lsp-installer/servers/mm0_ls/init.lua @@ -1,8 +1,7 @@ local server = require "nvim-lsp-installer.server" -local std = require "nvim-lsp-installer.installers.std" -local context = require "nvim-lsp-installer.installers.context" local path = require "nvim-lsp-installer.path" local process = require "nvim-lsp-installer.process" +local git = require "nvim-lsp-installer.core.managers.git" return function(name, root_dir) return server.Server:new { @@ -10,20 +9,13 @@ return function(name, root_dir) root_dir = root_dir, languages = { "metamath-zero" }, homepage = "https://github.com/digama0/mm0", - installer = { - std.git_clone "https://github.com/digama0/mm0", - ---@type ServerInstallerFunction - function(_, callback, ctx) - process.spawn("cargo", { - args = { "build", "--release" }, - cwd = path.concat { ctx.install_dir, "mm0-rs" }, - stdio_sink = ctx.stdio_sink, - }, callback) - end, - context.receipt(function(receipt) - receipt:with_primary_source(receipt.git_remote "https://github.com/digama0/mm0") - end), - }, + async = true, + ---@param ctx InstallContext + installer = function(ctx) + git.clone({ "https://github.com/digama0/mm0" }).with_receipt() + ctx.spawn.cargo { "build", "--release", cwd = path.concat { ctx.cwd:get(), "mm0-rs" } } + ctx.receipt:with_primary_source(ctx.receipt.git_remote "https://github.com/digama0/mm0") + end, default_options = { cmd_env = { PATH = process.extend_path { path.concat { root_dir, "mm0-rs", "target", "release" } }, diff --git a/lua/nvim-lsp-installer/servers/nimls/init.lua b/lua/nvim-lsp-installer/servers/nimls/init.lua index b554f1d8..e92a891a 100644 --- a/lua/nvim-lsp-installer/servers/nimls/init.lua +++ b/lua/nvim-lsp-installer/servers/nimls/init.lua @@ -1,8 +1,6 @@ local server = require "nvim-lsp-installer.server" -local std = require "nvim-lsp-installer.installers.std" local process = require "nvim-lsp-installer.process" -local path = require "nvim-lsp-installer.path" -local context = require "nvim-lsp-installer.installers.context" +local git = require "nvim-lsp-installer.core.managers.git" return function(name, root_dir) return server.Server:new { @@ -10,19 +8,12 @@ return function(name, root_dir) root_dir = root_dir, homepage = "https://github.com/PMunch/nimlsp", languages = { "nim" }, - installer = { - std.git_clone "https://github.com/PMunch/nimlsp.git", - function(_, callback, ctx) - process.spawn("nimble", { - args = { "build", "-y", "--localdeps" }, - cwd = ctx.install_dir, - stdio_sink = ctx.stdio_sink, - }, callback) - end, - context.receipt(function(receipt) - receipt:with_primary_source(receipt.git_remote "https://github.com/PMunch/nimlsp.git") - end), - }, + async = true, + ---@param ctx InstallContext + installer = function(ctx) + git.clone({ "https://github.com/PMunch/nimlsp.git" }).with_receipt() + ctx.spawn.nimble { "build", "-y", "--localdeps" } + end, default_options = { cmd_env = { PATH = process.extend_path { root_dir }, diff --git a/lua/nvim-lsp-installer/servers/scry/init.lua b/lua/nvim-lsp-installer/servers/scry/init.lua index 8c092ad2..43a2ccd6 100644 --- a/lua/nvim-lsp-installer/servers/scry/init.lua +++ b/lua/nvim-lsp-installer/servers/scry/init.lua @@ -1,8 +1,8 @@ local server = require "nvim-lsp-installer.server" -local std = require "nvim-lsp-installer.installers.std" local process = require "nvim-lsp-installer.process" local path = require "nvim-lsp-installer.path" -local context = require "nvim-lsp-installer.installers.context" +local std = require "nvim-lsp-installer.core.managers.std" +local git = require "nvim-lsp-installer.core.managers.git" return function(name, root_dir) return server.Server:new { @@ -10,30 +10,18 @@ return function(name, root_dir) root_dir = root_dir, languages = { "crystal" }, homepage = "https://github.com/crystal-lang-tools/scry", - installer = { - std.ensure_executables { - { - "crystal", - "crystal was not found in path. Refer to https://crystal-lang.org/install/ for installation instructions.", - }, - { - "shards", - "shards was not found in path. Refer to https://crystal-lang.org/install/ for installation instructions.", - }, - }, - std.git_clone "https://github.com/crystal-lang-tools/scry.git", - ---@type ServerInstallerFunction - function(_, callback, ctx) - process.spawn("shards", { - args = { "build", "--verbose", "--release" }, - cwd = ctx.install_dir, - stdio_sink = ctx.stdio_sink, - }, callback) - end, - context.receipt(function(receipt) - receipt:with_primary_source(receipt.git_remote "https://github.com/crystal-lang-tools/scry.git") - end), - }, + async = true, + ---@param ctx InstallContext + installer = function(ctx) + std.ensure_executable("crystal", { + help_url = "https://crystal-lang.org/install/", + }) + std.ensure_executable("shards", { + help_url = "https://crystal-lang.org/install/", + }) + git.clone({ "https://github.com/crystal-lang-tools/scry.git" }).with_receipt() + ctx.spawn.shards { "build", "--verbose", "--release" } + end, default_options = { cmd_env = { PATH = process.extend_path { path.concat { root_dir, "bin" } }, diff --git a/lua/nvim-lsp-installer/servers/solargraph/init.lua b/lua/nvim-lsp-installer/servers/solargraph/init.lua index d0b44450..e03a29f1 100644 --- a/lua/nvim-lsp-installer/servers/solargraph/init.lua +++ b/lua/nvim-lsp-installer/servers/solargraph/init.lua @@ -1,5 +1,5 @@ local server = require "nvim-lsp-installer.server" -local gem = require "nvim-lsp-installer.installers.gem" +local gem = require "nvim-lsp-installer.core.managers.gem" return function(name, root_dir) return server.Server:new { @@ -7,6 +7,7 @@ return function(name, root_dir) root_dir = root_dir, languages = { "ruby" }, homepage = "https://solargraph.org", + async = true, installer = gem.packages { "solargraph" }, default_options = { cmd_env = gem.env(root_dir), diff --git a/lua/nvim-lsp-installer/servers/sorbet/init.lua b/lua/nvim-lsp-installer/servers/sorbet/init.lua index bb5f97bb..3b0ab025 100644 --- a/lua/nvim-lsp-installer/servers/sorbet/init.lua +++ b/lua/nvim-lsp-installer/servers/sorbet/init.lua @@ -1,5 +1,5 @@ local server = require "nvim-lsp-installer.server" -local gem = require "nvim-lsp-installer.installers.gem" +local gem = require "nvim-lsp-installer.core.managers.gem" return function(name, root_dir) return server.Server:new { @@ -7,6 +7,7 @@ return function(name, root_dir) root_dir = root_dir, homepage = "https://sorbet.org/", languages = { "ruby" }, + async = true, installer = gem.packages { "sorbet" }, default_options = { cmd_env = gem.env(root_dir), diff --git a/lua/nvim-lsp-installer/servers/sourcekit/init.lua b/lua/nvim-lsp-installer/servers/sourcekit/init.lua index b7f3d3a1..d55148b5 100644 --- a/lua/nvim-lsp-installer/servers/sourcekit/init.lua +++ b/lua/nvim-lsp-installer/servers/sourcekit/init.lua @@ -1,6 +1,5 @@ local server = require "nvim-lsp-installer.server" -local std = require "nvim-lsp-installer.installers.std" -local context = require "nvim-lsp-installer.installers.context" +local std = require "nvim-lsp-installer.core.managers.std" return function(name, root_dir) return server.Server:new { @@ -8,17 +7,8 @@ return function(name, root_dir) root_dir = root_dir, homepage = "https://github.com/apple/sourcekit-lsp", languages = { "swift" }, - installer = { - std.ensure_executables { - { - "sourcekit-lsp", - "sourcekit-lsp was not found in path. Refer to https://github.com/apple/sourcekit-lsp for installation instructions.", - }, - }, - context.receipt(function(receipt) - receipt:with_primary_source(receipt.system "sourcekit-lsp") - end), - }, + async = true, + installer = std.system_executable("sourcekit-lsp", { help_url = "https://github.com/apple/sourcekit-lsp" }), default_options = {}, } end diff --git a/lua/nvim-lsp-installer/servers/sourcery/init.lua b/lua/nvim-lsp-installer/servers/sourcery/init.lua index 487f97d5..c4efeaf6 100644 --- a/lua/nvim-lsp-installer/servers/sourcery/init.lua +++ b/lua/nvim-lsp-installer/servers/sourcery/init.lua @@ -1,5 +1,5 @@ local server = require "nvim-lsp-installer.server" -local pip3 = require "nvim-lsp-installer.installers.pip3" +local pip3 = require "nvim-lsp-installer.core.managers.pip3" return function(name, root_dir) return server.Server:new { @@ -7,6 +7,7 @@ return function(name, root_dir) root_dir = root_dir, languages = { "python" }, homepage = "https://docs.sourcery.ai/", + async = true, installer = pip3.packages { "sourcery-cli" }, default_options = { cmd_env = pip3.env(root_dir), diff --git a/lua/nvim-lsp-installer/servers/spectral/init.lua b/lua/nvim-lsp-installer/servers/spectral/init.lua index e308369c..61047942 100644 --- a/lua/nvim-lsp-installer/servers/spectral/init.lua +++ b/lua/nvim-lsp-installer/servers/spectral/init.lua @@ -1,9 +1,7 @@ local server = require "nvim-lsp-installer.server" -local npm = require "nvim-lsp-installer.installers.npm" -local std = require "nvim-lsp-installer.installers.std" -local installers = require "nvim-lsp-installer.installers" -local context = require "nvim-lsp-installer.installers.context" local path = require "nvim-lsp-installer.path" +local git = require "nvim-lsp-installer.core.managers.git" +local npm = require "nvim-lsp-installer.core.managers.npm" return function(name, root_dir) return server.Server:new { @@ -11,21 +9,19 @@ return function(name, root_dir) root_dir = root_dir, languages = { "openapi", "asyncapi" }, homepage = "https://stoplight.io/open-source/spectral/", - installer = { - std.git_clone "https://github.com/stoplightio/vscode-spectral", - npm.install(), - installers.branch_context { - context.set_working_dir "server", - npm.install(), - }, - installers.always_succeed(npm.run "compile"), - context.set_working_dir "server", - context.receipt(function(receipt, ctx) - receipt - :mark_invalid() -- Due to the `context.set_working_dir` after clone, we essentially erase any trace of the cloned git repo, so we mark this as invalid. - :with_primary_source(receipt.git_remote "https://github.com/stoplightio/vscode-spectral") - end), - }, + async = true, + ---@param ctx InstallContext + installer = function(ctx) + git.clone({ "https://github.com/stoplightio/vscode-spectral" }).with_receipt() + local server_dir = path.concat { ctx.cwd:get(), "server" } + ctx.spawn.npm { "install" } + ctx.spawn.npm { "install", cwd = server_dir } + pcall(npm.run, { "compile" }) + + -- TODO: don't do this + ctx.cwd:set(server_dir) + ctx.receipt:mark_invalid() -- Due to the `context.set_working_dir` after clone, we essentially erase any trace of the cloned git repo, so we mark this as invalid. + end, default_options = { cmd = { "node", path.concat { root_dir, "out", "server.js" }, "--stdio" }, }, diff --git a/lua/nvim-lsp-installer/servers/sqls/init.lua b/lua/nvim-lsp-installer/servers/sqls/init.lua index 40a11d67..9cad121b 100644 --- a/lua/nvim-lsp-installer/servers/sqls/init.lua +++ b/lua/nvim-lsp-installer/servers/sqls/init.lua @@ -1,5 +1,5 @@ local server = require "nvim-lsp-installer.server" -local go = require "nvim-lsp-installer.installers.go" +local go = require "nvim-lsp-installer.core.managers.go" return function(name, root_dir) return server.Server:new { @@ -7,6 +7,7 @@ return function(name, root_dir) root_dir = root_dir, languages = { "sql" }, homepage = "https://github.com/lighttiger2505/sqls", + async = true, installer = go.packages { "github.com/lighttiger2505/sqls" }, default_options = { cmd_env = go.env(root_dir), diff --git a/lua/nvim-lsp-installer/servers/theme_check/init.lua b/lua/nvim-lsp-installer/servers/theme_check/init.lua index 7bd9ddc9..e2f402e5 100644 --- a/lua/nvim-lsp-installer/servers/theme_check/init.lua +++ b/lua/nvim-lsp-installer/servers/theme_check/init.lua @@ -1,5 +1,5 @@ local server = require "nvim-lsp-installer.server" -local gem = require "nvim-lsp-installer.installers.gem" +local gem = require "nvim-lsp-installer.core.managers.gem" return function(name, root_dir) return server.Server:new { @@ -7,6 +7,7 @@ return function(name, root_dir) root_dir = root_dir, languages = { "liquid" }, homepage = "https://github.com/Shopify/theme-check", + async = true, installer = gem.packages { "theme-check" }, default_options = { cmd_env = gem.env(root_dir), diff --git a/lua/nvim-lsp-installer/ui/status-win/components/settings-schema.lua b/lua/nvim-lsp-installer/ui/status-win/components/settings-schema.lua index e67c0267..550dcdb5 100644 --- a/lua/nvim-lsp-installer/ui/status-win/components/settings-schema.lua +++ b/lua/nvim-lsp-installer/ui/status-win/components/settings-schema.lua @@ -2,7 +2,7 @@ local Ui = require "nvim-lsp-installer.ui" local Data = require "nvim-lsp-installer.data" -local list_map, list_not_nil, lazy = Data.list_map, Data.list_not_nil, Data.lazy +local list_map = Data.list_map local property_type_highlights = { ["string"] = "String", -- cgit v1.2.3-70-g09d2