Skip to content
This repository has been archived by the owner on Nov 12, 2022. It is now read-only.

Commit

Permalink
feat: add 'automatic' option to ensure_installed setting
Browse files Browse the repository at this point in the history
  • Loading branch information
williamboman committed Apr 28, 2022
1 parent 8603cdc commit b23b6d5
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "",
Expand Down Expand Up @@ -269,6 +270,8 @@ Illustrations in the logo are derived from [@Kaligule](https://schauderbasis.de/
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.
Expand Down
6 changes: 5 additions & 1 deletion doc/nvim-lsp-installer.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "✓",
Expand All @@ -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 be installed 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.
Expand Down
9 changes: 6 additions & 3 deletions lua/nvim-lsp-installer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
4 changes: 4 additions & 0 deletions lua/nvim-lsp-installer/middleware.lua
Original file line number Diff line number Diff line change
@@ -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 = {}

Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions lua/nvim-lsp-installer/settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit b23b6d5

Please sign in to comment.