diff options
| author | William Boman <william@redwill.se> | 2021-10-18 13:59:43 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-18 13:59:43 +0200 |
| commit | cee25503cd6df85366c5106c40cc5240634e647e (patch) | |
| tree | 6e242bc0b0c5a6c3e40b165323a6c1a9c20576a1 /lua | |
| parent | Remove the pdflatex check (#174) (diff) | |
| download | mason-cee25503cd6df85366c5106c40cc5240634e647e.tar mason-cee25503cd6df85366c5106c40cc5240634e647e.tar.gz mason-cee25503cd6df85366c5106c40cc5240634e647e.tar.bz2 mason-cee25503cd6df85366c5106c40cc5240634e647e.tar.lz mason-cee25503cd6df85366c5106c40cc5240634e647e.tar.xz mason-cee25503cd6df85366c5106c40cc5240634e647e.tar.zst mason-cee25503cd6df85366c5106c40cc5240634e647e.zip | |
speed up :LspInstall, :LspUninstall, :LspUninstallAll commands (#175)
- `:LspUninstallAll` now just nukes the entire install directory immediately,
instead of uninstalling each server one by one. There's also a confirmation
prompt now.
- `:LspInstall` & `:LspUninstall` now sources its autocompletion directly from
a Lua table, instead of sourcing the server names from each server module (thus
avoiding unnecessary `require` calls).
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/nvim-lsp-installer.lua | 37 | ||||
| -rw-r--r-- | lua/nvim-lsp-installer/servers/init.lua | 33 | ||||
| -rw-r--r-- | lua/nvim-lsp-installer/settings.lua | 8 | ||||
| -rw-r--r-- | lua/nvim-lsp-installer/ui/status-win/init.lua | 14 |
4 files changed, 65 insertions, 27 deletions
diff --git a/lua/nvim-lsp-installer.lua b/lua/nvim-lsp-installer.lua index b05ac31c..5c41864d 100644 --- a/lua/nvim-lsp-installer.lua +++ b/lua/nvim-lsp-installer.lua @@ -1,9 +1,11 @@ +local fs = require "nvim-lsp-installer.fs" local notify = require "nvim-lsp-installer.notify" local dispatcher = require "nvim-lsp-installer.dispatcher" local process = require "nvim-lsp-installer.process" local status_win = require "nvim-lsp-installer.ui.status-win" local servers = require "nvim-lsp-installer.servers" local settings = require "nvim-lsp-installer.settings" +local log = require "nvim-lsp-installer.log" local M = {} @@ -33,18 +35,31 @@ function M.uninstall(server_name) end function M.uninstall_all() - local installed_servers = servers.get_installed_servers() - status_win().open() - if #installed_servers > 0 then - local function uninstall(idx) - status_win().uninstall_server(installed_servers[idx]) - if installed_servers[idx + 1] then - vim.schedule(function() - uninstall(idx + 1) - end) - end + local choice = vim.fn.confirm( + ("This will uninstall all servers currently installed at %q. Continue?"):format( + vim.fn.fnamemodify(settings.current.install_root_dir, ":~") + ), + "&Yes\n&No", + 2 + ) + if settings.current.install_root_dir ~= settings._DEFAULT_SETTINGS.install_root_dir then + choice = vim.fn.confirm( + ( + "WARNING: You are using a non-default install_root_dir (%q). This command will delete the entire directory. Continue?" + ):format(vim.fn.fnamemodify(settings.current.install_root_dir, ":~")), + "&Yes\n&No", + 2 + ) + end + if choice == 1 then + log.info "Uninstalling all servers." + if fs.dir_exists(settings.current.install_root_dir) then + fs.rmrf(settings.current.install_root_dir) end - uninstall(1) + status_win().mark_all_servers_uninstalled() + status_win().open() + else + print "Uninstalling all servers was aborted." end end diff --git a/lua/nvim-lsp-installer/servers/init.lua b/lua/nvim-lsp-installer/servers/init.lua index 64359520..94a67b3c 100644 --- a/lua/nvim-lsp-installer/servers/init.lua +++ b/lua/nvim-lsp-installer/servers/init.lua @@ -176,10 +176,6 @@ function M.get_server(server_name) ):format(server_name, "https://github.com/williamboman/nvim-lsp-installer", server_factory) end -local function get_available_server_names() - return vim.tbl_keys(vim.tbl_extend("force", CORE_SERVERS, INITIALIZED_SERVERS)) -end - local function resolve_servers(server_names) return Data.list_map(function(server_name) local ok, server = M.get_server(server_name) @@ -190,20 +186,35 @@ local function resolve_servers(server_names) end, server_names) end +function M.get_available_server_names() + return vim.tbl_keys(vim.tbl_extend("force", CORE_SERVERS, INITIALIZED_SERVERS)) +end + +function M.get_installed_server_names() + return vim.tbl_filter(function(server_name) + return M.is_server_installed(server_name) + end, M.get_available_server_names()) +end + +function M.get_uninstalled_server_names() + return vim.tbl_filter(function(server_name) + return not M.is_server_installed(server_name) + end, M.get_available_server_names()) +end + +-- Expensive to call the first time - loads all server modules. function M.get_available_servers() - return resolve_servers(get_available_server_names()) + return resolve_servers(M.get_available_server_names()) end +-- Somewhat expensive to call the first time (depends on how many servers are currently installed). function M.get_installed_servers() - return resolve_servers(vim.tbl_filter(function(server_name) - return M.is_server_installed(server_name) - end, get_available_server_names())) + return resolve_servers(M.get_installed_server_names()) end +-- Expensive to call the first time (depends on how many servers are currently not installed). function M.get_uninstalled_servers() - return resolve_servers(vim.tbl_filter(function(server_name) - return not M.is_server_installed(server_name) - end, get_available_server_names())) + return resolve_servers(M.get_uninstalled_server_names()) end function M.register(server) diff --git a/lua/nvim-lsp-installer/settings.lua b/lua/nvim-lsp-installer/settings.lua index 1d999573..f10b9e28 100644 --- a/lua/nvim-lsp-installer/settings.lua +++ b/lua/nvim-lsp-installer/settings.lua @@ -1,6 +1,8 @@ local path = require "nvim-lsp-installer.path" -local DEFAULT_SETTINGS = { +local M = {} + +M._DEFAULT_SETTINGS = { ui = { icons = { -- The list icon to use for installed servers. @@ -48,9 +50,7 @@ local DEFAULT_SETTINGS = { max_concurrent_installers = 4, } -local M = {} - -M.current = DEFAULT_SETTINGS +M.current = M._DEFAULT_SETTINGS function M.set(opts) M.current = vim.tbl_deep_extend("force", M.current, opts) diff --git a/lua/nvim-lsp-installer/ui/status-win/init.lua b/lua/nvim-lsp-installer/ui/status-win/init.lua index c6f4540f..e8931bce 100644 --- a/lua/nvim-lsp-installer/ui/status-win/init.lua +++ b/lua/nvim-lsp-installer/ui/status-win/init.lua @@ -270,7 +270,7 @@ local function UninstalledServers(servers, expanded_server) Data.list_not_nil( { settings.current.ui.icons.server_uninstalled, "LspInstallerMuted" }, { " " .. server.name, "LspInstallerMuted" }, - Data.when(server.uninstaller.has_run, { " (just uninstalled)", "Comment" }) + Data.when(server.uninstaller.has_run, { " (uninstalled)", "Comment" }) ), }, Ui.Keybind(settings.current.ui.keymaps.toggle_server_expand, "EXPAND_SERVER", { server.name }), @@ -558,6 +558,17 @@ local function init(all_servers) end) end + local function mark_all_servers_uninstalled() + mutate_state(function(state) + for _, server_name in ipairs(lsp_servers.get_available_server_names()) do + if state.servers[server_name].is_installed then + state.servers[server_name].is_installed = false + state.servers[server_name].uninstaller.has_run = true + end + end + end) + end + local start_help_command_animation do local help_command = ":help " @@ -656,6 +667,7 @@ local function init(all_servers) open = open, install_server = install_server, uninstall_server = uninstall_server, + mark_all_servers_uninstalled = mark_all_servers_uninstalled, } end |
