From 2d687154968e7a12345fe6167b538cd8488114cb Mon Sep 17 00:00:00 2001 From: Michael Lingelbach Date: Wed, 14 Apr 2021 01:34:10 -0700 Subject: LspStart: make start all matching clients by default --- README.md | 2 +- lua/lspconfig.lua | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 60cdc004..d135cccd 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ omnifunc completion The following support tab-completion for all arguments: -* `:LspStart ` Start the requested server name. Will only succesfully start if the command detects a root directory matching the current config. Pass `autostart = false` to your `.setup{}` call for a language server if you would like to launch clients solely with this command. +* `:LspStart ` Start the requested server name. Will only succesfully start if the command detects a root directory matching the current config. Pass `autostart = false` to your `.setup{}` call for a language server if you would like to launch clients solely with this command. Defaults to all servers matching current buffer filetype. * `:LspStop ` Defaults to stopping all buffer clients. * `:LspRestart ` Defaults to restarting all buffer clients. diff --git a/lua/lspconfig.lua b/lua/lspconfig.lua index ba8660ec..a901a1a2 100644 --- a/lua/lspconfig.lua +++ b/lua/lspconfig.lua @@ -24,9 +24,22 @@ function M._root._setup() }; LspStart = { function(server_name) - require('lspconfig')[server_name].autostart() + if server_name then + require('lspconfig')[server_name].autostart() + else + local buffer_filetype = vim.bo.filetype + for client_name, config in pairs(configs) do + if config.filetypes then + for _, filetype_match in ipairs(config.filetypes) do + if buffer_filetype == filetype_match then + require('lspconfig')[client_name].autostart() + end + end + end + end + end end; - "-nargs=1 -complete=custom,v:lua.lsp_complete_configured_servers"; + "-nargs=? -complete=custom,v:lua.lsp_complete_configured_servers"; description = '`:LspStart` Manually launches a language server.'; }; LspStop = { -- cgit v1.3