瀏覽代碼

refactor(lsp): cleanup servers' override configuration (#2243)

* refactor(lsp): cleanup override settings

- rename lsp.override to lsp.automatic_configuration.ignored_servers
- add lsp.automatic_configuration.ignored_filetypes

* chore(info): update override section

* refactor(lsp): rename ignored to skipped

* fix: better deprecation handling

* docs(lsp): add example for (un-)skipping servers

* refactor(lsp): allow installing overridden servers

* docs(lsp): update config_win.example.lua as well

* chore(lsp): update skipped_servers list

* fix(logger): less noise from client_is_configured
kylo252 3 年之前
父節點
當前提交
198577aa75

+ 18 - 11
lua/lvim/config/init.lua

@@ -56,19 +56,19 @@ function M:init()
 end
 
 local function handle_deprecated_settings()
-  local function deprecation_notice(setting, msg)
+  local function deprecation_notice(setting, new_setting)
     local in_headless = #vim.api.nvim_list_uis() == 0
     if in_headless then
       return
     end
 
-    msg = msg
-      or string.format(
-        "Deprecation notice: [%s] setting is no longer supported. See https://github.com/LunarVim/LunarVim#breaking-changes",
-        setting
-      )
+    local msg = string.format(
+      "Deprecation notice: [%s] setting is no longer supported. %s",
+      setting,
+      new_setting or "See https://github.com/LunarVim/LunarVim#breaking-changes"
+    )
     vim.schedule(function()
-      Log:warn(msg)
+      vim.notify_once(msg, vim.log.levels.WARN)
     end)
   end
 
@@ -80,6 +80,16 @@ local function handle_deprecated_settings()
     end
   end
 
+  -- lvim.lsp.override
+  if lvim.lsp.override and not vim.tbl_isempty(lvim.lsp.override) then
+    deprecation_notice("lvim.lsp.override", "Use `lvim.lsp.automatic_configuration.skipped_servers` instead")
+    vim.tbl_map(function(c)
+      if not vim.tbl_contains(lvim.lsp.automatic_configuration.skipped_servers, c) then
+        table.insert(lvim.lsp.automatic_configuration.skipped_servers, c)
+      end
+    end, lvim.lsp.override)
+  end
+
   -- lvim.lsp.popup_border
   if vim.tbl_contains(vim.tbl_keys(lvim.lsp), "popup_border") then
     deprecation_notice "lvim.lsp.popup_border"
@@ -87,10 +97,7 @@ local function handle_deprecated_settings()
 
   -- dashboard.nvim
   if lvim.builtin.dashboard.active then
-    deprecation_notice(
-      "dashboard",
-      "Deprecation notice: `lvim.builtin.dashboard` has been replaced with `lvim.builtin.alpha`. See LunarVim#1906"
-    )
+    deprecation_notice("lvim.builtin.dashboard", "Use `lvim.builtin.alpha` instead. See LunarVim#1906")
   end
 end
 

+ 18 - 12
lua/lvim/core/info.lua

@@ -100,21 +100,26 @@ local function make_client_info(client)
   return client_info
 end
 
-local function make_override_info(ft)
+local function make_auto_lsp_info(ft)
+  local skipped_filetypes = lvim.lsp.automatic_configuration.skipped_filetypes
+  local skipped_servers = lvim.lsp.automatic_configuration.skipped_servers
+  local info_lines = { "Automatic LSP info" }
+
+  if vim.tbl_contains(skipped_filetypes, ft) then
+    vim.list_extend(info_lines, { "* Status: disabled for " .. ft })
+    return info_lines
+  end
+
   local available = lsp_utils.get_supported_servers_per_filetype(ft)
-  local overridden = vim.tbl_filter(function(name)
+  local skipped = vim.tbl_filter(function(name)
     return vim.tbl_contains(available, name)
-  end, lvim.lsp.override)
+  end, skipped_servers)
 
-  local info_lines = { "" }
-  if #overridden == 0 then
-    return info_lines
+  if #skipped == 0 then
+    return { "" }
   end
 
-  info_lines = {
-    fmt("Overridden %s server(s)", ft),
-    fmt("* list: %s", str_list(overridden)),
-  }
+  vim.list_extend(info_lines, { fmt("* Skipped servers: %s", str_list(skipped)) })
 
   return info_lines
 end
@@ -150,7 +155,7 @@ function M.toggle_popup(ft)
     table.insert(client_names, client.name)
   end
 
-  local override_info = make_override_info(ft)
+  local auto_lsp_info = make_auto_lsp_info(ft)
 
   local formatters_info = make_formatters_info(ft)
 
@@ -169,7 +174,7 @@ function M.toggle_popup(ft)
       { "" },
       lsp_info,
       { "" },
-      override_info,
+      auto_lsp_info,
       { "" },
       formatters_info,
       { "" },
@@ -192,6 +197,7 @@ function M.toggle_popup(ft)
     vim.fn.matchadd("LvimInfoHeader", "Formatters info")
     vim.fn.matchadd("LvimInfoHeader", "Linters info")
     vim.fn.matchadd("LvimInfoHeader", "Code actions info")
+    vim.fn.matchadd("LvimInfoHeader", "Automatic LSP info")
     vim.fn.matchadd("LvimInfoIdentifier", " " .. ft .. "$")
     vim.fn.matchadd("string", "true")
     vim.fn.matchadd("string", "active")

+ 48 - 41
lua/lvim/lsp/config.lua

@@ -1,3 +1,43 @@
+local skipped_servers = {
+  "angularls",
+  "ansiblels",
+  "ccls",
+  "csharp_ls",
+  "cssmodules_ls",
+  "denols",
+  "ember",
+  "emmet_ls",
+  "eslint",
+  "eslintls",
+  "golangci_lint_ls",
+  "graphql",
+  "jedi_language_server",
+  "ltex",
+  "ocamlls",
+  "phpactor",
+  "psalm",
+  "pylsp",
+  "quick_lint_js",
+  "rome",
+  "reason_ls",
+  "scry",
+  "solang",
+  "solidity_ls",
+  "sorbet",
+  "sourcekit",
+  "sourcery",
+  "spectral",
+  "sqlls",
+  "sqls",
+  "stylelint_lsp",
+  "tailwindcss",
+  "tflint",
+  "verible",
+  "vuels",
+}
+
+local skipped_filetypes = { "markdown", "rst", "plaintext" }
+
 return {
   templates_dir = join_paths(get_runtime_dir(), "site", "after", "ftplugin"),
   diagnostics = {
@@ -41,6 +81,12 @@ return {
   on_attach_callback = nil,
   on_init_callback = nil,
   automatic_servers_installation = true,
+  automatic_configuration = {
+    ---@usage list of servers that the automatic installer will skip
+    skipped_servers = skipped_servers,
+    ---@usage list of filetypes that the automatic installer will skip
+    skipped_filetypes = skipped_filetypes,
+  },
   buffer_mappings = {
     normal_mode = {
       ["K"] = { "<cmd>lua vim.lsp.buf.hover()<CR>", "Show hover" },
@@ -62,45 +108,6 @@ return {
     setup = {},
     config = {},
   },
-  override = {
-    "angularls",
-    "ansiblels",
-    "ccls",
-    "csharp_ls",
-    "cssmodules_ls",
-    "denols",
-    "ember",
-    "emmet_ls",
-    "eslint",
-    "eslintls",
-    "golangci_lint_ls",
-    "grammarly",
-    "graphql",
-    "jedi_language_server",
-    "ltex",
-    "ocamlls",
-    "phpactor",
-    "psalm",
-    "pylsp",
-    "quick_lint_js",
-    "reason_ls",
-    "remark_ls",
-    "rome",
-    "scry",
-    "solang",
-    "solidity_ls",
-    "sorbet",
-    "sourcekit",
-    "sourcery",
-    "spectral",
-    "sqlls",
-    "sqls",
-    "stylelint_lsp",
-    "tailwindcss",
-    "tflint",
-    "verible",
-    "vuels",
-    "zeta_note",
-    "zk",
-  },
+  ---@deprecated use automatic_configuration.skipped_servers instead
+  override = {},
 }

+ 2 - 4
lua/lvim/lsp/manager.lua

@@ -55,6 +55,7 @@ local function client_is_configured(server_name, ft)
   local active_autocmds = vim.split(vim.fn.execute("autocmd FileType " .. ft), "\n")
   for _, result in ipairs(active_autocmds) do
     if result:match(server_name) then
+      Log:debug(string.format("[%q] is already configured", server_name))
       return true
     end
   end
@@ -68,7 +69,6 @@ function M.setup(server_name, user_config)
   vim.validate { name = { server_name, "string" } }
 
   if lvim_lsp_utils.is_client_active(server_name) or client_is_configured(server_name) then
-    Log:debug(string.format("[%q] is already configured. Ignoring repeated setup call.", server_name))
     return
   end
 
@@ -77,9 +77,7 @@ function M.setup(server_name, user_config)
   local servers = require "nvim-lsp-installer.servers"
   local server_available, requested_server = servers.get_server(server_name)
 
-  local is_overridden = vim.tbl_contains(lvim.lsp.override, server_name)
-
-  if not server_available or is_overridden then
+  if not server_available then
     pcall(function()
       require("lspconfig")[server_name].setup(config)
       buf_try_add(server_name)

+ 9 - 3
lua/lvim/lsp/templates.lua

@@ -15,16 +15,22 @@ function M.remove_template_files()
   end
 end
 
+local skipped_filetypes = lvim.lsp.automatic_configuration.skipped_filetypes
+local skipped_servers = lvim.lsp.automatic_configuration.skipped_servers
+
 ---Generates an ftplugin file based on the server_name in the selected directory
 ---@param server_name string name of a valid language server, e.g. pyright, gopls, tsserver, etc.
 ---@param dir string the full path to the desired directory
 function M.generate_ftplugin(server_name, dir)
-  if vim.tbl_contains(lvim.lsp.override, server_name) then
+  if vim.tbl_contains(skipped_servers, server_name) then
     return
   end
 
-  -- we need to go through lspconfig to get the corresponding filetypes currently
-  local filetypes = lvim_lsp_utils.get_supported_filetypes(server_name) or {}
+  -- get the supported filetypes and remove any ignored ones
+  local filetypes = vim.tbl_filter(function(ft)
+    return not vim.tbl_contains(skipped_filetypes, ft)
+  end, lvim_lsp_utils.get_supported_filetypes(server_name) or {})
+
   if not filetypes then
     return
   end

+ 10 - 6
utils/installer/config.example.lua

@@ -85,13 +85,17 @@ lvim.builtin.treesitter.highlight.enabled = true
 -- ---@usage disable automatic installation of servers
 -- lvim.lsp.automatic_servers_installation = false
 
--- ---@usage Select which servers should be configured manually. Requires `:LvimCacheReset` to take effect.
--- See the full default list `:lua print(vim.inspect(lvim.lsp.override))`
--- vim.list_extend(lvim.lsp.override, { "pyright" })
-
--- ---@usage setup a server -- see: https://www.lunarvim.org/languages/#overriding-the-default-configuration
+-- ---configure a server manually. !!Requires `:LvimCacheReset` to take effect!!
+-- ---see the full default list `:lua print(vim.inspect(lvim.lsp.automatic_configuration.skipped_servers))`
+-- vim.list_extend(lvim.lsp.automatic_configuration.skipped_servers, { "pyright" })
 -- local opts = {} -- check the lspconfig documentation for a list of all possible options
--- require("lvim.lsp.manager").setup("pylsp", opts)
+-- require("lvim.lsp.manager").setup("pyright", opts)
+
+-- ---remove a server from the skipped list, e.g. eslint, or emmet_ls. !!Requires `:LvimCacheReset` to take effect!!
+-- ---`:LvimInfo` lists which server(s) are skiipped for the current filetype
+-- vim.tbl_map(function(server)
+--   return server ~= "emmet_ls"
+-- end, lvim.lsp.automatic_configuration.skipped_servers)
 
 -- -- you can set a custom on_attach function that will be used for all the language servers
 -- -- See <https://github.com/neovim/nvim-lspconfig#keybindings-and-completion>

+ 10 - 6
utils/installer/config_win.example.lua

@@ -100,13 +100,17 @@ lvim.builtin.treesitter.highlight.enabled = true
 -- ---@usage disable automatic installation of servers
 -- lvim.lsp.automatic_servers_installation = false
 
--- ---@usage Select which servers should be configured manually. Requires `:LvimCacheRest` to take effect.
--- See the full default list `:lua print(vim.inspect(lvim.lsp.override))`
--- vim.list_extend(lvim.lsp.override, { "pyright" })
-
--- ---@usage setup a server -- see: https://www.lunarvim.org/languages/#overriding-the-default-configuration
+-- ---configure a server manually. !!Requires `:LvimCacheReset` to take effect!!
+-- ---see the full default list `:lua print(vim.inspect(lvim.lsp.automatic_configuration.skipped_servers))`
+-- vim.list_extend(lvim.lsp.automatic_configuration.skipped_servers, { "pyright" })
 -- local opts = {} -- check the lspconfig documentation for a list of all possible options
--- require("lvim.lsp.manager").setup("pylsp", opts)
+-- require("lvim.lsp.manager").setup("pyright", opts)
+
+-- ---remove a server from the skipped list, e.g. eslint, or emmet_ls. !!Requires `:LvimCacheReset` to take effect!!
+-- ---`:LvimInfo` lists which server(s) are skiipped for the current filetype
+-- vim.tbl_map(function(server)
+--   return server ~= "emmet_ls"
+-- end, lvim.lsp.automatic_configuration.skipped_servers)
 
 -- -- you can set a custom on_attach function that will be used for all the language servers
 -- -- See <https://github.com/neovim/nvim-lspconfig#keybindings-and-completion>