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

Commit

Permalink
feat: add ensure_installed to setup table (#637)
Browse files Browse the repository at this point in the history
  • Loading branch information
williamboman authored Apr 28, 2022
1 parent 43a200f commit 8603cdc
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ Example:

```lua
require("nvim-lsp-installer").setup({
ensure_installed = { "sumneko_lua", "rust_analyzer" },
ui = {
icons = {
server_installed = "",
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions doc/nvim-lsp-installer.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 19 additions & 0 deletions lua/nvim-lsp-installer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,32 @@ 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
settings.set(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 = {
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 @@ -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.
Expand Down

0 comments on commit 8603cdc

Please sign in to comment.