From 016cd4bdfd7740d71fae024162a47b8e8a72af03 Mon Sep 17 00:00:00 2001 From: William Boman Date: Fri, 29 Apr 2022 13:32:59 +0200 Subject: feat: add 'automatic_installation' feature toggle to setup options (#638) --- README.md | 7 +++++-- doc/nvim-lsp-installer.txt | 6 +++++- lua/nvim-lsp-installer.lua | 9 ++++++--- lua/nvim-lsp-installer/middleware.lua | 4 ++++ lua/nvim-lsp-installer/settings.lua | 2 ++ 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index d22b6c12..f1804a35 100644 --- a/README.md +++ b/README.md @@ -114,7 +114,8 @@ Example: ```lua require("nvim-lsp-installer").setup({ - ensure_installed = { "sumneko_lua", "rust_analyzer" }, + ensure_installed = { "rust_analyzer", "sumneko_lua" }, + automatic_installation = true, ui = { icons = { server_installed = "✓", @@ -267,8 +268,10 @@ 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" } + -- A list of servers to automatically install if they're not already installed. 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. + automatic_installation = false, 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 75b9e242..b9b05e55 100644 --- a/doc/nvim-lsp-installer.txt +++ b/doc/nvim-lsp-installer.txt @@ -158,6 +158,8 @@ Refer to the |nvim-lsp-installer-default-settings| for all available settings. Example: > require("nvim-lsp-installer").setup({ + ensure_installed = { "rust_analyzer", "sumneko_lua" }, + automatic_installation = true, ui = { icons = { server_installed = "✓", @@ -172,8 +174,10 @@ Example: > The following settings are applied by default. > local DEFAULT_SETTINGS = { - -- A list of servers to automatically install. Example: { "rust_analyzer", "sumneko_lua" } + -- A list of servers to automatically install if they're not already installed. 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. + automatic_installation = false, 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 f41dbbf7..631f66a2 100644 --- a/lua/nvim-lsp-installer.lua +++ b/lua/nvim-lsp-installer.lua @@ -37,9 +37,12 @@ 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) + + if vim.tbl_islist(settings.current.ensure_installed) then + vim.schedule(function() + ensure_installed(settings.current.ensure_installed) + end) + end end M.info_window = { diff --git a/lua/nvim-lsp-installer/middleware.lua b/lua/nvim-lsp-installer/middleware.lua index 3e01b976..cd5c508d 100644 --- a/lua/nvim-lsp-installer/middleware.lua +++ b/lua/nvim-lsp-installer/middleware.lua @@ -1,5 +1,6 @@ local util = require "lspconfig.util" local servers = require "nvim-lsp-installer.servers" +local settings = require "nvim-lsp-installer.settings" local M = {} @@ -25,6 +26,9 @@ function M.register_lspconfig_hook() local ok, server = servers.get_server(config.name) if ok then merge_in_place(config, server._default_options) + if settings.current.automatic_installation and not server:is_installed() then + server:install() + end end end) end diff --git a/lua/nvim-lsp-installer/settings.lua b/lua/nvim-lsp-installer/settings.lua index 7a36e217..44c739db 100644 --- a/lua/nvim-lsp-installer/settings.lua +++ b/lua/nvim-lsp-installer/settings.lua @@ -6,6 +6,8 @@ local M = {} 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. + automatic_installation = false, ui = { icons = { -- The list icon to use for installed servers. -- cgit v1.2.3-70-g09d2