aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lua/nvim-lsp-installer.lua37
-rw-r--r--lua/nvim-lsp-installer/servers/init.lua33
-rw-r--r--lua/nvim-lsp-installer/settings.lua8
-rw-r--r--lua/nvim-lsp-installer/ui/status-win/init.lua14
-rw-r--r--plugin/nvim-lsp-installer.vim8
5 files changed, 67 insertions, 33 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
diff --git a/plugin/nvim-lsp-installer.vim b/plugin/nvim-lsp-installer.vim
index 2cd3485b..3050d865 100644
--- a/plugin/nvim-lsp-installer.vim
+++ b/plugin/nvim-lsp-installer.vim
@@ -4,16 +4,12 @@ let g:loaded_nvim_lsp_installer = v:true
let s:save_cpo = &cpo
set cpo&vim
-function! s:MapServerName(servers) abort
- return map(a:servers, {_, val -> val.name})
-endfunction
-
function! s:LspInstallCompletion(...) abort
- return join(sort(s:MapServerName(luaeval("require'nvim-lsp-installer.servers'.get_available_servers()"))), "\n")
+ return join(luaeval("require'nvim-lsp-installer.servers'.get_available_server_names()"), "\n")
endfunction
function! s:LspUninstallCompletion(...) abort
- return join(sort(s:MapServerName(luaeval("require'nvim-lsp-installer.servers'.get_installed_servers()"))), "\n")
+ return join(luaeval("require'nvim-lsp-installer.servers'.get_installed_server_names()"), "\n")
endfunction
function! s:LspInstall(server_names) abort