aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua')
-rw-r--r--lua/nvim-lsp-installer/data.lua12
-rw-r--r--lua/nvim-lsp-installer/middleware.lua19
-rw-r--r--lua/nvim-lsp-installer/settings.lua5
3 files changed, 30 insertions, 6 deletions
diff --git a/lua/nvim-lsp-installer/data.lua b/lua/nvim-lsp-installer/data.lua
index 264fda80..268d3aec 100644
--- a/lua/nvim-lsp-installer/data.lua
+++ b/lua/nvim-lsp-installer/data.lua
@@ -1,3 +1,5 @@
+-- TODO: rename this to functional.lua, long overdue
+
local Data = {}
---@generic T : string
@@ -122,14 +124,16 @@ function Data.list_any(list, predicate)
return false
end
+function Data.identity(a)
+ return a
+end
+
---@generic T : fun(...)
---@param fn T
----@param cache_key_generator fun(...): string | nil
+---@param cache_key_generator (fun(...): string | nil)|nil
---@return T
function Data.memoize(fn, cache_key_generator)
- cache_key_generator = cache_key_generator or function(a)
- return a
- end
+ cache_key_generator = cache_key_generator or Data.identity
local cache = {}
return function(...)
local key = cache_key_generator(...)
diff --git a/lua/nvim-lsp-installer/middleware.lua b/lua/nvim-lsp-installer/middleware.lua
index 7def4276..b09b51ac 100644
--- a/lua/nvim-lsp-installer/middleware.lua
+++ b/lua/nvim-lsp-installer/middleware.lua
@@ -1,6 +1,9 @@
local util = require "lspconfig.util"
local servers = require "nvim-lsp-installer.servers"
local settings = require "nvim-lsp-installer.settings"
+local Data = require "nvim-lsp-installer.data"
+
+local memoize, set_of = Data.memoize, Data.set_of
local M = {}
@@ -21,14 +24,26 @@ local function merge_in_place(t1, t2)
return t1
end
+local memoized_set = memoize(set_of)
+
+---@param server_name string
+local function should_auto_install(server_name)
+ if settings.current.automatic_installation == true then
+ return true
+ end
+ if type(settings.current.automatic_installation) == "table" then
+ return not memoized_set(settings.current.automatic_installation.exclude)[server_name]
+ end
+ return false
+end
+
function M.register_lspconfig_hook()
util.on_setup = util.add_hook_before(util.on_setup, function(config)
local ok, server = servers.get_server(config.name)
if ok then
if server:is_installed() then
merge_in_place(config, server._default_options)
- end
- if settings.current.automatic_installation and not server:is_installed() then
+ elseif should_auto_install(server.name) then
server:install()
end
end
diff --git a/lua/nvim-lsp-installer/settings.lua b/lua/nvim-lsp-installer/settings.lua
index 44c739db..5cfdae4f 100644
--- a/lua/nvim-lsp-installer/settings.lua
+++ b/lua/nvim-lsp-installer/settings.lua
@@ -7,6 +7,11 @@ local DEFAULT_SETTINGS = {
-- A list of servers to automatically install. Example: { "rust_analyzer", "sumneko_lua" }
ensure_installed = {},
-- Whether servers that are set up (via lspconfig) should be automatically installed if they're not already installed.
+ -- Can either be:
+ -- - false: Servers are not automatically installed.
+ -- - true: All servers set up via lspconfig are automatically installed.
+ -- - { exclude: string[] }: All servers set up via lspconfig, except the ones provided in the list, are automatically installed.
+ -- Example: automatic_installation = { exclude = { "rust_analyzer", "solargraph" } }
automatic_installation = false,
ui = {
icons = {