diff options
Diffstat (limited to 'lua')
21 files changed, 42 insertions, 29 deletions
diff --git a/lua/nvim-lsp-installer/installers/shell.lua b/lua/nvim-lsp-installer/installers/shell.lua index e169d184..37d99af9 100644 --- a/lua/nvim-lsp-installer/installers/shell.lua +++ b/lua/nvim-lsp-installer/installers/shell.lua @@ -1,7 +1,7 @@ local M = {} function M.raw(raw_script) - return function (server, on_exit) + return function (server, callback) local shell = vim.o.shell vim.o.shell = "/bin/bash" vim.cmd [[new]] @@ -9,7 +9,13 @@ function M.raw(raw_script) "set -e;\n" .. raw_script, { cwd = server._root_dir, - on_exit = on_exit + on_exit = function (_, exit_code) + if exit_code ~= 0 then + callback(false, ("Exit code was non-successful: %d"):format(exit_code)) + else + callback(true, nil) + end + end } ) vim.o.shell = shell diff --git a/lua/nvim-lsp-installer/installers/zx.lua b/lua/nvim-lsp-installer/installers/zx.lua index 20ee9bb1..92027ef8 100644 --- a/lua/nvim-lsp-installer/installers/zx.lua +++ b/lua/nvim-lsp-installer/installers/zx.lua @@ -44,7 +44,7 @@ end function M.file(relpath) local script_path = path.realpath(relpath, 3) - return function (server, on_exit) + return function (server, callback) M.install_zx(function () vim.cmd [[new]] vim.fn.termopen(("set -e; %q %q"):format( @@ -52,7 +52,13 @@ function M.file(relpath) script_path ), { cwd = server._root_dir, - on_exit = on_exit + on_exit = function (_, exit_code) + if exit_code ~= 0 then + callback(false, ("Exit code was non-successful: %d"):format(exit_code)) + else + callback(true, nil) + end + end }) vim.cmd [[startinsert]] -- so that the buffer tails the term log nicely end, false) diff --git a/lua/nvim-lsp-installer/server.lua b/lua/nvim-lsp-installer/server.lua index 847e54e1..60e96851 100644 --- a/lua/nvim-lsp-installer/server.lua +++ b/lua/nvim-lsp-installer/server.lua @@ -103,17 +103,18 @@ M.Server.__index = M.Server -- -- @field root_dir (string) The root directory of the installation. Most servers will make use of server.get_server_root_path() to produce its root_dir path. -- --- @field install_cmd (string) The shell script that installs the LSP. Make sure to exit with an error code (e.g. exit 1) on failures. --- The shell script is executed with "set -e" (exits the script on first non-successful command) by default. +-- @field installer (function) The function that installs the LSP (see the .installers module). The function signature should be `function (server, callback)`, where +-- `server` is the Server instance being installed, and `callback` is a function that must be called upon completion. The `callback` function +-- has the signature `function (success, result)`, where `success` is a boolean and `result` is of any type (similar to `pcall`). -- -- @field default_options (table) The default options to be passed to lspconfig's .setup() function. Each server should provide at least the `cmd` field. -- --- @field pre_install_check (function) An optional function to be executed before the install_cmd. This allows ensuring that any prerequisites are fulfilled. +-- @field pre_install_check (function) An optional function to be executed before the installer. This allows ensuring that any prerequisites are fulfilled. -- This could for example be verifying that required build tools are installed. function M.Server:new(opts) return setmetatable({ name = opts.name, - _install_cmd = opts.install_cmd, + _installer = opts.installer, _root_dir = opts.root_dir, _default_options = opts.default_options, _pre_install_check = opts.pre_install_check, @@ -149,9 +150,9 @@ function M.Server:install() self:create_root_dir() - self._install_cmd(self, function (_, exit_code) - if exit_code ~= 0 then - vim.api.nvim_err_writeln(("Server installation failed for %s. Exit code: %d"):format(self.name, exit_code)) + self._installer(self, function (success, result) + if not success then + vim.api.nvim_err_writeln(("Server installation failed for %s. %s"):format(self.name, result)) pcall(self.uninstall, self) else print(("Successfully installed %s"):format(self.name)) diff --git a/lua/nvim-lsp-installer/servers/bashls/init.lua b/lua/nvim-lsp-installer/servers/bashls/init.lua index 323485e8..4c556c37 100644 --- a/lua/nvim-lsp-installer/servers/bashls/init.lua +++ b/lua/nvim-lsp-installer/servers/bashls/init.lua @@ -7,7 +7,7 @@ local root_dir = server.get_server_root_path("bash") return server.Server:new { name = "bashls", root_dir = root_dir, - install_cmd = npm.packages { "bash-language-server@latest" }, + installer = npm.packages { "bash-language-server@latest" }, default_options = { cmd = { path.concat { root_dir, "node_modules", ".bin", "bash-language-server" }, "start" }, }, diff --git a/lua/nvim-lsp-installer/servers/clangd/init.lua b/lua/nvim-lsp-installer/servers/clangd/init.lua index b3a12ad2..4183699a 100644 --- a/lua/nvim-lsp-installer/servers/clangd/init.lua +++ b/lua/nvim-lsp-installer/servers/clangd/init.lua @@ -7,7 +7,7 @@ local root_dir = server.get_server_root_path("c-family") return server.Server:new { name = "clangd", root_dir = root_dir, - install_cmd = zx.file("./install.mjs"), + installer = zx.file("./install.mjs"), default_options = { cmd = { path.concat { root_dir, "clangd", "bin", "clangd" } }, } diff --git a/lua/nvim-lsp-installer/servers/cssls/init.lua b/lua/nvim-lsp-installer/servers/cssls/init.lua index 86b9e1f6..1d0e6ea5 100644 --- a/lua/nvim-lsp-installer/servers/cssls/init.lua +++ b/lua/nvim-lsp-installer/servers/cssls/init.lua @@ -7,7 +7,7 @@ local root_dir = server.get_server_root_path("css") return server.Server:new { name = "cssls", root_dir = root_dir, - install_cmd = npm.packages { "vscode-css-languageserver-bin" }, + installer = npm.packages { "vscode-css-languageserver-bin" }, default_options = { cmd = { path.concat { root_dir, "node_modules", ".bin", "css-languageserver" }, "--stdio" }, }, diff --git a/lua/nvim-lsp-installer/servers/denols/init.lua b/lua/nvim-lsp-installer/servers/denols/init.lua index e7415201..6df28510 100644 --- a/lua/nvim-lsp-installer/servers/denols/init.lua +++ b/lua/nvim-lsp-installer/servers/denols/init.lua @@ -12,7 +12,7 @@ curl -fsSL https://deno.land/x/install/install.sh | sh return server.Server:new { name = "denols", root_dir = root_dir, - install_cmd = shell.raw(install_cmd), + installer = shell.raw(install_cmd), default_options = { cmd = { path.concat { root_dir, "bin", "deno" }, "lsp" }, }, diff --git a/lua/nvim-lsp-installer/servers/dockerls/init.lua b/lua/nvim-lsp-installer/servers/dockerls/init.lua index 2a4b3e81..ef8defa2 100644 --- a/lua/nvim-lsp-installer/servers/dockerls/init.lua +++ b/lua/nvim-lsp-installer/servers/dockerls/init.lua @@ -7,7 +7,7 @@ local root_dir = server.get_server_root_path("dockerfile") return server.Server:new { name = "dockerls", root_dir = root_dir, - install_cmd = npm.packages { "dockerfile-language-server-nodejs@latest" }, + installer = npm.packages { "dockerfile-language-server-nodejs@latest" }, default_options = { cmd = { path.concat { root_dir, "node_modules", ".bin", "docker-langserver" }, "--stdio" }, }, diff --git a/lua/nvim-lsp-installer/servers/eslintls/init.lua b/lua/nvim-lsp-installer/servers/eslintls/init.lua index 88f729f9..e2b38729 100644 --- a/lua/nvim-lsp-installer/servers/eslintls/init.lua +++ b/lua/nvim-lsp-installer/servers/eslintls/init.lua @@ -64,7 +64,7 @@ npm install; return server.Server:new { name = "eslintls", root_dir = root_dir, - install_cmd = shell.raw(install_cmd), + installer = shell.raw(install_cmd), default_options = { cmd = { "node", path.concat { root_dir, "server", "out", "eslintServer.js" }, "--stdio" }, handlers = { diff --git a/lua/nvim-lsp-installer/servers/gopls/init.lua b/lua/nvim-lsp-installer/servers/gopls/init.lua index 59113191..fe0ebea9 100644 --- a/lua/nvim-lsp-installer/servers/gopls/init.lua +++ b/lua/nvim-lsp-installer/servers/gopls/init.lua @@ -17,7 +17,7 @@ return server.Server:new { error("Please install the Go CLI before installing gopls (https://golang.org/doc/install).") end end, - install_cmd = shell.raw(install_cmd), + installer = shell.raw(install_cmd), default_options = { cmd = { path.concat { root_dir, "gopls" } }, } diff --git a/lua/nvim-lsp-installer/servers/graphql/init.lua b/lua/nvim-lsp-installer/servers/graphql/init.lua index 279b6e25..b2d15b01 100644 --- a/lua/nvim-lsp-installer/servers/graphql/init.lua +++ b/lua/nvim-lsp-installer/servers/graphql/init.lua @@ -9,7 +9,7 @@ local root_dir = server.get_server_root_path("graphql") return server.Server:new { name = "graphql", root_dir = root_dir, - install_cmd = npm.packages { "graphql-language-service-cli@latest", "graphql" }, + installer = npm.packages { "graphql-language-service-cli@latest", "graphql" }, default_options = { cmd = { path.concat { root_dir, "node_modules", ".bin", "graphql-lsp" }, "server", "-m", "stream" }, filetypes = { "typescriptreact", "javascriptreact", "graphql" }, diff --git a/lua/nvim-lsp-installer/servers/html/init.lua b/lua/nvim-lsp-installer/servers/html/init.lua index 8038ea5e..e6c4a814 100644 --- a/lua/nvim-lsp-installer/servers/html/init.lua +++ b/lua/nvim-lsp-installer/servers/html/init.lua @@ -7,7 +7,7 @@ local root_dir = server.get_server_root_path("html") return server.Server:new { name = "html", root_dir = root_dir, - install_cmd = npm.packages { "vscode-html-languageserver-bin" }, + installer = npm.packages { "vscode-html-languageserver-bin" }, default_options = { cmd = { path.concat { root_dir, "node_modules", ".bin", "html-languageserver" }, "--stdio" }, }, diff --git a/lua/nvim-lsp-installer/servers/jsonls/init.lua b/lua/nvim-lsp-installer/servers/jsonls/init.lua index b99a8103..f1a2a643 100644 --- a/lua/nvim-lsp-installer/servers/jsonls/init.lua +++ b/lua/nvim-lsp-installer/servers/jsonls/init.lua @@ -7,7 +7,7 @@ local root_dir = server.get_server_root_path("json") return server.Server:new { name = "jsonls", root_dir = root_dir, - install_cmd = npm.packages { "vscode-json-languageserver" }, + installer = npm.packages { "vscode-json-languageserver" }, default_options = { cmd = { path.concat { root_dir, "node_modules", ".bin", "vscode-json-languageserver" }, "--stdio" }, }, diff --git a/lua/nvim-lsp-installer/servers/pyright/init.lua b/lua/nvim-lsp-installer/servers/pyright/init.lua index a01b9882..c03660e8 100644 --- a/lua/nvim-lsp-installer/servers/pyright/init.lua +++ b/lua/nvim-lsp-installer/servers/pyright/init.lua @@ -7,7 +7,7 @@ local root_dir = server.get_server_root_path("python") return server.Server:new { name = "pyright", root_dir = root_dir, - install_cmd = npm.packages { "pyright" }, + installer = npm.packages { "pyright" }, default_options = { cmd = { path.concat { root_dir, "node_modules", ".bin", "pyright-langserver" }, "--stdio" }, on_attach = server.common_on_attach, diff --git a/lua/nvim-lsp-installer/servers/rust_analyzer/init.lua b/lua/nvim-lsp-installer/servers/rust_analyzer/init.lua index 99b0c54c..f959cd69 100644 --- a/lua/nvim-lsp-installer/servers/rust_analyzer/init.lua +++ b/lua/nvim-lsp-installer/servers/rust_analyzer/init.lua @@ -7,7 +7,7 @@ local root_dir = server.get_server_root_path("rust") return server.Server:new { name = "rust_analyzer", root_dir = root_dir, - install_cmd = zx.file("./install.mjs"), + installer = zx.file("./install.mjs"), default_options = { cmd = { path.concat { root_dir, "rust-analyzer" } }, }, diff --git a/lua/nvim-lsp-installer/servers/solargraph/init.lua b/lua/nvim-lsp-installer/servers/solargraph/init.lua index b808d917..630cc15c 100644 --- a/lua/nvim-lsp-installer/servers/solargraph/init.lua +++ b/lua/nvim-lsp-installer/servers/solargraph/init.lua @@ -7,7 +7,7 @@ local root_dir = server.get_server_root_path("ruby") return server.Server:new { name = "solargraph", root_dir = root_dir, - install_cmd = zx.file("./install.mjs"), + installer = zx.file("./install.mjs"), pre_install_check = function () if vim.fn.executable("bundle") ~= 1 then error("bundle not installed") diff --git a/lua/nvim-lsp-installer/servers/sumneko_lua/init.lua b/lua/nvim-lsp-installer/servers/sumneko_lua/init.lua index aeb03e82..01828749 100644 --- a/lua/nvim-lsp-installer/servers/sumneko_lua/init.lua +++ b/lua/nvim-lsp-installer/servers/sumneko_lua/init.lua @@ -13,7 +13,7 @@ local bin_dir = uname_alias[uname] or uname return server.Server:new { name = "sumneko_lua", root_dir = root_dir, - install_cmd = zx.file("./install.mjs"), + installer = zx.file("./install.mjs"), pre_install_check = function() if vim.fn.executable("ninja") ~= 1 then error("ninja not installed (see https://github.com/ninja-build/ninja/wiki/Pre-built-Ninja-packages)") diff --git a/lua/nvim-lsp-installer/servers/tsserver/init.lua b/lua/nvim-lsp-installer/servers/tsserver/init.lua index cc714506..e0ca22bd 100644 --- a/lua/nvim-lsp-installer/servers/tsserver/init.lua +++ b/lua/nvim-lsp-installer/servers/tsserver/init.lua @@ -7,7 +7,7 @@ local root_dir = server.get_server_root_path("tsserver") return server.Server:new { name = "tsserver", root_dir = root_dir, - install_cmd = npm.packages { "typescript-language-server" }, + installer = npm.packages { "typescript-language-server" }, default_options = { cmd = { path.concat { root_dir, "node_modules", ".bin", "typescript-language-server" }, "--stdio" }, }, diff --git a/lua/nvim-lsp-installer/servers/vimls/init.lua b/lua/nvim-lsp-installer/servers/vimls/init.lua index afc7e73b..3c8fc7dd 100644 --- a/lua/nvim-lsp-installer/servers/vimls/init.lua +++ b/lua/nvim-lsp-installer/servers/vimls/init.lua @@ -7,7 +7,7 @@ local root_dir = server.get_server_root_path("vim") return server.Server:new { name = "vimls", root_dir = root_dir, - install_cmd = npm.packages { "vim-language-server@latest" }, + installer = npm.packages { "vim-language-server@latest" }, default_options = { cmd = { path.concat { root_dir, "node_modules", ".bin", "vim-language-server" }, "--stdio" }, } diff --git a/lua/nvim-lsp-installer/servers/vuels/init.lua b/lua/nvim-lsp-installer/servers/vuels/init.lua index c5e3977e..a4403da6 100644 --- a/lua/nvim-lsp-installer/servers/vuels/init.lua +++ b/lua/nvim-lsp-installer/servers/vuels/init.lua @@ -7,7 +7,7 @@ local root_dir = server.get_server_root_path("vuels") return server.Server:new { name = "vuels", root_dir = root_dir, - install_cmd = npm.packages { "vls" }, + installer = npm.packages { "vls" }, default_options = { cmd = { path.concat { root_dir, "node_modules", ".bin", "vls" }, "--stdio"}, }, diff --git a/lua/nvim-lsp-installer/servers/yamlls/init.lua b/lua/nvim-lsp-installer/servers/yamlls/init.lua index a93069a0..09ca7ba7 100644 --- a/lua/nvim-lsp-installer/servers/yamlls/init.lua +++ b/lua/nvim-lsp-installer/servers/yamlls/init.lua @@ -7,7 +7,7 @@ local root_dir = server.get_server_root_path("yaml") return server.Server:new { name = "yamlls", root_dir = root_dir, - install_cmd = npm.packages { "yaml-language-server" }, + installer = npm.packages { "yaml-language-server" }, default_options = { cmd = { path.concat { root_dir, "node_modules", ".bin", "yaml-language-server" }, "--stdio" }, } |
