aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2021-12-13 07:54:47 +0100
committerGitHub <noreply@github.com>2021-12-13 07:54:47 +0100
commitd7b10b13d72d4bf8f7b34779ddc3514bcc26b0f2 (patch)
tree0c697a373655d0e5fd2907ff5787942001c86cf2 /lua
parent.github: update new server request template (diff)
downloadmason-d7b10b13d72d4bf8f7b34779ddc3514bcc26b0f2.tar
mason-d7b10b13d72d4bf8f7b34779ddc3514bcc26b0f2.tar.gz
mason-d7b10b13d72d4bf8f7b34779ddc3514bcc26b0f2.tar.bz2
mason-d7b10b13d72d4bf8f7b34779ddc3514bcc26b0f2.tar.lz
mason-d7b10b13d72d4bf8f7b34779ddc3514bcc26b0f2.tar.xz
mason-d7b10b13d72d4bf8f7b34779ddc3514bcc26b0f2.tar.zst
mason-d7b10b13d72d4bf8f7b34779ddc3514bcc26b0f2.zip
feat: allow server installation by just typing `:LspInstall` (#331)
This will prompt the user which server associated with the currently opened buffer's &filetype to install.
Diffstat (limited to 'lua')
-rw-r--r--lua/nvim-lsp-installer.lua23
1 files changed, 23 insertions, 0 deletions
diff --git a/lua/nvim-lsp-installer.lua b/lua/nvim-lsp-installer.lua
index 3a7e8b2f..62b20a1e 100644
--- a/lua/nvim-lsp-installer.lua
+++ b/lua/nvim-lsp-installer.lua
@@ -8,6 +8,7 @@ local settings = require "nvim-lsp-installer.settings"
local log = require "nvim-lsp-installer.log"
local platform = require "nvim-lsp-installer.platform"
local language_autocomplete_map = require "nvim-lsp-installer._generated.language_autocomplete_map"
+local filetype_server_map = require "nvim-lsp-installer._generated.filetype_map"
local M = {}
@@ -62,6 +63,10 @@ function M.install_sync(server_identifiers)
local failed_servers = {}
local server_tuples = {}
+ if vim.tbl_count(server_identifiers) == 0 then
+ raise_error "No servers provided."
+ end
+
-- Collect all servers and exit early if unable to find one.
for _, server_identifier in pairs(server_identifiers) do
local server_name, version = servers.parse_server_identifier(server_identifier)
@@ -143,6 +148,24 @@ local function resolve_language_alias(server_name, callback)
end
end
+---Will prompt the user via vim.ui.select() to select which server associated with the provided filetype to install.
+---If the provided filetype is not associated with a server, an error message will be displayed.
+---@param filetype string
+function M.install_by_filetype(filetype)
+ local servers_by_filetype = filetype_server_map[filetype]
+ if servers_by_filetype then
+ vim.ui.select(servers_by_filetype, {
+ prompt = ("Please select which server you want to install for filetype %q:"):format(filetype),
+ }, function(choice)
+ if choice then
+ M.install(choice)
+ end
+ end)
+ else
+ notify(("No LSP servers found for filetype %q"):format(filetype), vim.log.levels.WARN)
+ end
+end
+
--- Queues a server to be installed. Will also open the status window.
--- Use the .on_server_ready(cb) function to register a handler to be executed when a server is ready to be set up.
---@param server_identifier string @The server to install. This can also include a requested version, for example "rust_analyzer@nightly".