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 c7bc86a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Example:

```lua
require("nvim-lsp-installer").setup({
ensure_installed = { "sumneko_lua", "rust_analyzer" },
ensure_installed = "automatic", -- this can alternatively be a list of servers like { "sumneko_lua", "rust_analyzer" }
ui = {
icons = {
server_installed = "",
Expand Down Expand Up @@ -267,7 +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" }
-- A list of servers to automatically install, or "automatic". Example: { "rust_analyzer", "sumneko_lua" }
-- Setting this to "automatic" will automatically install LSP servers that are set up via lspconfig.
ensure_installed = {},
ui = {
icons = {
Expand Down
4 changes: 3 additions & 1 deletion doc/nvim-lsp-installer.txt
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ Refer to the |nvim-lsp-installer-default-settings| for all available settings.
Example: >
require("nvim-lsp-installer").setup({
ensure_installed = "automatic",
ui = {
icons = {
server_installed = "✓",
Expand All @@ -172,7 +173,8 @@ 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, or "automatic". Example: { "rust_analyzer", "sumneko_lua" }
-- Setting this to "automatic" will automatically install LSP servers that are set up via lspconfig.
ensure_installed = {},
ui = {
icons = {
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.ensure_installed == "on_demand" and not server:is_installed() then
server:install()
end
end
end)
end
Expand Down

0 comments on commit c7bc86a

Please sign in to comment.