diff options
| author | William Boman <william@redwill.se> | 2021-09-10 13:38:39 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-09-10 13:38:39 +0200 |
| commit | d2ec0c0070c01ba0e3e8926031cfe848a016df44 (patch) | |
| tree | bf57f20725e11125ed51caac547c483d4e642831 /lua/nvim-lsp-installer/server.lua | |
| parent | CUSTOM_SERVERS.md: update docs (diff) | |
| download | mason-d2ec0c0070c01ba0e3e8926031cfe848a016df44.tar mason-d2ec0c0070c01ba0e3e8926031cfe848a016df44.tar.gz mason-d2ec0c0070c01ba0e3e8926031cfe848a016df44.tar.bz2 mason-d2ec0c0070c01ba0e3e8926031cfe848a016df44.tar.lz mason-d2ec0c0070c01ba0e3e8926031cfe848a016df44.tar.xz mason-d2ec0c0070c01ba0e3e8926031cfe848a016df44.tar.zst mason-d2ec0c0070c01ba0e3e8926031cfe848a016df44.zip | |
rewrite some installers for broader cross-platform support (#85)
- Remove all usage of zx in favour of native Lua (via libuv)
- Introduce new set of `std` installers
The following servers will have to be reinstalled due to this change:
1. clangd
2. solargraph
3. sumneko_lua
4. tailwindcss
Diffstat (limited to 'lua/nvim-lsp-installer/server.lua')
| -rw-r--r-- | lua/nvim-lsp-installer/server.lua | 43 |
1 files changed, 15 insertions, 28 deletions
diff --git a/lua/nvim-lsp-installer/server.lua b/lua/nvim-lsp-installer/server.lua index ccad4c77..2e1a477c 100644 --- a/lua/nvim-lsp-installer/server.lua +++ b/lua/nvim-lsp-installer/server.lua @@ -1,5 +1,6 @@ local dispatcher = require "nvim-lsp-installer.dispatcher" local fs = require "nvim-lsp-installer.fs" +local installers = require "nvim-lsp-installer.installers" local path = require "nvim-lsp-installer.path" local status_win = require "nvim-lsp-installer.ui.status-win" @@ -24,8 +25,6 @@ M.Server.__index = M.Server -- -- @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 installer. This allows ensuring that any prerequisites are fulfilled. --- This could for example be verifying that required build tools are installed. -- -- @field post_setup (function) An optional function to be executed after the setup function has been successfully called. -- Use this to defer setting up server specific things until they're actually @@ -39,9 +38,8 @@ function M.Server:new(opts) name = opts.name, root_dir = opts.root_dir, _root_dir = opts.root_dir, -- @deprecated Use the `root_dir` property instead. - _installer = opts.installer, + _installer = type(opts.installer) == "function" and opts.installer or installers.pipe(opts.installer), _default_options = opts.default_options, - _pre_install_check = opts.pre_install_check, _post_setup = opts.post_setup, _pre_setup = opts.pre_setup, }, M.Server) @@ -65,11 +63,11 @@ function M.Server:get_default_options() end function M.Server:is_installed() - return fs.dir_exists(self._root_dir) + return fs.dir_exists(self.root_dir) end function M.Server:create_root_dir() - fs.mkdirp(self._root_dir) + fs.mkdirp(self.root_dir) end function M.Server:install() @@ -77,15 +75,13 @@ function M.Server:install() end function M.Server:install_attached(opts, callback) - local ok, err = pcall(self.pre_install, self) - if not ok then - opts.stdio_sink.stderr(tostring(err)) - callback(false) - return - end - self._installer(self, function(success) + self:uninstall() + self:create_root_dir() + local install_ok, install_err = pcall(self._installer, self, function(success) if not success then - pcall(self.uninstall, self) + vim.schedule(function() + pcall(self.uninstall, self) + end) else vim.schedule(function() dispatcher.dispatch_server_ready(self) @@ -93,24 +89,15 @@ function M.Server:install_attached(opts, callback) end callback(success) end, opts) -end - -function M.Server:pre_install() - if self._pre_install_check then - self._pre_install_check() + if not install_ok then + opts.stdio_sink.stderr(tostring(install_err)) + callback(false) end - - -- 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. - self:uninstall() - - self:create_root_dir() end function M.Server:uninstall() - if fs.dir_exists(self._root_dir) then - fs.rmrf(self._root_dir) + if fs.dir_exists(self.root_dir) then + fs.rmrf(self.root_dir) end end |
