aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md3
-rw-r--r--doc/nvim-lsp-installer.txt2
-rw-r--r--lua/nvim-lsp-installer.lua19
-rw-r--r--lua/nvim-lsp-installer/settings.lua2
4 files changed, 26 insertions, 0 deletions
diff --git a/README.md b/README.md
index acde37e9..d22b6c12 100644
--- a/README.md
+++ b/README.md
@@ -114,6 +114,7 @@ Example:
```lua
require("nvim-lsp-installer").setup({
+ ensure_installed = { "sumneko_lua", "rust_analyzer" },
ui = {
icons = {
server_installed = "✓",
@@ -266,6 +267,8 @@ Illustrations in the logo are derived from [@Kaligule](https://schauderbasis.de/
```lua
local DEFAULT_SETTINGS = {
+ -- A list of servers to automatically install. Example: { "rust_analyzer", "sumneko_lua" }
+ ensure_installed = {},
ui = {
icons = {
-- The list icon to use for installed servers.
diff --git a/doc/nvim-lsp-installer.txt b/doc/nvim-lsp-installer.txt
index 68e1ec5b..c7c5e28b 100644
--- a/doc/nvim-lsp-installer.txt
+++ b/doc/nvim-lsp-installer.txt
@@ -172,6 +172,8 @@ Example: >
The following settings are applied by default. >
local DEFAULT_SETTINGS = {
+ -- A list of servers to automatically install. Example: { "rust_analyzer", "sumneko_lua" }
+ ensure_installed = {},
ui = {
icons = {
-- The list icon to use for installed servers.
diff --git a/lua/nvim-lsp-installer.lua b/lua/nvim-lsp-installer.lua
index a910440e..ab566551 100644
--- a/lua/nvim-lsp-installer.lua
+++ b/lua/nvim-lsp-installer.lua
@@ -14,6 +14,22 @@ local M = {}
M.settings = settings.set
+---@param server_identifiers string[]
+local function ensure_installed(server_identifiers)
+ local candidates = {}
+ for _, server_identifier in ipairs(server_identifiers) do
+ local server_name, version = servers.parse_server_identifier(server_identifier)
+ local ok, server = servers.get_server(server_name)
+ if ok and not server:is_installed() then
+ table.insert(candidates, server_name)
+ server:install(version)
+ end
+ end
+ if #candidates > 0 then
+ notify("Installing LSP servers: " .. table.concat(candidates, ", "))
+ end
+end
+
---@param config table
function M.setup(config)
if config then
@@ -21,6 +37,9 @@ function M.setup(config)
end
settings.uses_new_setup = true
require("nvim-lsp-installer.middleware").register_lspconfig_hook()
+ vim.schedule(function()
+ ensure_installed(settings.current.ensure_installed)
+ end)
end
M.info_window = {
diff --git a/lua/nvim-lsp-installer/settings.lua b/lua/nvim-lsp-installer/settings.lua
index 87499354..7a36e217 100644
--- a/lua/nvim-lsp-installer/settings.lua
+++ b/lua/nvim-lsp-installer/settings.lua
@@ -4,6 +4,8 @@ local M = {}
---@class LspInstallerSettings
local DEFAULT_SETTINGS = {
+ -- A list of servers to automatically install. Example: { "rust_analyzer", "sumneko_lua" }
+ ensure_installed = {},
ui = {
icons = {
-- The list icon to use for installed servers.