瀏覽代碼

refactor(lsp)!: deprecate `lvim.lsp.diagnostics` (#3916)

CPea 2 年之前
父節點
當前提交
9e86655361
共有 5 個文件被更改,包括 58 次插入53 次删除
  1. 21 0
      lua/lvim/config/_deprecated.lua
  2. 26 0
      lua/lvim/config/settings.lua
  3. 10 31
      lua/lvim/lsp/config.lua
  4. 0 19
      lua/lvim/lsp/handlers.lua
  5. 1 3
      lua/lvim/lsp/init.lua

+ 21 - 0
lua/lvim/config/_deprecated.lua

@@ -53,12 +53,33 @@ function M.handle()
   lvim.lsp.popup_border = {}
   setmetatable(lvim.lsp.popup_border, mt)
 
+  ---@deprecated
+  lvim.lsp.float = {}
+  setmetatable(lvim.lsp.float, {
+    __newindex = function(_, k, _)
+      deprecate("lvim.lsp.float." .. k, "Use options provided by the handler instead")
+    end,
+  })
+
+  ---@deprecated
+  lvim.lsp.diagnostics = {}
+  setmetatable(lvim.lsp.diagnostics, {
+    __newindex = function(table, k, v)
+      deprecate("lvim.lsp.diagnostics." .. k, string.format("Use `vim.diagnostic.config({ %s = %s })` instead", k, v))
+      rawset(table, k, v)
+    end,
+  })
+
   ---@deprecated
   lvim.lang = {}
   setmetatable(lvim.lang, mt)
 end
 
 function M.post_load()
+  if lvim.lsp.diagnostics and not vim.tbl_isempty(lvim.lsp.diagnostics) then
+    vim.diagnostic.config(lvim.lsp.diagnostics)
+  end
+
   if lvim.lsp.override and not vim.tbl_isempty(lvim.lsp.override) then
     deprecate("lvim.lsp.override", "Use `lvim.lsp.automatic_configuration.skipped_servers` instead")
     vim.tbl_map(function(c)

+ 26 - 0
lua/lvim/config/settings.lua

@@ -74,6 +74,32 @@ M.load_default_options = function()
       ["[jt]sconfig.*.json"] = "jsonc",
     },
   }
+
+  local default_diagnostic_config = {
+    signs = {
+      active = true,
+      values = {
+        { name = "DiagnosticSignError", text = lvim.icons.diagnostics.Error },
+        { name = "DiagnosticSignWarn", text = lvim.icons.diagnostics.Warning },
+        { name = "DiagnosticSignHint", text = lvim.icons.diagnostics.Hint },
+        { name = "DiagnosticSignInfo", text = lvim.icons.diagnostics.Information },
+      },
+    },
+    virtual_text = true,
+    update_in_insert = false,
+    underline = true,
+    severity_sort = true,
+    float = {
+      focusable = true,
+      style = "minimal",
+      border = "rounded",
+      source = "always",
+      header = "",
+      prefix = "",
+    },
+  }
+
+  vim.diagnostic.config(default_diagnostic_config)
 end
 
 M.load_headless_options = function()

+ 10 - 31
lua/lvim/lsp/config.lua

@@ -58,36 +58,10 @@ local join_paths = require("lvim.utils").join_paths
 
 return {
   templates_dir = join_paths(get_runtime_dir(), "site", "after", "ftplugin"),
-  diagnostics = {
-    signs = {
-      active = true,
-      values = {
-        { name = "DiagnosticSignError", text = lvim.icons.diagnostics.Error },
-        { name = "DiagnosticSignWarn", text = lvim.icons.diagnostics.Warning },
-        { name = "DiagnosticSignHint", text = lvim.icons.diagnostics.Hint },
-        { name = "DiagnosticSignInfo", text = lvim.icons.diagnostics.Information },
-      },
-    },
-    virtual_text = true,
-    update_in_insert = false,
-    underline = true,
-    severity_sort = true,
-    float = {
-      focusable = true,
-      style = "minimal",
-      border = "rounded",
-      source = "always",
-      header = "",
-      prefix = "",
-    },
-  },
+  ---@deprecated use vim.diagnostic.config({ ... }) instead
+  diagnostics = {},
   document_highlight = false,
   code_lens_refresh = true,
-  float = {
-    focusable = true,
-    style = "minimal",
-    border = "rounded",
-  },
   on_attach_callback = nil,
   on_init_callback = nil,
   automatic_configuration = {
@@ -106,9 +80,14 @@ return {
       ["gs"] = { "<cmd>lua vim.lsp.buf.signature_help()<cr>", "show signature help" },
       ["gl"] = {
         function()
-          local config = lvim.lsp.diagnostics.float
-          config.scope = "line"
-          vim.diagnostic.open_float(0, config)
+          local float = vim.diagnostic.config().float
+
+          if float then
+            local config = type(float) == "table" and float or {}
+            config.scope = "line"
+
+            vim.diagnostic.open_float(config)
+          end
         end,
         "Show line diagnostics",
       },

+ 0 - 19
lua/lvim/lsp/handlers.lua

@@ -1,19 +0,0 @@
--- Set Default Prefix.
--- Note: You can set a prefix per lsp server in the lv-globals.lua file
-local M = {}
-
-function M.setup()
-  local config = { -- your config
-    virtual_text = lvim.lsp.diagnostics.virtual_text,
-    signs = lvim.lsp.diagnostics.signs,
-    underline = lvim.lsp.diagnostics.underline,
-    update_in_insert = lvim.lsp.diagnostics.update_in_insert,
-    severity_sort = lvim.lsp.diagnostics.severity_sort,
-    float = lvim.lsp.diagnostics.float,
-  }
-  vim.diagnostic.config(config)
-  vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, lvim.lsp.float)
-  vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, lvim.lsp.float)
-end
-
-return M

+ 1 - 3
lua/lvim/lsp/init.lua

@@ -95,13 +95,11 @@ function M.setup()
   end
 
   if lvim.use_icons then
-    for _, sign in ipairs(lvim.lsp.diagnostics.signs.values) do
+    for _, sign in ipairs(vim.tbl_get(vim.diagnostic.config(), "signs", "values") or {}) do
       vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = sign.name })
     end
   end
 
-  require("lvim.lsp.handlers").setup()
-
   if not utils.is_directory(lvim.lsp.templates_dir) then
     require("lvim.lsp.templates").generate_templates()
   end