aboutsummaryrefslogtreecommitdiffstats
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
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.
-rw-r--r--README.md2
-rw-r--r--doc/nvim-lsp-installer.txt15
-rw-r--r--lua/nvim-lsp-installer.lua23
-rw-r--r--plugin/nvim-lsp-installer.vim15
4 files changed, 48 insertions, 7 deletions
diff --git a/README.md b/README.md
index 9168e699..e16cd97d 100644
--- a/README.md
+++ b/README.md
@@ -60,7 +60,7 @@ Plug 'williamboman/nvim-lsp-installer'
### Commands
- `:LspInstallInfo` - opens a graphical overview of your language servers
-- `:LspInstall [--sync] <server> ...` - installs/reinstalls language servers. Runs in a blocking fashion if the `--sync` argument is passed (only recommended for scripting purposes).
+- `:LspInstall [--sync] [server] ...` - installs/reinstalls language servers. Runs in a blocking fashion if the `--sync` argument is passed (only recommended for scripting purposes).
- `:LspUninstall [--sync] <server> ...` - uninstalls language servers. Runs in a blocking fashion if the `--sync` argument is passed (only recommended for scripting purposes).
- `:LspUninstallAll [--no-confirm]` - uninstalls all language servers
- `:LspInstallLog` - opens the log file in a new tab window
diff --git a/doc/nvim-lsp-installer.txt b/doc/nvim-lsp-installer.txt
index 5a9794a7..14703df6 100644
--- a/doc/nvim-lsp-installer.txt
+++ b/doc/nvim-lsp-installer.txt
@@ -79,6 +79,12 @@ of the server name, like so: >
:LspInstall tsserver@0.6.3 graphql@latest rust_analyzer@nightly
<
+To install a server associated with the filetype of the currently opened
+buffer, simply just run: >
+
+ :LspInstall
+<
+
Please refer to each server's own release page to find which versions are
available.
@@ -130,15 +136,20 @@ COMMANDS *nvim-lsp-installer-commands*
Opens the UI for nvim-lsp-installer.
*:LspInstall*
-:LspInstall [--sync] {server_name} ...
+:LspInstall [--sync] [server_name] ...
Installs language servers. If the `--sync` argument is passed, the command will
be blocking until all installations complete. This is useful for headless
installations, for example: >
$ nvim --headless -c "LspInstall --sync rust_analyzer clangd clojure_lsp" -c q
-
<
+
+If no server names are provided (`:LspInstall`), you will be prompted to
+select which server associated with the currently opened buffer's filetype you
+want to install. If none are associated, an error message will be printed
+instead.
+
*:LspUninstall*
:LspUninstall [--sync] {server_name} ...
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".
diff --git a/plugin/nvim-lsp-installer.vim b/plugin/nvim-lsp-installer.vim
index e6470072..3829384c 100644
--- a/plugin/nvim-lsp-installer.vim
+++ b/plugin/nvim-lsp-installer.vim
@@ -19,6 +19,9 @@ function! s:LspUninstallAllCompletion(...) abort
endfunction
function! s:ParseArgs(args)
+ if len(a:args) == 0
+ return { 'sync': v:false, 'servers': [] }
+ endif
let sync = a:args[0] == "--sync"
let servers = sync ? a:args[1:] : a:args
return { 'sync': sync, 'servers': servers }
@@ -29,9 +32,13 @@ function! s:LspInstall(args) abort
if parsed_args.sync
call luaeval("require'nvim-lsp-installer'.install_sync(_A)", parsed_args.servers)
else
- for server_name in l:parsed_args.servers
- call luaeval("require'nvim-lsp-installer'.install(_A)", server_name)
- endfor
+ if len(parsed_args.servers) == 0
+ call luaeval("require'nvim-lsp-installer'.install_by_filetype(_A)", &filetype)
+ else
+ for server_name in l:parsed_args.servers
+ call luaeval("require'nvim-lsp-installer'.install(_A)", server_name)
+ endfor
+ endif
endif
endfunction
@@ -63,7 +70,7 @@ function! s:LspInstallLog() abort
exe 'tabnew ' .. luaeval("require'nvim-lsp-installer.log'.outfile")
endfunction
-command! -bar -nargs=+ -complete=custom,s:LspInstallCompletion LspInstall call s:LspInstall([<f-args>])
+command! -bar -nargs=* -complete=custom,s:LspInstallCompletion LspInstall call s:LspInstall([<f-args>])
command! -bar -nargs=+ -complete=custom,s:LspUninstallCompletion LspUninstall call s:LspUninstall([<f-args>])
command! -bar -nargs=? -complete=custom,s:LspUninstallAllCompletion LspUninstallAll call s:LspUninstallAll([<f-args>])