diff options
| author | William Boman <william@redwill.se> | 2022-04-06 00:25:50 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-04-06 00:25:50 +0200 |
| commit | 999476c324b26223aaf409a84497215e18d74499 (patch) | |
| tree | 323cc5b072471e5e78ee94b273157779bbcb9611 | |
| parent | fix(taplo): use crate distribution (#576) (diff) | |
| download | mason-999476c324b26223aaf409a84497215e18d74499.tar mason-999476c324b26223aaf409a84497215e18d74499.tar.gz mason-999476c324b26223aaf409a84497215e18d74499.tar.bz2 mason-999476c324b26223aaf409a84497215e18d74499.tar.lz mason-999476c324b26223aaf409a84497215e18d74499.tar.xz mason-999476c324b26223aaf409a84497215e18d74499.tar.zst mason-999476c324b26223aaf409a84497215e18d74499.zip | |
switch majority of installers to async implementation (#574)
66 files changed, 510 insertions, 286 deletions
@@ -8,15 +8,15 @@ dependencies: clean_dependencies: rm -rf dependencies -.PHONY: clean_servers -clean_servers: +.PHONY: clean_fixtures +clean_fixtures: rm -rf "${INSTALL_ROOT_DIR}" .PHONY: clean -clean: clean_servers clean_dependencies +clean: clean_fixtures clean_dependencies .PHONY: test -test: clean_servers dependencies +test: clean_fixtures dependencies INSTALL_ROOT_DIR=${INSTALL_ROOT_DIR} $(NVIM_HEADLESS) -c "call RunTests()" # vim:noexpandtab diff --git a/lua/nvim-lsp-installer/core/fs.lua b/lua/nvim-lsp-installer/core/fs.lua index f3db813a..3819bd51 100644 --- a/lua/nvim-lsp-installer/core/fs.lua +++ b/lua/nvim-lsp-installer/core/fs.lua @@ -59,10 +59,33 @@ end ---@async ---@param path string +function M.mkdirp(path) + log.debug("fs: mkdirp", path) + if vim.in_fast_event() then + a.scheduler() + end + if vim.fn.mkdir(path, "p") ~= 1 then + log.debug "fs: mkdirp failed" + error(("mkdirp: Could not create directory %q."):format(path)) + end +end + +---@async +---@param path string ---@param new_path string function M.rename(path, new_path) log.debug("fs: rename", path, new_path) uv.fs_rename(path, new_path) end +---@async +---@param path string +---@param contents string +function M.write_file(path, contents) + log.fmt_debug("fs: write_file %s", path) + local fd = assert(uv.fs_open(path, "w", 438)) + uv.fs_write(fd, contents, -1) + assert(uv.fs_close(fd)) +end + return M diff --git a/lua/nvim-lsp-installer/core/context.lua b/lua/nvim-lsp-installer/core/installer/context.lua index 128ad417..ad956178 100644 --- a/lua/nvim-lsp-installer/core/context.lua +++ b/lua/nvim-lsp-installer/core/installer/context.lua @@ -1,11 +1,9 @@ local spawn = require "nvim-lsp-installer.core.spawn" local log = require "nvim-lsp-installer.log" -local Optional = require "nvim-lsp-installer.core.optional" local fs = require "nvim-lsp-installer.core.fs" -local settings = require "nvim-lsp-installer.settings" -local Result = require "nvim-lsp-installer.core.result" local path = require "nvim-lsp-installer.path" local platform = require "nvim-lsp-installer.platform" +local receipt = require "nvim-lsp-installer.core.receipt" ---@class ContextualSpawn ---@field cwd CwdManager @@ -57,111 +55,80 @@ function ContextualFs:dir_exists(rel_path) end ---@class CwdManager +---@field private boundary_path string @Defines the upper boundary for which paths are allowed as cwd. +---@field private cwd string local CwdManager = {} CwdManager.__index = CwdManager -function CwdManager.new(cwd) - return setmetatable({ cwd = cwd }, CwdManager) + +function CwdManager.new(boundary_path, cwd) + assert(type(boundary_path) == "string") + return setmetatable({ + boundary_path = boundary_path, + cwd = cwd, + }, CwdManager) end + function CwdManager:get() - return self.cwd + return assert(self.cwd, "Tried to access cwd before it was set.") end + +---@param new_cwd string function CwdManager:set(new_cwd) + assert(type(new_cwd) == "string") + assert( + path.is_subdirectory(self.boundary_path, new_cwd), + ("%q is not a subdirectory of %q"):format(new_cwd, self.boundary_path) + ) self.cwd = new_cwd end ---@class InstallContext +---@field public name string ---@field public receipt InstallReceiptBuilder ---@field public requested_version Optional ---@field public fs ContextualFs ---@field public spawn JobSpawn ----@field private cwd_manager CwdManager ----@field private destination_dir string +---@field public cwd CwdManager +---@field public destination_dir string +---@field public stdio_sink StdioSink local InstallContext = {} InstallContext.__index = InstallContext function InstallContext.new(opts) - local cwd_manager = CwdManager.new(opts.cwd) + local cwd_manager = CwdManager.new(opts.boundary_path) return setmetatable({ - cwd_manager = cwd_manager, + name = opts.name, + cwd = cwd_manager, spawn = ContextualSpawn.new(cwd_manager, opts.stdio_sink), fs = ContextualFs.new(cwd_manager), - receipt = opts.receipt, - requested_version = opts.requested_version, + receipt = receipt.InstallReceiptBuilder.new(), destination_dir = opts.destination_dir, + requested_version = opts.requested_version, + stdio_sink = opts.stdio_sink, }, InstallContext) end ----@deprecated ----@param ctx ServerInstallContext ----@param destination_dir string -function InstallContext.from_server_context(ctx, destination_dir) - return InstallContext.new { - cwd = ctx.install_dir, - receipt = ctx.receipt, - stdio_sink = ctx.stdio_sink, - requested_version = Optional.of_nilable(ctx.requested_server_version), - destination_dir = destination_dir, - } -end - -function InstallContext:cwd() - return self.cwd_manager:get() -end - ----@param new_cwd string @The new cwd (absolute path). -function InstallContext:set_cwd(new_cwd) - self - :ensure_path_ownership(new_cwd) - :map(function(p) - self.cwd_manager:set(p) - return p - end) - :get_or_throw() -end - ----@param abs_path string -function InstallContext:ensure_path_ownership(abs_path) - if path.is_subdirectory(self:cwd_manager(), abs_path) or self.destination_dir == abs_path then - return Result.success(abs_path) - else - return Result.failure( - ("Path %q is outside of current path ownership (%q)."):format(abs_path, settings.current.install_root_dir) - ) - end -end - ---@async function InstallContext:promote_cwd() - local cwd = self:cwd() + local cwd = self.cwd:get() if self.destination_dir == cwd then log.fmt_debug("cwd %s is already promoted (at %s)", cwd, self.destination_dir) - return Result.success "Current working dir is already in destination." + return end log.fmt_debug("Promoting cwd %s to %s", cwd, self.destination_dir) - return Result.run_catching(function() - -- 1. Remove destination dir, if it exists - if fs.dir_exists(self.destination_dir) then - fs.rmrf(self.destination_dir) - end - return self.destination_dir - end) - :map_catching(function(destination_dir) - -- 2. Prepare for renaming cwd to destination - if platform.is_unix then - -- Some Unix systems will raise an error when renaming a directory to a destination that does not already exist. - fs.mkdir(destination_dir) - end - return destination_dir - end) - :map_catching(function(destination_dir) - -- 3. Move the cwd to the final installation directory - fs.rename(cwd, destination_dir) - return destination_dir - end) - :map_catching(function(destination_dir) - -- 4. Update cwd - self:set_cwd(destination_dir) - end) + -- 1. Remove destination dir, if it exists + if fs.dir_exists(self.destination_dir) then + fs.rmrf(self.destination_dir) + end + -- 2. Prepare for renaming cwd to destination + if platform.is_unix then + -- Some Unix systems will raise an error when renaming a directory to a destination that does not already exist. + fs.mkdir(self.destination_dir) + end + -- 3. Move the cwd to the final installation directory + fs.rename(cwd, self.destination_dir) + -- 4. Update cwd + self.cwd:set(self.destination_dir) end return InstallContext diff --git a/lua/nvim-lsp-installer/core/installer/init.lua b/lua/nvim-lsp-installer/core/installer/init.lua new file mode 100644 index 00000000..03b2de01 --- /dev/null +++ b/lua/nvim-lsp-installer/core/installer/init.lua @@ -0,0 +1,65 @@ +local log = require "nvim-lsp-installer.log" +local path = require "nvim-lsp-installer.path" +local fs = require "nvim-lsp-installer.core.fs" +local Result = require "nvim-lsp-installer.core.result" + +local M = {} + +---@async +---@param context InstallContext +local function write_receipt(context) + if context.receipt.is_marked_invalid then + return log.fmt_debug("Skipping writing receipt for %s because it is marked as invalid.", context.name) + end + context.receipt:with_name(context.name):with_schema_version("1.0a"):with_completion_time(vim.loop.gettimeofday()) + local receipt_success, install_receipt = pcall(context.receipt.build, context.receipt) + if receipt_success then + local receipt_path = path.concat { context.cwd:get(), "nvim-lsp-installer-receipt.json" } + pcall(fs.write_file, receipt_path, vim.json.encode(install_receipt)) + else + log.fmt_error("Failed to build receipt for installation=%s, error=%s", context.name, install_receipt) + end +end + +---@async +---@param context InstallContext +---@param installer async fun(ctx: InstallContext) +function M.execute(context, installer) + log.fmt_debug("Executing installer for name=%s", context.name) + local tmp_installation_dir = ("%s.tmp"):format(context.destination_dir) + return Result.run_catching(function() + -- 1. prepare installation dir + context.receipt:with_start_time(vim.loop.gettimeofday()) + if fs.dir_exists(tmp_installation_dir) then + fs.rmrf(tmp_installation_dir) + end + fs.mkdirp(tmp_installation_dir) + context.cwd:set(tmp_installation_dir) + + -- 2. run installer + installer(context) + + -- 3. finalize + write_receipt(context) + context:promote_cwd() + end):on_failure(function(failure) + context.stdio_sink.stderr(tostring(failure)) + context.stdio_sink.stderr "\n" + log.fmt_error("Installation failed, name=%s, error=%s", context.name, failure) + pcall(fs.rmrf, tmp_installation_dir) + pcall(fs.rmrf, context.cwd:get()) + end) +end + +---@param installers async fun(ctx: InstallContext)[] +function M.serial(installers) + ---@async + ---@param ctx InstallContext + return function(ctx) + for _, installer_step in pairs(installers) do + installer_step(ctx) + end + end +end + +return M diff --git a/lua/nvim-lsp-installer/core/managers/go/init.lua b/lua/nvim-lsp-installer/core/managers/go/init.lua index 96706368..d73a250c 100644 --- a/lua/nvim-lsp-installer/core/managers/go/init.lua +++ b/lua/nvim-lsp-installer/core/managers/go/init.lua @@ -12,7 +12,7 @@ function M.packages(packages) ---@param ctx InstallContext return function(ctx) local env = process.graft_env { - GOBIN = ctx.cwd(), + GOBIN = ctx.cwd:get(), } -- Install the head package do diff --git a/lua/nvim-lsp-installer/core/managers/pip3/init.lua b/lua/nvim-lsp-installer/core/managers/pip3/init.lua index 61130a96..06408f3b 100644 --- a/lua/nvim-lsp-installer/core/managers/pip3/init.lua +++ b/lua/nvim-lsp-installer/core/managers/pip3/init.lua @@ -32,7 +32,7 @@ function M.packages(packages) or list_not_nil(vim.g.python3_host_prog, "python3", "python") -- pip3 will hardcode the full path to venv executables, so we need to promote cwd to make sure pip uses the final destination path. - ctx:promote_cwd():get_or_throw() + ctx:promote_cwd() -- Find first executable that manages to create venv local executable = list_find_first(executables, function(executable) @@ -42,7 +42,7 @@ function M.packages(packages) Optional.of_nilable(executable) :if_present(function(python3) ctx.spawn[python3] { - env = process.graft_env(M.env(ctx:cwd())), -- use venv env + env = process.graft_env(M.env(ctx.cwd:get())), -- use venv env "-m", "pip", "install", diff --git a/lua/nvim-lsp-installer/core/optional.lua b/lua/nvim-lsp-installer/core/optional.lua index d37a7e69..8e68648c 100644 --- a/lua/nvim-lsp-installer/core/optional.lua +++ b/lua/nvim-lsp-installer/core/optional.lua @@ -54,9 +54,9 @@ function Optional:or_else(value) end ---@param supplier fun(): Optional -function Optional:when_empty(supplier) +function Optional:or_(supplier) if self:is_present() then - return self._value + return self else return supplier() end diff --git a/lua/nvim-lsp-installer/core/result.lua b/lua/nvim-lsp-installer/core/result.lua index f5c2d747..74fb9bc8 100644 --- a/lua/nvim-lsp-installer/core/result.lua +++ b/lua/nvim-lsp-installer/core/result.lua @@ -113,6 +113,22 @@ function Result:recover_catching(recover_fn) end end +---@param fn fun(value: any): any +function Result:on_failure(fn) + if self:is_failure() then + fn(self.value.error) + end + return self +end + +---@param fn fun(value: any): any +function Result:on_success(fn) + if self:is_success() then + fn(self.value) + end + return self +end + ---@param fn fun(): any ---@return Result function Result.run_catching(fn) diff --git a/lua/nvim-lsp-installer/health/init.lua b/lua/nvim-lsp-installer/health/init.lua index 0db06461..44a0cdc4 100644 --- a/lua/nvim-lsp-installer/health/init.lua +++ b/lua/nvim-lsp-installer/health/init.lua @@ -1,13 +1,14 @@ local health = require "health" local process = require "nvim-lsp-installer.process" -local gem = require "nvim-lsp-installer.installers.gem" -local composer = require "nvim-lsp-installer.installers.composer" -local npm = require "nvim-lsp-installer.installers.npm" local platform = require "nvim-lsp-installer.platform" local Data = require "nvim-lsp-installer.data" local when = Data.when +local gem_cmd = platform.is_win and "gem.cmd" or "gem" +local composer_cmd = platform.is_win and "composer.bat" or "composer" +local npm_cmd = platform.is_win and "npm.cmd" or "npm" + local M = {} ---@alias HealthCheckResult @@ -156,11 +157,11 @@ function M.check() end, }, check { cmd = "ruby", args = { "--version" }, name = "Ruby", relaxed = true }, - check { cmd = gem.gem_cmd, args = { "--version" }, name = "RubyGem", relaxed = true }, - check { cmd = composer.composer_cmd, args = { "--version" }, name = "Composer", relaxed = true }, + check { cmd = gem_cmd, args = { "--version" }, name = "RubyGem", relaxed = true }, + check { cmd = composer_cmd, args = { "--version" }, name = "Composer", relaxed = true }, check { cmd = "php", args = { "--version" }, name = "PHP", relaxed = true }, check { - cmd = npm.npm_command, + cmd = npm_cmd, args = { "--version" }, name = "npm", version_check = function(version) diff --git a/lua/nvim-lsp-installer/server.lua b/lua/nvim-lsp-installer/server.lua index 5597bba7..de6481a4 100644 --- a/lua/nvim-lsp-installer/server.lua +++ b/lua/nvim-lsp-installer/server.lua @@ -1,14 +1,17 @@ local dispatcher = require "nvim-lsp-installer.dispatcher" local a = require "nvim-lsp-installer.core.async" +local InstallContext = require "nvim-lsp-installer.core.installer.context" local fs = require "nvim-lsp-installer.fs" local log = require "nvim-lsp-installer.log" local platform = require "nvim-lsp-installer.platform" local settings = require "nvim-lsp-installer.settings" local installers = require "nvim-lsp-installer.installers" +local installer = require "nvim-lsp-installer.core.installer" local servers = require "nvim-lsp-installer.servers" local status_win = require "nvim-lsp-installer.ui.status-win" local path = require "nvim-lsp-installer.path" local receipt = require "nvim-lsp-installer.core.receipt" +local Optional = require "nvim-lsp-installer.core.optional" local M = {} @@ -25,6 +28,7 @@ M.get_server_root_path = servers.get_server_install_path ---@field public deprecated ServerDeprecation|nil @The existence (not nil) of this field indicates this server is depracted. ---@field public languages string[] ---@field private _installer ServerInstallerFunction +---@field private _async boolean ---@field private _on_ready_handlers fun(server: Server)[] ---@field private _default_options table @The server's default options. This is used in @see Server#setup. M.Server = {} @@ -38,9 +42,10 @@ function M.Server:new(opts) root_dir = opts.root_dir, homepage = opts.homepage, deprecated = opts.deprecated, + _async = opts.async or false, languages = opts.languages or {}, _on_ready_handlers = {}, - _installer = type(opts.installer) == "function" and opts.installer or installers.pipe(opts.installer), + _installer = opts.installer, _default_options = opts.default_options, }, M.Server) end @@ -208,47 +213,68 @@ end ---@param context ServerInstallContext ---@param callback ServerInstallCallback function M.Server:install_attached(context, callback) - a.run( - function() - context.receipt = receipt.InstallReceiptBuilder.new() - context.receipt:with_start_time(vim.loop.gettimeofday()) - - a.scheduler() - self:_setup_install_context(context) - local async_installer = a.promisify(function(server, context, callback) - -- args are shifted - return self._installer(server, callback, context) - end) - assert(async_installer(self, context), "Installation failed.") - + if self._async then + a.run(function() + local install_context = InstallContext.new { + name = self.name, + boundary_path = settings.current.install_root_dir, + stdio_sink = context.stdio_sink, + destination_dir = self.root_dir, + requested_version = Optional.of_nilable(context.requested_server_version), + } + installer.execute(install_context, self._installer):get_or_throw() a.scheduler() - if not self:promote_install_dir(context.install_dir) then - error(("Failed to promote the temporary installation directory %q."):format(context.install_dir)) + dispatcher.dispatch_server_ready(self) + for _, on_ready_handler in ipairs(self._on_ready_handlers) do + on_ready_handler(self) end + end, callback) + else + --- Deprecated + a.run( + function() + context.receipt = receipt.InstallReceiptBuilder.new() + context.receipt:with_start_time(vim.loop.gettimeofday()) - self:_write_receipt(context.receipt) + a.scheduler() + self:_setup_install_context(context) + local async_installer = a.promisify(function(server, context, callback) + local normalized_installer = type(self._installer) == "function" and self._installer + or installers.pipe(self._installer) + -- args are shifted + return normalized_installer(server, callback, context) + end) + assert(async_installer(self, context), "Installation failed.") - -- Dispatch the server is ready - vim.schedule(function() - dispatcher.dispatch_server_ready(self) - for _, on_ready_handler in ipairs(self._on_ready_handlers) do - on_ready_handler(self) + a.scheduler() + if not self:promote_install_dir(context.install_dir) then + error(("Failed to promote the temporary installation directory %q."):format(context.install_dir)) end + + self:_write_receipt(context.receipt) + + -- Dispatch the server is ready + vim.schedule(function() + dispatcher.dispatch_server_ready(self) + for _, on_ready_handler in ipairs(self._on_ready_handlers) do + on_ready_handler(self) + end + end) + end, + vim.schedule_wrap(function(ok, result) + if not ok then + pcall(fs.rmrf, context.install_dir) + log.fmt_error("Server installation failed, server_name=%s, error=%s", self.name, result) + context.stdio_sink.stderr(tostring(result) .. "\n") + end + -- The tmp dir should in most cases have been "promoted" and already renamed to its final destination, + -- but we make sure to delete it should the installer modify the installation working directory during + -- installation. + pcall(fs.rmrf, self:get_tmp_install_dir()) + callback(ok) end) - end, - vim.schedule_wrap(function(ok, result) - if not ok then - pcall(fs.rmrf, context.install_dir) - log.fmt_error("Server installation failed, server_name=%s, error=%s", self.name, result) - context.stdio_sink.stderr(tostring(result) .. "\n") - end - -- The tmp dir should in most cases have been "promoted" and already renamed to its final destination, - -- but we make sure to delete it should the installer modify the installation working directory during - -- installation. - pcall(fs.rmrf, self:get_tmp_install_dir()) - callback(ok) - end) - ) + ) + end end function M.Server:uninstall() diff --git a/lua/nvim-lsp-installer/servers/angularls/init.lua b/lua/nvim-lsp-installer/servers/angularls/init.lua index feb31190..23970b25 100644 --- a/lua/nvim-lsp-installer/servers/angularls/init.lua +++ b/lua/nvim-lsp-installer/servers/angularls/init.lua @@ -1,6 +1,6 @@ local server = require "nvim-lsp-installer.server" local platform = require "nvim-lsp-installer.platform" -local npm = require "nvim-lsp-installer.installers.npm" +local npm = require "nvim-lsp-installer.core.managers.npm" local Data = require "nvim-lsp-installer.data" local path = require "nvim-lsp-installer.path" @@ -42,6 +42,7 @@ return function(name, root_dir) homepage = "https://angular.io/guide/language-service", languages = { "angular" }, installer = npm.packages { "@angular/language-server", "typescript" }, + async = true, default_options = { cmd = get_cmd(path.cwd()), cmd_env = npm.env(root_dir), diff --git a/lua/nvim-lsp-installer/servers/ansiblels/init.lua b/lua/nvim-lsp-installer/servers/ansiblels/init.lua index 2ee54b65..92541e56 100644 --- a/lua/nvim-lsp-installer/servers/ansiblels/init.lua +++ b/lua/nvim-lsp-installer/servers/ansiblels/init.lua @@ -1,8 +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 npm = require "nvim-lsp-installer.installers.npm" -local context = require "nvim-lsp-installer.installers.context" +local npm = require "nvim-lsp-installer.core.managers.npm" +local git = require "nvim-lsp-installer.core.managers.git" +local installer = require "nvim-lsp-installer.core.installer" return function(name, root_dir) return server.Server:new { @@ -10,14 +10,13 @@ return function(name, root_dir) root_dir = root_dir, languages = { "ansible" }, homepage = "https://github.com/ansible/ansible-language-server", - installer = { - std.git_clone "https://github.com/ansible/ansible-language-server", - npm.install { "npm@latest" }, -- ansiblels has quite a strict npm version requirement - npm.exec(npm.npm_command, { "install" }), - npm.run "compile", - context.receipt(function(receipt) - receipt:with_primary_source(receipt.git_remote "https://github.com/ansible/ansible-language-server") - end), + async = true, + installer = installer.serial { + git.clone { "https://github.com/ansible/ansible-language-server" }, + -- ansiblels has quite a strict npm version requirement. + -- Install dependencies using the the latest npm version. + npm.exec { "npm@latest", "install" }, + npm.run { "compile" }, }, default_options = { cmd = { "node", path.concat { root_dir, "out", "server", "src", "server.js" }, "--stdio" }, diff --git a/lua/nvim-lsp-installer/servers/asm_lsp/init.lua b/lua/nvim-lsp-installer/servers/asm_lsp/init.lua index 35f3ab92..f80f8401 100644 --- a/lua/nvim-lsp-installer/servers/asm_lsp/init.lua +++ b/lua/nvim-lsp-installer/servers/asm_lsp/init.lua @@ -1,5 +1,5 @@ local server = require "nvim-lsp-installer.server" -local cargo = require "nvim-lsp-installer.installers.cargo" +local cargo = require "nvim-lsp-installer.core.managers.cargo" return function(name, root_dir) return server.Server:new { @@ -7,6 +7,7 @@ return function(name, root_dir) root_dir = root_dir, languages = { "assembly-gas", "assembly-nasm", "assembly-go" }, homepage = "https://github.com/bergercookie/asm-lsp", + async = true, installer = cargo.crate "asm-lsp", default_options = { cmd_env = cargo.env(root_dir), diff --git a/lua/nvim-lsp-installer/servers/awk_ls/init.lua b/lua/nvim-lsp-installer/servers/awk_ls/init.lua index 62695777..213abaca 100644 --- a/lua/nvim-lsp-installer/servers/awk_ls/init.lua +++ b/lua/nvim-lsp-installer/servers/awk_ls/init.lua @@ -1,5 +1,5 @@ local server = require "nvim-lsp-installer.server" -local npm = require "nvim-lsp-installer.installers.npm" +local npm = require "nvim-lsp-installer.core.managers.npm" return function(name, root_dir) return server.Server:new { @@ -8,6 +8,7 @@ return function(name, root_dir) languages = { "awk" }, homepage = "https://github.com/Beaglefoot/awk-language-server", installer = npm.packages { "awk-language-server" }, + async = true, default_options = { cmd_env = npm.env(root_dir), }, diff --git a/lua/nvim-lsp-installer/servers/bashls/init.lua b/lua/nvim-lsp-installer/servers/bashls/init.lua index e8a2553e..bb3e5d53 100644 --- a/lua/nvim-lsp-installer/servers/bashls/init.lua +++ b/lua/nvim-lsp-installer/servers/bashls/init.lua @@ -1,5 +1,5 @@ local server = require "nvim-lsp-installer.server" -local npm = require "nvim-lsp-installer.installers.npm" +local npm = require "nvim-lsp-installer.core.managers.npm" return function(name, root_dir) return server.Server:new { @@ -7,6 +7,7 @@ return function(name, root_dir) root_dir = root_dir, languages = { "bash" }, homepage = "https://github.com/bash-lsp/bash-language-server", + async = true, installer = npm.packages { "bash-language-server" }, default_options = { cmd_env = npm.env(root_dir), diff --git a/lua/nvim-lsp-installer/servers/cmake/init.lua b/lua/nvim-lsp-installer/servers/cmake/init.lua index f70624cb..f6c3058a 100644 --- a/lua/nvim-lsp-installer/servers/cmake/init.lua +++ b/lua/nvim-lsp-installer/servers/cmake/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, homepage = "https://github.com/regen100/cmake-language-server", languages = { "cmake" }, + async = true, installer = pip3.packages { "cmake-language-server" }, default_options = { cmd_env = pip3.env(root_dir), diff --git a/lua/nvim-lsp-installer/servers/csharp_ls/init.lua b/lua/nvim-lsp-installer/servers/csharp_ls/init.lua index 82ad4258..8600782d 100644 --- a/lua/nvim-lsp-installer/servers/csharp_ls/init.lua +++ b/lua/nvim-lsp-installer/servers/csharp_ls/init.lua @@ -1,5 +1,5 @@ local server = require "nvim-lsp-installer.server" -local dotnet = require "nvim-lsp-installer.installers.dotnet" +local dotnet = require "nvim-lsp-installer.core.managers.dotnet" return function(name, root_dir) return server.Server:new { @@ -7,6 +7,7 @@ return function(name, root_dir) root_dir = root_dir, languages = { "c#" }, homepage = "https://github.com/razzmatazz/csharp-language-server", + async = true, installer = dotnet.package "csharp-ls", default_options = { cmd_env = dotnet.env(root_dir), diff --git a/lua/nvim-lsp-installer/servers/cssmodules_ls/init.lua b/lua/nvim-lsp-installer/servers/cssmodules_ls/init.lua index b1a6c188..cf09539f 100644 --- a/lua/nvim-lsp-installer/servers/cssmodules_ls/init.lua +++ b/lua/nvim-lsp-installer/servers/cssmodules_ls/init.lua @@ -1,5 +1,5 @@ local server = require "nvim-lsp-installer.server" -local npm = require "nvim-lsp-installer.installers.npm" +local npm = require "nvim-lsp-installer.core.managers.npm" return function(name, root_dir) return server.Server:new { @@ -8,6 +8,7 @@ return function(name, root_dir) homepage = "https://github.com/antonk52/cssmodules-language-server", languages = { "css" }, installer = npm.packages { "cssmodules-language-server" }, + async = true, default_options = { cmd_env = npm.env(root_dir), }, diff --git a/lua/nvim-lsp-installer/servers/cucumber_language_server/init.lua b/lua/nvim-lsp-installer/servers/cucumber_language_server/init.lua index d9b091db..3d810f01 100644 --- a/lua/nvim-lsp-installer/servers/cucumber_language_server/init.lua +++ b/lua/nvim-lsp-installer/servers/cucumber_language_server/init.lua @@ -1,5 +1,5 @@ local server = require "nvim-lsp-installer.server" -local npm = require "nvim-lsp-installer.installers.npm" +local npm = require "nvim-lsp-installer.core.managers.npm" return function(name, root_dir) return server.Server:new { @@ -8,6 +8,7 @@ return function(name, root_dir) languages = { "cucumber" }, homepage = "https://github.com/cucumber/language-server", installer = npm.packages { "@cucumber/language-server" }, + async = true, default_options = { cmd_env = npm.env(root_dir), }, diff --git a/lua/nvim-lsp-installer/servers/diagnosticls/init.lua b/lua/nvim-lsp-installer/servers/diagnosticls/init.lua index 5594eca2..9b822a2b 100644 --- a/lua/nvim-lsp-installer/servers/diagnosticls/init.lua +++ b/lua/nvim-lsp-installer/servers/diagnosticls/init.lua @@ -1,5 +1,5 @@ local server = require "nvim-lsp-installer.server" -local npm = require "nvim-lsp-installer.installers.npm" +local npm = require "nvim-lsp-installer.core.managers.npm" return function(name, root_dir) return server.Server:new { @@ -8,6 +8,7 @@ return function(name, root_dir) languages = {}, homepage = "https://github.com/iamcco/diagnostic-languageserver", installer = npm.packages { "diagnostic-languageserver" }, + async = true, default_options = { cmd_env = npm.env(root_dir), }, diff --git a/lua/nvim-lsp-installer/servers/dockerls/init.lua b/lua/nvim-lsp-installer/servers/dockerls/init.lua index ab306ff2..45ce6806 100644 --- a/lua/nvim-lsp-installer/servers/dockerls/init.lua +++ b/lua/nvim-lsp-installer/servers/dockerls/init.lua @@ -1,5 +1,5 @@ local server = require "nvim-lsp-installer.server" -local npm = require "nvim-lsp-installer.installers.npm" +local npm = require "nvim-lsp-installer.core.managers.npm" return function(name, root_dir) return server.Server:new { @@ -8,6 +8,7 @@ return function(name, root_dir) homepage = "https://github.com/rcjsuen/dockerfile-language-server-nodejs", languages = { "docker" }, installer = npm.packages { "dockerfile-language-server-nodejs" }, + async = true, default_options = { cmd_env = npm.env(root_dir), }, diff --git a/lua/nvim-lsp-installer/servers/dotls/init.lua b/lua/nvim-lsp-installer/servers/dotls/init.lua index b4655e52..26400b65 100644 --- a/lua/nvim-lsp-installer/servers/dotls/init.lua +++ b/lua/nvim-lsp-installer/servers/dotls/init.lua @@ -1,5 +1,5 @@ local server = require "nvim-lsp-installer.server" -local npm = require "nvim-lsp-installer.installers.npm" +local npm = require "nvim-lsp-installer.core.managers.npm" return function(name, root_dir) return server.Server:new { @@ -8,6 +8,7 @@ return function(name, root_dir) homepage = "https://github.com/nikeee/dot-language-server", languages = { "dot" }, installer = npm.packages { "dot-language-server" }, + async = true, default_options = { cmd_env = npm.env(root_dir), }, diff --git a/lua/nvim-lsp-installer/servers/elmls/init.lua b/lua/nvim-lsp-installer/servers/elmls/init.lua index 8d5e0041..30eebfd3 100644 --- a/lua/nvim-lsp-installer/servers/elmls/init.lua +++ b/lua/nvim-lsp-installer/servers/elmls/init.lua @@ -1,5 +1,5 @@ local server = require "nvim-lsp-installer.server" -local npm = require "nvim-lsp-installer.installers.npm" +local npm = require "nvim-lsp-installer.core.managers.npm" return function(name, root_dir) return server.Server:new { @@ -8,6 +8,7 @@ return function(name, root_dir) homepage = "https://github.com/elm-tooling/elm-language-server", languages = { "elm" }, installer = npm.packages { "@elm-tooling/elm-language-server", "elm", "elm-test", "elm-format" }, + async = true, default_options = { cmd_env = npm.env(root_dir), }, diff --git a/lua/nvim-lsp-installer/servers/ember/init.lua b/lua/nvim-lsp-installer/servers/ember/init.lua index 80c417b6..3ebddec9 100644 --- a/lua/nvim-lsp-installer/servers/ember/init.lua +++ b/lua/nvim-lsp-installer/servers/ember/init.lua @@ -1,5 +1,5 @@ local server = require "nvim-lsp-installer.server" -local npm = require "nvim-lsp-installer.installers.npm" +local npm = require "nvim-lsp-installer.core.managers.npm" return function(name, root_dir) return server.Server:new { @@ -8,6 +8,7 @@ return function(name, root_dir) languages = { "ember" }, homepage = "https://github.com/lifeart/ember-language-server", installer = npm.packages { "@lifeart/ember-language-server" }, + async = true, default_options = { cmd_env = npm.env(root_dir), }, diff --git a/lua/nvim-lsp-installer/servers/emmet_ls/init.lua b/lua/nvim-lsp-installer/servers/emmet_ls/init.lua index 93fa181c..91258daa 100644 --- a/lua/nvim-lsp-installer/servers/emmet_ls/init.lua +++ b/lua/nvim-lsp-installer/servers/emmet_ls/init.lua @@ -1,5 +1,5 @@ local server = require "nvim-lsp-installer.server" -local npm = require "nvim-lsp-installer.installers.npm" +local npm = require "nvim-lsp-installer.core.managers.npm" return function(name, root_dir) return server.Server:new { @@ -8,6 +8,7 @@ return function(name, root_dir) homepage = "https://github.com/aca/emmet-ls", languages = { "emmet" }, installer = npm.packages { "emmet-ls" }, + async = true, default_options = { cmd_env = npm.env(root_dir), }, diff --git a/lua/nvim-lsp-installer/servers/esbonio/init.lua b/lua/nvim-lsp-installer/servers/esbonio/init.lua index 173eb44c..b0de81d7 100644 --- a/lua/nvim-lsp-installer/servers/esbonio/init.lua +++ b/lua/nvim-lsp-installer/servers/esbonio/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 = { "sphinx" }, homepage = "https://pypi.org/project/esbonio/", + async = true, installer = pip3.packages { "esbonio" }, default_options = { cmd_env = pip3.env(root_dir), diff --git a/lua/nvim-lsp-installer/servers/flux_lsp/init.lua b/lua/nvim-lsp-installer/servers/flux_lsp/init.lua index 0475528f..be9ffce5 100644 --- a/lua/nvim-lsp-installer/servers/flux_lsp/init.lua +++ b/lua/nvim-lsp-installer/servers/flux_lsp/init.lua @@ -1,5 +1,5 @@ local server = require "nvim-lsp-installer.server" -local cargo = require "nvim-lsp-installer.installers.cargo" +local cargo = require "nvim-lsp-installer.core.managers.cargo" return function(name, root_dir) return server.Server:new { @@ -7,6 +7,7 @@ return function(name, root_dir) root_dir = root_dir, languages = { "flux" }, homepage = "https://github.com/influxdata/flux-lsp", + async = true, installer = cargo.crate("https://github.com/influxdata/flux-lsp", { git = true, }), diff --git a/lua/nvim-lsp-installer/servers/foam_ls/init.lua b/lua/nvim-lsp-installer/servers/foam_ls/init.lua index 2e28fe08..2586b242 100644 --- a/lua/nvim-lsp-installer/servers/foam_ls/init.lua +++ b/lua/nvim-lsp-installer/servers/foam_ls/init.lua @@ -1,6 +1,5 @@ local server = require "nvim-lsp-installer.server" -local path = require "nvim-lsp-installer.path" -local npm = require "nvim-lsp-installer.installers.npm" +local npm = require "nvim-lsp-installer.core.managers.npm" return function(name, root_dir) return server.Server:new { @@ -9,6 +8,7 @@ return function(name, root_dir) homepage = "https://github.com/FoamScience/foam-language-server", languages = { "foam", "OpenFOAM" }, installer = npm.packages { "foam-language-server" }, + async = true, default_options = { cmd_env = npm.env(root_dir), }, diff --git a/lua/nvim-lsp-installer/servers/fortls/init.lua b/lua/nvim-lsp-installer/servers/fortls/init.lua index aade0502..466dc910 100644 --- a/lua/nvim-lsp-installer/servers/fortls/init.lua +++ b/lua/nvim-lsp-installer/servers/fortls/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, homepage = "https://github.com/hansec/fortran-language-server", languages = { "fortran" }, + async = true, installer = pip3.packages { "fortran-language-server" }, default_options = { cmd_env = pip3.env(root_dir), diff --git a/lua/nvim-lsp-installer/servers/fsautocomplete/init.lua b/lua/nvim-lsp-installer/servers/fsautocomplete/init.lua index cd1284e7..fd075ba7 100644 --- a/lua/nvim-lsp-installer/servers/fsautocomplete/init.lua +++ b/lua/nvim-lsp-installer/servers/fsautocomplete/init.lua @@ -1,5 +1,5 @@ local server = require "nvim-lsp-installer.server" -local dotnet = require "nvim-lsp-installer.installers.dotnet" +local dotnet = require "nvim-lsp-installer.core.managers.dotnet" return function(name, root_dir) return server.Server:new { @@ -7,6 +7,7 @@ return function(name, root_dir) root_dir = root_dir, languages = { "f#" }, homepage = "https://github.com/fsharp/FsAutoComplete", + async = true, installer = dotnet.package "fsautocomplete", default_options = { cmd_env = dotnet.env(root_dir), diff --git a/lua/nvim-lsp-installer/servers/grammarly/init.lua b/lua/nvim-lsp-installer/servers/grammarly/init.lua index 1c8d7646..58c7a217 100644 --- a/lua/nvim-lsp-installer/servers/grammarly/init.lua +++ b/lua/nvim-lsp-installer/servers/grammarly/init.lua @@ -1,5 +1,5 @@ local server = require "nvim-lsp-installer.server" -local npm = require "nvim-lsp-installer.installers.npm" +local npm = require "nvim-lsp-installer.core.managers.npm" return function(name, root_dir) return server.Server:new { @@ -8,6 +8,7 @@ return function(name, root_dir) homepage = "https://github.com/znck/grammarly", languages = {}, installer = npm.packages { "@emacs-grammarly/unofficial-grammarly-language-server" }, + async = true, default_options = { cmd_env = npm.env(root_dir), }, diff --git a/lua/nvim-lsp-installer/servers/graphql/init.lua b/lua/nvim-lsp-installer/servers/graphql/init.lua index c513208e..fe0ac0f0 100644 --- a/lua/nvim-lsp-installer/servers/graphql/init.lua +++ b/lua/nvim-lsp-installer/servers/graphql/init.lua @@ -1,5 +1,5 @@ local server = require "nvim-lsp-installer.server" -local npm = require "nvim-lsp-installer.installers.npm" +local npm = require "nvim-lsp-installer.core.managers.npm" return function(name, root_dir) return server.Server:new { @@ -8,6 +8,7 @@ return function(name, root_dir) homepage = "https://www.npmjs.com/package/graphql-language-service-cli", languages = { "graphql" }, installer = npm.packages { "graphql-language-service-cli", "graphql" }, + async = true, default_options = { cmd_env = npm.env(root_dir), }, diff --git a/lua/nvim-lsp-installer/servers/intelephense/init.lua b/lua/nvim-lsp-installer/servers/intelephense/init.lua index a606ce35..e4e86c29 100644 --- a/lua/nvim-lsp-installer/servers/intelephense/init.lua +++ b/lua/nvim-lsp-installer/servers/intelephense/init.lua @@ -1,5 +1,5 @@ local server = require "nvim-lsp-installer.server" -local npm = require "nvim-lsp-installer.installers.npm" +local npm = require "nvim-lsp-installer.core.managers.npm" return function(name, root_dir) return server.Server:new { @@ -8,6 +8,7 @@ return function(name, root_dir) homepage = "https://intelephense.com", languages = { "php" }, installer = npm.packages { "intelephense" }, + async = true, default_options = { cmd_env = npm.env(root_dir), }, diff --git a/lua/nvim-lsp-installer/servers/jedi_language_server/init.lua b/lua/nvim-lsp-installer/servers/jedi_language_server/init.lua index 2a7b300a..86c4ebe1 100644 --- a/lua/nvim-lsp-installer/servers/jedi_language_server/init.lua +++ b/lua/nvim-lsp-installer/servers/jedi_language_server/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://github.com/pappasam/jedi-language-server", + async = true, installer = pip3.packages { "jedi-language-server" }, default_options = { cmd_env = pip3.env(root_dir), diff --git a/lua/nvim-lsp-installer/servers/lelwel_ls/init.lua b/lua/nvim-lsp-installer/servers/lelwel_ls/init.lua index b00dbdfa..d69aedd5 100644 --- a/lua/nvim-lsp-installer/servers/lelwel_ls/init.lua +++ b/lua/nvim-lsp-installer/servers/lelwel_ls/init.lua @@ -1,5 +1,5 @@ local server = require "nvim-lsp-installer.server" -local cargo = require "nvim-lsp-installer.installers.cargo" +local cargo = require "nvim-lsp-installer.core.managers.cargo" return function(name, root_dir) return server.Server:new { @@ -7,6 +7,7 @@ return function(name, root_dir) root_dir = root_dir, languages = { "lelwel" }, homepage = "https://github.com/0x2a-42/lelwel", + async = true, installer = cargo.crate("lelwel", { features = "lsp", }), diff --git a/lua/nvim-lsp-installer/servers/nickel_ls/init.lua b/lua/nvim-lsp-installer/servers/nickel_ls/init.lua index d87062e7..bf87cd21 100644 --- a/lua/nvim-lsp-installer/servers/nickel_ls/init.lua +++ b/lua/nvim-lsp-installer/servers/nickel_ls/init.lua @@ -1,8 +1,8 @@ local path = require "nvim-lsp-installer.path" local server = require "nvim-lsp-installer.server" -local std = require "nvim-lsp-installer.installers.std" -local context = require "nvim-lsp-installer.installers.context" -local cargo = require "nvim-lsp-installer.installers.cargo" +local installer = require "nvim-lsp-installer.core.installer" +local cargo = require "nvim-lsp-installer.core.managers.cargo" +local git = require "nvim-lsp-installer.core.managers.git" return function(name, root_dir) return server.Server:new { @@ -10,14 +10,19 @@ return function(name, root_dir) root_dir = root_dir, homepage = "https://nickel-lang.org/", languages = { "nickel" }, - installer = { - std.git_clone "https://github.com/tweag/nickel", - cargo.install { - path = path.concat { "lsp", "nls" }, - }, - context.receipt(function(receipt) - receipt:with_primary_source(receipt.git_remote "https://github.com/tweag/nickel") - end), + async = true, + installer = installer.serial { + git.clone { "https://github.com/tweag/nickel" }, + ---@param ctx InstallContext + function(ctx) + ctx.spawn.cargo { + "install", + "--root", + ".", + "--path", + path.concat { "lsp", "nls" }, + } + end, }, default_options = { cmd_env = cargo.env(root_dir), diff --git a/lua/nvim-lsp-installer/servers/ocamlls/init.lua b/lua/nvim-lsp-installer/servers/ocamlls/init.lua index 80361b4c..062be8e7 100644 --- a/lua/nvim-lsp-installer/servers/ocamlls/init.lua +++ b/lua/nvim-lsp-installer/servers/ocamlls/init.lua @@ -1,5 +1,5 @@ local server = require "nvim-lsp-installer.server" -local npm = require "nvim-lsp-installer.installers.npm" +local npm = require "nvim-lsp-installer.core.managers.npm" return function(name, root_dir) return server.Server:new { @@ -12,6 +12,7 @@ return function(name, root_dir) homepage = "https://github.com/ocaml-lsp/ocaml-language-server", languages = { "ocaml" }, installer = npm.packages { "ocaml-language-server" }, + async = true, default_options = { cmd_env = npm.env(root_dir), }, diff --git a/lua/nvim-lsp-installer/servers/ocamllsp/init.lua b/lua/nvim-lsp-installer/servers/ocamllsp/init.lua index 73b6bab8..ad51cfa4 100644 --- a/lua/nvim-lsp-installer/servers/ocamllsp/init.lua +++ b/lua/nvim-lsp-installer/servers/ocamllsp/init.lua @@ -1,5 +1,5 @@ local server = require "nvim-lsp-installer.server" -local opam = require "nvim-lsp-installer.installers.opam" +local opam = require "nvim-lsp-installer.core.managers.opam" 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/ocaml/ocaml-lsp", languages = { "ocaml" }, + async = true, installer = opam.packages { "ocaml-lsp-server" }, default_options = { cmd_env = opam.env(root_dir), diff --git a/lua/nvim-lsp-installer/servers/perlnavigator/init.lua b/lua/nvim-lsp-installer/servers/perlnavigator/init.lua index c944eeb9..fc82fe3c 100644 --- a/lua/nvim-lsp-installer/servers/perlnavigator/init.lua +++ b/lua/nvim-lsp-installer/servers/perlnavigator/init.lua @@ -1,6 +1,6 @@ local server = require "nvim-lsp-installer.server" local path = require "nvim-lsp-installer.path" -local npm = require "nvim-lsp-installer.installers.npm" +local npm = require "nvim-lsp-installer.core.managers.npm" return function(name, root_dir) return server.Server:new { @@ -9,6 +9,7 @@ return function(name, root_dir) languages = { "perl" }, homepage = "https://github.com/bscan/PerlNavigator", installer = npm.packages { "perlnavigator-server" }, + async = true, default_options = { cmd = { "node", diff --git a/lua/nvim-lsp-installer/servers/phpactor/init.lua b/lua/nvim-lsp-installer/servers/phpactor/init.lua index 45ce5ccd..af5d863c 100644 --- a/lua/nvim-lsp-installer/servers/phpactor/init.lua +++ b/lua/nvim-lsp-installer/servers/phpactor/init.lua @@ -1,10 +1,10 @@ -local installers = require "nvim-lsp-installer.installers" local path = require "nvim-lsp-installer.path" local server = require "nvim-lsp-installer.server" -local composer = require "nvim-lsp-installer.installers.composer" -local std = require "nvim-lsp-installer.installers.std" -local context = require "nvim-lsp-installer.installers.context" +local composer = require "nvim-lsp-installer.core.managers.composer" +local git = require "nvim-lsp-installer.core.managers.git" +local installer = require "nvim-lsp-installer.core.installer" local process = require "nvim-lsp-installer.process" +local platform = require "nvim-lsp-installer.platform" return function(name, root_dir) return server.Server:new { @@ -12,14 +12,13 @@ return function(name, root_dir) root_dir = root_dir, homepage = "https://phpactor.readthedocs.io/en/master/", languages = { "php" }, - installer = installers.when { - unix = { - std.git_clone "https://github.com/phpactor/phpactor.git", - composer.install(), - context.receipt(function(receipt) - receipt:with_primary_source(receipt.git_remote "https://github.com/phpactor/phpactor.git") - end), - }, + async = true, + installer = installer.serial { + function() + assert(platform.is_unix, "Phpactor only supports UNIX environments.") + end, + git.clone { "https://github.com/phpactor/phpactor.git" }, + composer.install(), }, default_options = { cmd_env = { diff --git a/lua/nvim-lsp-installer/servers/prismals/init.lua b/lua/nvim-lsp-installer/servers/prismals/init.lua index e7e38391..e42aa1a1 100644 --- a/lua/nvim-lsp-installer/servers/prismals/init.lua +++ b/lua/nvim-lsp-installer/servers/prismals/init.lua @@ -1,5 +1,5 @@ local server = require "nvim-lsp-installer.server" -local npm = require "nvim-lsp-installer.installers.npm" +local npm = require "nvim-lsp-installer.core.managers.npm" return function(name, root_dir) return server.Server:new { @@ -8,6 +8,7 @@ return function(name, root_dir) languages = { "prisma" }, homepage = "https://github.com/prisma/language-tools", installer = npm.packages { "@prisma/language-server" }, + async = true, default_options = { cmd_env = npm.env(root_dir), }, diff --git a/lua/nvim-lsp-installer/servers/psalm/init.lua b/lua/nvim-lsp-installer/servers/psalm/init.lua index 3b3d4721..8c8b9be3 100644 --- a/lua/nvim-lsp-installer/servers/psalm/init.lua +++ b/lua/nvim-lsp-installer/servers/psalm/init.lua @@ -1,5 +1,5 @@ local server = require "nvim-lsp-installer.server" -local composer = require "nvim-lsp-installer.installers.composer" +local composer = require "nvim-lsp-installer.core.managers.composer" return function(name, root_dir) return server.Server:new { @@ -7,6 +7,7 @@ return function(name, root_dir) root_dir = root_dir, homepage = "https://psalm.dev/", languages = { "php" }, + async = true, installer = composer.require { "vimeo/psalm" }, default_options = { cmd_env = composer.env(root_dir), diff --git a/lua/nvim-lsp-installer/servers/purescriptls/init.lua b/lua/nvim-lsp-installer/servers/purescriptls/init.lua index 710d6d47..338bb82c 100644 --- a/lua/nvim-lsp-installer/servers/purescriptls/init.lua +++ b/lua/nvim-lsp-installer/servers/purescriptls/init.lua @@ -1,5 +1,5 @@ local server = require "nvim-lsp-installer.server" -local npm = require "nvim-lsp-installer.installers.npm" +local npm = require "nvim-lsp-installer.core.managers.npm" return function(name, root_dir) return server.Server:new { @@ -8,6 +8,7 @@ return function(name, root_dir) languages = { "purescript" }, homepage = "https://github.com/nwolverson/purescript-language-server", installer = npm.packages { "purescript-language-server" }, + async = true, default_options = { cmd_env = npm.env(root_dir), }, diff --git a/lua/nvim-lsp-installer/servers/pylsp/init.lua b/lua/nvim-lsp-installer/servers/pylsp/init.lua index a676109b..0ee9e6a0 100644 --- a/lua/nvim-lsp-installer/servers/pylsp/init.lua +++ b/lua/nvim-lsp-installer/servers/pylsp/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" local process = require "nvim-lsp-installer.process" local notify = require "nvim-lsp-installer.notify" @@ -21,6 +21,7 @@ return function(name, root_dir) root_dir = root_dir, languages = { "python" }, homepage = "https://github.com/python-lsp/python-lsp-server", + async = true, installer = pip3.packages { "python-lsp-server[all]" }, default_options = { cmd_env = pip3.env(root_dir), diff --git a/lua/nvim-lsp-installer/servers/pyright/init.lua b/lua/nvim-lsp-installer/servers/pyright/init.lua index 8bdcaebd..73c6bed3 100644 --- a/lua/nvim-lsp-installer/servers/pyright/init.lua +++ b/lua/nvim-lsp-installer/servers/pyright/init.lua @@ -1,5 +1,5 @@ local server = require "nvim-lsp-installer.server" -local npm = require "nvim-lsp-installer.installers.npm" +local npm = require "nvim-lsp-installer.core.managers.npm" return function(name, root_dir) return server.Server:new { @@ -8,6 +8,7 @@ return function(name, root_dir) languages = { "python" }, homepage = "https://github.com/microsoft/pyright", installer = npm.packages { "pyright" }, + async = true, default_options = { cmd_env = npm.env(root_dir), }, diff --git a/lua/nvim-lsp-installer/servers/remark_ls/init.lua b/lua/nvim-lsp-installer/servers/remark_ls/init.lua index 860b2db1..acc7c2f3 100644 --- a/lua/nvim-lsp-installer/servers/remark_ls/init.lua +++ b/lua/nvim-lsp-installer/servers/remark_ls/init.lua @@ -1,5 +1,5 @@ local server = require "nvim-lsp-installer.server" -local npm = require "nvim-lsp-installer.installers.npm" +local npm = require "nvim-lsp-installer.core.managers.npm" return function(name, root_dir) return server.Server:new { @@ -8,6 +8,7 @@ return function(name, root_dir) homepage = "https://github.com/remarkjs/remark-language-server", languages = { "markdown" }, installer = npm.packages { "remark-language-server" }, + async = true, default_options = { cmd_env = npm.env(root_dir), }, diff --git a/lua/nvim-lsp-installer/servers/rnix/init.lua b/lua/nvim-lsp-installer/servers/rnix/init.lua index 35290aae..d552b11c 100644 --- a/lua/nvim-lsp-installer/servers/rnix/init.lua +++ b/lua/nvim-lsp-installer/servers/rnix/init.lua @@ -1,5 +1,5 @@ local server = require "nvim-lsp-installer.server" -local cargo = require "nvim-lsp-installer.installers.cargo" +local cargo = require "nvim-lsp-installer.core.managers.cargo" return function(name, root_dir) return server.Server:new { @@ -7,6 +7,7 @@ return function(name, root_dir) root_dir = root_dir, languages = { "nix" }, homepage = "https://github.com/nix-community/rnix-lsp", + async = true, installer = cargo.crate "rnix-lsp", default_options = { cmd_env = cargo.env(root_dir), diff --git a/lua/nvim-lsp-installer/servers/rome/init.lua b/lua/nvim-lsp-installer/servers/rome/init.lua index ca1f25bf..7a20384c 100644 --- a/lua/nvim-lsp-installer/servers/rome/init.lua +++ b/lua/nvim-lsp-installer/servers/rome/init.lua @@ -1,7 +1,7 @@ local server = require "nvim-lsp-installer.server" -local npm = require "nvim-lsp-installer.installers.npm" -local Data = require "nvim-lsp-installer.data" -local context = require "nvim-lsp-installer.installers.context" +local npm = require "nvim-lsp-installer.core.managers.npm" +local installer = require "nvim-lsp-installer.core.installer" +local Optional = require "nvim-lsp-installer.core.optional" return function(name, root_dir) return server.Server:new { @@ -9,15 +9,16 @@ return function(name, root_dir) root_dir = root_dir, languages = { "typescript", "javascript" }, homepage = "https://rome.tools", - installer = { - context.set(function(ctx) - ctx.requested_server_version = Data.coalesce( - ctx.requested_server_version, - "10.0.7-nightly.2021.7.27" -- https://github.com/rome/tools/pull/1409 - ) - end), + installer = installer.serial { + ---@param ctx InstallContext + function(ctx) + ctx.requested_version = ctx.requested_version:or_(function() + return Optional.of "10.0.7-nightly.2021.7.27" + end) + end, npm.packages { "rome" }, }, + async = true, default_options = { cmd_env = npm.env(root_dir), }, diff --git a/lua/nvim-lsp-installer/servers/salt_ls/init.lua b/lua/nvim-lsp-installer/servers/salt_ls/init.lua index 8101fa2e..f8d27a7e 100644 --- a/lua/nvim-lsp-installer/servers/salt_ls/init.lua +++ b/lua/nvim-lsp-installer/servers/salt_ls/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 = { "sls" }, homepage = "https://github.com/dcermak/salt-lsp", + async = true, installer = pip3.packages { "salt-lsp" }, default_options = { cmd_env = pip3.env(root_dir), diff --git a/lua/nvim-lsp-installer/servers/solidity_ls/init.lua b/lua/nvim-lsp-installer/servers/solidity_ls/init.lua index 451738f6..577b5c35 100644 --- a/lua/nvim-lsp-installer/servers/solidity_ls/init.lua +++ b/lua/nvim-lsp-installer/servers/solidity_ls/init.lua @@ -1,5 +1,5 @@ local server = require "nvim-lsp-installer.server" -local npm = require "nvim-lsp-installer.installers.npm" +local npm = require "nvim-lsp-installer.core.managers.npm" return function(name, root_dir) return server.Server:new { @@ -8,6 +8,7 @@ return function(name, root_dir) languages = { "solidity" }, homepage = "https://github.com/edag94/vscode-solidity", installer = npm.packages { "solidity-language-server" }, + async = true, default_options = { cmd_env = npm.env(root_dir), }, diff --git a/lua/nvim-lsp-installer/servers/sqlls/init.lua b/lua/nvim-lsp-installer/servers/sqlls/init.lua index 7e6e0dff..3e562608 100644 --- a/lua/nvim-lsp-installer/servers/sqlls/init.lua +++ b/lua/nvim-lsp-installer/servers/sqlls/init.lua @@ -1,5 +1,5 @@ local server = require "nvim-lsp-installer.server" -local npm = require "nvim-lsp-installer.installers.npm" +local npm = require "nvim-lsp-installer.core.managers.npm" return function(name, root_dir) return server.Server:new { @@ -8,6 +8,7 @@ return function(name, root_dir) languages = { "sql" }, homepage = "https://github.com/joe-re/sql-language-server", installer = npm.packages { "sql-language-server" }, + async = true, default_options = { cmd_env = npm.env(root_dir), }, diff --git a/lua/nvim-lsp-installer/servers/stylelint_lsp/init.lua b/lua/nvim-lsp-installer/servers/stylelint_lsp/init.lua index 1bfbe7f3..6d52b3b2 100644 --- a/lua/nvim-lsp-installer/servers/stylelint_lsp/init.lua +++ b/lua/nvim-lsp-installer/servers/stylelint_lsp/init.lua @@ -1,5 +1,5 @@ local server = require "nvim-lsp-installer.server" -local npm = require "nvim-lsp-installer.installers.npm" +local npm = require "nvim-lsp-installer.core.managers.npm" return function(name, root_dir) return server.Server:new { @@ -8,6 +8,7 @@ return function(name, root_dir) homepage = "https://github.com/bmatcuk/stylelint-lsp", languages = { "stylelint" }, installer = npm.packages { "stylelint-lsp" }, + async = true, default_options = { cmd_env = npm.env(root_dir), }, diff --git a/lua/nvim-lsp-installer/servers/svelte/init.lua b/lua/nvim-lsp-installer/servers/svelte/init.lua index b14dc247..3cc545b0 100644 --- a/lua/nvim-lsp-installer/servers/svelte/init.lua +++ b/lua/nvim-lsp-installer/servers/svelte/init.lua @@ -1,5 +1,5 @@ local server = require "nvim-lsp-installer.server" -local npm = require "nvim-lsp-installer.installers.npm" +local npm = require "nvim-lsp-installer.core.managers.npm" return function(name, root_dir) return server.Server:new { @@ -8,6 +8,7 @@ return function(name, root_dir) languages = { "svelte" }, homepage = "https://github.com/sveltejs/language-tools", installer = npm.packages { "svelte-language-server" }, + async = true, default_options = { cmd_env = npm.env(root_dir), }, diff --git a/lua/nvim-lsp-installer/servers/svls/init.lua b/lua/nvim-lsp-installer/servers/svls/init.lua index 401ee965..58a46432 100644 --- a/lua/nvim-lsp-installer/servers/svls/init.lua +++ b/lua/nvim-lsp-installer/servers/svls/init.lua @@ -1,5 +1,5 @@ local server = require "nvim-lsp-installer.server" -local cargo = require "nvim-lsp-installer.installers.cargo" +local cargo = require "nvim-lsp-installer.core.managers.cargo" return function(name, root_dir) return server.Server:new { @@ -7,6 +7,7 @@ return function(name, root_dir) root_dir = root_dir, languages = { "systemverilog" }, homepage = "https://github.com/dalance/svls", + async = true, installer = cargo.crate "svls", default_options = { cmd_env = cargo.env(root_dir), diff --git a/lua/nvim-lsp-installer/servers/tailwindcss/init.lua b/lua/nvim-lsp-installer/servers/tailwindcss/init.lua index d62e70bd..d24948b0 100644 --- a/lua/nvim-lsp-installer/servers/tailwindcss/init.lua +++ b/lua/nvim-lsp-installer/servers/tailwindcss/init.lua @@ -1,5 +1,5 @@ local server = require "nvim-lsp-installer.server" -local npm = require "nvim-lsp-installer.installers.npm" +local npm = require "nvim-lsp-installer.core.managers.npm" return function(name, root_dir) return server.Server:new { @@ -7,6 +7,7 @@ return function(name, root_dir) root_dir = root_dir, languages = { "tailwind" }, installer = npm.packages { "@tailwindcss/language-server" }, + async = true, default_options = { cmd_env = npm.env(root_dir), }, diff --git a/lua/nvim-lsp-installer/servers/taplo/init.lua b/lua/nvim-lsp-installer/servers/taplo/init.lua index 94ddcc62..0d584e6b 100644 --- a/lua/nvim-lsp-installer/servers/taplo/init.lua +++ b/lua/nvim-lsp-installer/servers/taplo/init.lua @@ -1,5 +1,5 @@ local server = require "nvim-lsp-installer.server" -local cargo = require "nvim-lsp-installer.installers.cargo" +local cargo = require "nvim-lsp-installer.core.managers.cargo" return function(name, root_dir) return server.Server:new { @@ -7,6 +7,7 @@ return function(name, root_dir) root_dir = root_dir, languages = { "toml" }, homepage = "https://taplo.tamasfe.dev/lsp/", + async = true, installer = cargo.crate "taplo-cli", default_options = { cmd_env = cargo.env(root_dir), diff --git a/lua/nvim-lsp-installer/servers/tsserver/init.lua b/lua/nvim-lsp-installer/servers/tsserver/init.lua index 5b192475..22091418 100644 --- a/lua/nvim-lsp-installer/servers/tsserver/init.lua +++ b/lua/nvim-lsp-installer/servers/tsserver/init.lua @@ -1,5 +1,5 @@ local server = require "nvim-lsp-installer.server" -local npm = require "nvim-lsp-installer.installers.npm" +local npm = require "nvim-lsp-installer.core.managers.npm" return function(name, root_dir) return server.Server:new { @@ -8,6 +8,7 @@ return function(name, root_dir) languages = { "typescript", "javascript" }, homepage = "https://github.com/typescript-language-server/typescript-language-server", installer = npm.packages { "typescript-language-server", "typescript" }, + async = true, default_options = { cmd_env = npm.env(root_dir), }, diff --git a/lua/nvim-lsp-installer/servers/vimls/init.lua b/lua/nvim-lsp-installer/servers/vimls/init.lua index 28c7d26b..b753e92a 100644 --- a/lua/nvim-lsp-installer/servers/vimls/init.lua +++ b/lua/nvim-lsp-installer/servers/vimls/init.lua @@ -1,5 +1,5 @@ local server = require "nvim-lsp-installer.server" -local npm = require "nvim-lsp-installer.installers.npm" +local npm = require "nvim-lsp-installer.core.managers.npm" return function(name, root_dir) return server.Server:new { @@ -8,6 +8,7 @@ return function(name, root_dir) languages = { "vim" }, homepage = "https://github.com/iamcco/vim-language-server", installer = npm.packages { "vim-language-server" }, + async = true, default_options = { cmd_env = npm.env(root_dir), }, diff --git a/lua/nvim-lsp-installer/servers/volar/init.lua b/lua/nvim-lsp-installer/servers/volar/init.lua index 769689b4..4bdda7b0 100644 --- a/lua/nvim-lsp-installer/servers/volar/init.lua +++ b/lua/nvim-lsp-installer/servers/volar/init.lua @@ -1,7 +1,7 @@ local path = require "nvim-lsp-installer.path" local fs = require "nvim-lsp-installer.fs" local server = require "nvim-lsp-installer.server" -local npm = require "nvim-lsp-installer.installers.npm" +local npm = require "nvim-lsp-installer.core.managers.npm" return function(name, root_dir) ---@param dir string @@ -26,6 +26,7 @@ return function(name, root_dir) homepage = "https://github.com/johnsoncodehk/volar", languages = { "vue" }, installer = npm.packages { "@volar/vue-language-server", "typescript" }, + async = true, default_options = { cmd_env = npm.env(root_dir), on_new_config = function(new_config, new_root_dir) diff --git a/lua/nvim-lsp-installer/servers/vscode-langservers-extracted/init.lua b/lua/nvim-lsp-installer/servers/vscode-langservers-extracted/init.lua index 83493834..22c2b045 100644 --- a/lua/nvim-lsp-installer/servers/vscode-langservers-extracted/init.lua +++ b/lua/nvim-lsp-installer/servers/vscode-langservers-extracted/init.lua @@ -1,5 +1,5 @@ local server = require "nvim-lsp-installer.server" -local npm = require "nvim-lsp-installer.installers.npm" +local npm = require "nvim-lsp-installer.core.managers.npm" ---@param languages string[] return function(languages) @@ -9,6 +9,7 @@ return function(languages) languages = languages, root_dir = root_dir, installer = npm.packages { "vscode-langservers-extracted" }, + async = true, default_options = { cmd_env = npm.env(root_dir), }, diff --git a/lua/nvim-lsp-installer/servers/vuels/init.lua b/lua/nvim-lsp-installer/servers/vuels/init.lua index 19f19faf..4b630142 100644 --- a/lua/nvim-lsp-installer/servers/vuels/init.lua +++ b/lua/nvim-lsp-installer/servers/vuels/init.lua @@ -1,5 +1,5 @@ local server = require "nvim-lsp-installer.server" -local npm = require "nvim-lsp-installer.installers.npm" +local npm = require "nvim-lsp-installer.core.managers.npm" return function(name, root_dir) return server.Server:new { @@ -8,6 +8,7 @@ return function(name, root_dir) languages = { "vue" }, homepage = "https://github.com/vuejs/vetur", installer = npm.packages { "vls" }, + async = true, default_options = { cmd_env = npm.env(root_dir), }, diff --git a/lua/nvim-lsp-installer/servers/yamlls/init.lua b/lua/nvim-lsp-installer/servers/yamlls/init.lua index 648b5a57..bbd94e0c 100644 --- a/lua/nvim-lsp-installer/servers/yamlls/init.lua +++ b/lua/nvim-lsp-installer/servers/yamlls/init.lua @@ -1,5 +1,5 @@ local server = require "nvim-lsp-installer.server" -local npm = require "nvim-lsp-installer.installers.npm" +local npm = require "nvim-lsp-installer.core.managers.npm" return function(name, root_dir) return server.Server:new { @@ -8,6 +8,7 @@ return function(name, root_dir) languages = { "yaml" }, homepage = "https://github.com/redhat-developer/yaml-language-server", installer = npm.packages { "yaml-language-server" }, + async = true, default_options = { cmd_env = npm.env(root_dir), }, diff --git a/tests/core/installer_spec.lua b/tests/core/installer_spec.lua new file mode 100644 index 00000000..7bddaee6 --- /dev/null +++ b/tests/core/installer_spec.lua @@ -0,0 +1,88 @@ +local spy = require "luassert.spy" +local match = require "luassert.match" +local fs = require "nvim-lsp-installer.core.fs" +local installer = require "nvim-lsp-installer.core.installer" +local InstallContext = require "nvim-lsp-installer.core.installer.context" +local process = require "nvim-lsp-installer.process" +local Optional = require "nvim-lsp-installer.core.optional" + +describe("installer", function() + it( + "should call installer", + async_test(function() + spy.on(fs, "mkdirp") + spy.on(fs, "rename") + local installer_fn = spy.new( + ---@param c InstallContext + function(c) + c.receipt:with_primary_source(c.receipt.npm "the-pkg") + end + ) + local destination_dir = ("%s/installer_spec"):format(os.getenv "INSTALL_ROOT_DIR") + local ctx = InstallContext.new { + name = "installer_spec_success", + destination_dir = destination_dir, + boundary_path = os.getenv "INSTALL_ROOT_DIR", + stdio_sink = process.empty_sink(), + requested_version = Optional.empty(), + } + local result = installer.execute(ctx, installer_fn) + assert.is_nil(result:err_or_nil()) + assert.spy(installer_fn).was_called(1) + assert.spy(installer_fn).was_called_with(match.ref(ctx)) + assert.spy(fs.mkdirp).was_called(1) + assert.spy(fs.mkdirp).was_called_with(destination_dir .. ".tmp") + assert.spy(fs.rename).was_called(1) + assert.spy(fs.rename).was_called_with(destination_dir .. ".tmp", destination_dir) + end) + ) + + it( + "should return failure if installer errors", + async_test(function() + spy.on(fs, "rmrf") + local installer_fn = spy.new(function() + error("something went wrong. don't try again.", 4) -- 4 because spy.new callstack + end) + local destination_dir = ("%s/installer_spec_failure"):format(os.getenv "INSTALL_ROOT_DIR") + local ctx = InstallContext.new { + name = "installer_spec_failure", + destination_dir = destination_dir, + boundary_path = os.getenv "INSTALL_ROOT_DIR", + stdio_sink = process.empty_sink(), + requested_version = Optional.empty(), + } + local result = installer.execute(ctx, installer_fn) + assert.spy(installer_fn).was_called(1) + assert.spy(installer_fn).was_called_with(match.ref(ctx)) + assert.is_true(result:is_failure()) + assert.equals("something went wrong. don't try again.", result:err_or_nil()) + assert.spy(fs.rmrf).was_called(2) + assert.spy(fs.rmrf).was_called_with(destination_dir .. ".tmp") + assert.spy(fs.rmrf).was_not_called_with(destination_dir) + end) + ) + + it( + "should write receipt", + async_test(function() + spy.on(fs, "write_file") + local destination_dir = ("%s/installer_spec_receipt"):format(os.getenv "INSTALL_ROOT_DIR") + local ctx = InstallContext.new { + name = "installer_spec_receipt", + destination_dir = destination_dir, + boundary_path = os.getenv "INSTALL_ROOT_DIR", + stdio_sink = process.empty_sink(), + requested_version = Optional.empty(), + } + installer.execute(ctx, function(c) + c.receipt:with_primary_source(c.receipt.npm "my-pkg") + end) + assert.spy(fs.write_file).was_called(1) + assert.spy(fs.write_file).was_called_with( + ("%s.tmp/nvim-lsp-installer-receipt.json"):format(destination_dir), + match.is_string() + ) + end) + ) +end) diff --git a/tests/core/result_spec.lua b/tests/core/result_spec.lua index cd10acb5..97c7da06 100644 --- a/tests/core/result_spec.lua +++ b/tests/core/result_spec.lua @@ -1,5 +1,6 @@ local Result = require "nvim-lsp-installer.core.result" local match = require "luassert.match" +local spy = require "luassert.spy" describe("result", function() it("should create success", function() @@ -117,4 +118,26 @@ describe("result", function() assert.is_true(result:is_failure()) assert.equals("Oh noes", result:err_or_nil()) end) + + it("should run on_failure if failure", function() + local on_success = spy.new() + local on_failure = spy.new() + local result = Result.failure("Oh noes"):on_failure(on_failure):on_success(on_success) + assert.is_true(result:is_failure()) + assert.equals("Oh noes", result:err_or_nil()) + assert.spy(on_failure).was_called(1) + assert.spy(on_success).was_called(0) + assert.spy(on_failure).was_called_with "Oh noes" + end) + + it("should run on_success if success", function() + local on_success = spy.new() + local on_failure = spy.new() + local result = Result.success("Oh noes"):on_failure(on_failure):on_success(on_success) + assert.is_true(result:is_success()) + assert.equals("Oh noes", result:get_or_nil()) + assert.spy(on_failure).was_called(0) + assert.spy(on_success).was_called(1) + assert.spy(on_success).was_called_with "Oh noes" + end) end) diff --git a/tests/helpers/lua/test_helpers.lua b/tests/helpers/lua/test_helpers.lua index 23353fcb..206337e1 100644 --- a/tests/helpers/lua/test_helpers.lua +++ b/tests/helpers/lua/test_helpers.lua @@ -6,7 +6,6 @@ local a = require "nvim-lsp-installer.core.async" local process = require "nvim-lsp-installer.process" local server = require "nvim-lsp-installer.server" local Optional = require "nvim-lsp-installer.core.optional" -local Result = require "nvim-lsp-installer.core.result" local receipt = require "nvim-lsp-installer.core.receipt" function async_test(suspend_fn) @@ -38,18 +37,18 @@ function ServerGenerator(opts) languages = { "dummylang" }, root_dir = server.get_server_root_path "dummy", homepage = "https://dummylang.org", - installer = function(_, callback, ctx) + async = true, + installer = function(ctx) ctx.stdio_sink.stdout "Installing dummy!\n" - callback(true) end, }, opts)) end function FailingServerGenerator(opts) return ServerGenerator(vim.tbl_deep_extend("force", { - installer = function(_, callback, ctx) + installer = function(ctx) ctx.stdio_sink.stdout "Installing failing dummy!\n" - callback(false) + error "Failed to do something." end, }, opts)) end @@ -57,16 +56,20 @@ end function InstallContextGenerator(opts) ---@type InstallContext local default_opts = { + name = "mock", fs = mock.new { append_file = mockx.just_runs, dir_exists = mockx.returns(true), file_exists = mockx.returns(true), }, spawn = mock.new {}, - cwd = function() - return "/tmp/install-dir" - end, - promote_cwd = mockx.returns(Result.success()), + cwd = mock.new { + get = mockx.returns "/tmp/install-dir", + set = mockx.just_runs, + }, + destination_dir = "/opt/install-dir", + stdio_sink = process.empty_sink(), + promote_cwd = mockx.just_runs, receipt = receipt.InstallReceiptBuilder.new(), requested_version = Optional.empty(), } diff --git a/tests/server_spec.lua b/tests/server_spec.lua index 41a40750..d1ecbb6a 100644 --- a/tests/server_spec.lua +++ b/tests/server_spec.lua @@ -2,8 +2,6 @@ local spy = require "luassert.spy" local lsp_installer = require "nvim-lsp-installer" local server = require "nvim-lsp-installer.server" local a = require "nvim-lsp-installer.core.async" -local context = require "nvim-lsp-installer.installers.context" -local fs = require "nvim-lsp-installer.fs" local function timestamp() local seconds, microseconds = vim.loop.gettimeofday() @@ -55,64 +53,27 @@ describe("server", function() end) ) - -- it( - -- "should be able to run async installer functions", - -- async_test(function() - -- local srv = ServerGenerator { - -- name = "async_installer_fixture", - -- root_dir = server.get_server_root_path "async_installer_fixture", - -- async = true, - -- installer = function() - -- a.sleep(130) - -- end, - -- } - -- local start = timestamp() - -- srv:install() - -- a.sleep(100) - -- assert.wait_for(function() - -- assert.is_true(srv:is_installed()) - -- end) - -- local stop = timestamp() - -- assert.is_true(stop - start >= 100) - -- end) - -- ) - it( - "should remove directories upon installation failure", + "should be able to run sync installer functions", async_test(function() - local srv = FailingServerGenerator { - name = "remove_dirs_failure", - root_dir = server.get_server_root_path "remove_dirs_failure", - installer = { - -- 1. sleep 500ms - function(_, callback) - vim.defer_fn(function() - callback(true) - end, 500) - end, - -- 2. promote install dir - context.promote_install_dir(), - -- 3. fail - function(_, callback) - callback(false) - end, - }, + local srv = ServerGenerator { + name = "async_installer_fixture", + root_dir = server.get_server_root_path "async_installer_fixture", + async = false, + installer = function(_, callback) + vim.defer_fn(function() + callback(true) + end, 130) + end, } + local start = timestamp() srv:install() - - -- 1. installation started - a.sleep(50) - assert.is_true(fs.dir_exists(srv:get_tmp_install_dir())) - - -- 2. install dir promoted - a.sleep(500) - assert.is_false(fs.dir_exists(srv:get_tmp_install_dir())) - - -- 3. installation failed - a.sleep(200) - - assert.is_false(srv:is_installed()) - assert.is_false(fs.dir_exists(srv:get_tmp_install_dir())) + a.sleep(100) + assert.wait_for(function() + assert.is_true(srv:is_installed()) + end) + local stop = timestamp() + assert.is_true(stop - start >= 100) end) ) end) |
