aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2021-04-08 13:59:31 +0200
committerWilliam Boman <william@redwill.se>2021-04-08 14:01:52 +0200
commit02fc4cf88874e72353a4d330f31365aa239ffc6b (patch)
tree56e1a992c34cee1fa32285956fd3818cc9e5d28a /lua
parentset new rulesCustomizations settings to empty list (diff)
downloadmason-02fc4cf88874e72353a4d330f31365aa239ffc6b.tar
mason-02fc4cf88874e72353a4d330f31365aa239ffc6b.tar.gz
mason-02fc4cf88874e72353a4d330f31365aa239ffc6b.tar.bz2
mason-02fc4cf88874e72353a4d330f31365aa239ffc6b.tar.lz
mason-02fc4cf88874e72353a4d330f31365aa239ffc6b.tar.xz
mason-02fc4cf88874e72353a4d330f31365aa239ffc6b.tar.zst
mason-02fc4cf88874e72353a4d330f31365aa239ffc6b.zip
rename pre_install to pre_install_check, also add some luadocs
Diffstat (limited to 'lua')
-rw-r--r--lua/nvim-lsp-installer/server.lua24
-rw-r--r--lua/nvim-lsp-installer/servers/solargraph.lua2
-rw-r--r--lua/nvim-lsp-installer/servers/sumneko_lua.lua2
3 files changed, 20 insertions, 8 deletions
diff --git a/lua/nvim-lsp-installer/server.lua b/lua/nvim-lsp-installer/server.lua
index 5c71922b..69a5b1e6 100644
--- a/lua/nvim-lsp-installer/server.lua
+++ b/lua/nvim-lsp-installer/server.lua
@@ -93,13 +93,25 @@ M.Server = {}
M.Server.__index = M.Server
---@class Server
+--@param opts table
+-- @field name (string) The name of the LSP server. This MUST correspond with lspconfig's naming.
+--
+-- @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 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.
+-- 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,
_root_dir = opts.root_dir,
_default_options = opts.default_options,
- _pre_install = opts.pre_install,
+ _pre_install_check = opts.pre_install_check,
}, M.Server)
end
@@ -123,13 +135,13 @@ function M.Server:create_root_dir()
end
function M.Server:install()
- if self._pre_install then
- self._pre_install()
+ if self._pre_install_check then
+ self._pre_install_check()
end
- -- We run uninstall after pre_install because we don't want to
+ -- We run uninstall after pre_install_check because we don't want to
-- unnecessarily uninstall a server should it no longer pass the
- -- pre_install check.
+ -- pre_install_check.
self:uninstall()
self:create_root_dir()
@@ -144,7 +156,7 @@ function M.Server:install()
on_exit = function (_, exit_code)
if exit_code ~= 0 then
vim.api.nvim_err_writeln("Server installation failed for " .. self.name .. ". Exit code: " .. exit_code)
- self:uninstall()
+ pcall(self.uninstall, self)
else
print("Successfully installed " .. self.name)
end
diff --git a/lua/nvim-lsp-installer/servers/solargraph.lua b/lua/nvim-lsp-installer/servers/solargraph.lua
index c9f99e7c..4e3e1808 100644
--- a/lua/nvim-lsp-installer/servers/solargraph.lua
+++ b/lua/nvim-lsp-installer/servers/solargraph.lua
@@ -23,7 +23,7 @@ return server.Server:new {
name = "solargraph",
root_dir = root_dir,
install_cmd = install_cmd,
- pre_install = function ()
+ pre_install_check = function ()
if vim.fn.executable('bundle') ~= 1 then
error("bundle not installed")
end
diff --git a/lua/nvim-lsp-installer/servers/sumneko_lua.lua b/lua/nvim-lsp-installer/servers/sumneko_lua.lua
index 81ac2bcb..ab8b3462 100644
--- a/lua/nvim-lsp-installer/servers/sumneko_lua.lua
+++ b/lua/nvim-lsp-installer/servers/sumneko_lua.lua
@@ -30,7 +30,7 @@ return server.Server:new {
name = "sumneko_lua",
root_dir = root_dir,
install_cmd = install_cmd,
- pre_install = function()
+ 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)")
end