diff options
| author | CPea <[email protected]> | 2023-04-21 00:58:52 +0700 | 
|---|---|---|
| committer | CPea <[email protected]> | 2023-04-24 19:11:25 +0700 | 
| commit | 66f82fe49ae5c43366caf8720ad4b9d790c73379 (patch) | |
| tree | 6bb72ebc68b83e3410c777c91eb3b5427a7a3b7d | |
| parent | a99b1db9a3f22f6e1b813086c68ad3f8bbb79ca8 (diff) | |
move default config to `settings.lua` and keep backward compability
keep backward compability
| -rw-r--r-- | lua/lvim/config/_deprecated.lua | 14 | ||||
| -rw-r--r-- | lua/lvim/config/init.lua | 2 | ||||
| -rw-r--r-- | lua/lvim/config/settings.lua | 33 | ||||
| -rw-r--r-- | lua/lvim/lsp/config.lua | 37 | ||||
| -rw-r--r-- | lua/lvim/lsp/handlers.lua | 45 | ||||
| -rw-r--r-- | lua/lvim/lsp/init.lua | 2 | 
6 files changed, 54 insertions, 79 deletions
| diff --git a/lua/lvim/config/_deprecated.lua b/lua/lvim/config/_deprecated.lua index d71d1c94..75b8daf8 100644 --- a/lua/lvim/config/_deprecated.lua +++ b/lua/lvim/config/_deprecated.lua @@ -57,15 +57,7 @@ function M.handle()    lvim.lsp.float = {}    setmetatable(lvim.lsp.float, {      __newindex = function(_, k, _) -      deprecate("lvim.lsp.float." .. k, "Use `lvim.lsp.handlers` instead.") -    end, -  }) - -  ---@deprecated -  lvim.lsp.diagnostics = {} -  setmetatable(lvim.lsp.diagnostics, { -    __newindex = function(_, k, _) -      deprecate("lvim.lsp.diagnostics." .. k, "Use `vim.diagnostic.config()` instead.") +      deprecate("lvim.lsp.float." .. k, "Use `float` option in `vim.diagnostic.config()` instead.")      end,    }) @@ -75,6 +67,10 @@ function M.handle()  end  function M.post_load() +  if lvim.lsp.diagnostics and not vim.tbl_isempty(lvim.lsp.diagnostics) then +    deprecate("lvim.lsp.diagnostics", "Use `vim.diagnostic.config()` instead") +  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) diff --git a/lua/lvim/config/init.lua b/lua/lvim/config/init.lua index 4ed9693f..90c17888 100644 --- a/lua/lvim/config/init.lua +++ b/lua/lvim/config/init.lua @@ -29,8 +29,6 @@ function M:init()    local lvim_lsp_config = require "lvim.lsp.config"    lvim.lsp = vim.deepcopy(lvim_lsp_config) -  require("lvim.lsp.handlers").load_defaults() -    lvim.builtin.luasnip = {      sources = {        friendly_snippets = true, diff --git a/lua/lvim/config/settings.lua b/lua/lvim/config/settings.lua index 42281ca1..b43b620e 100644 --- a/lua/lvim/config/settings.lua +++ b/lua/lvim/config/settings.lua @@ -74,6 +74,39 @@ 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 = "", +      format = function(d) +        local code = d.code or (d.user_data and d.user_data.lsp.code) +        if code then +          return string.format("%s [%s]", d.message, code):gsub("1. ", "") +        end +        return d.message +      end, +    }, +  } + +  vim.diagnostic.config(default_diagnostic_config)  end  M.load_headless_options = function() diff --git a/lua/lvim/lsp/config.lua b/lua/lvim/lsp/config.lua index 42bebdca..568441d2 100644 --- a/lua/lvim/lsp/config.lua +++ b/lua/lvim/lsp/config.lua @@ -54,37 +54,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, -  ---@usage list of the keys to override behavior of the handlers -  handlers = { -    focusable = true, -    style = "minimal", -    border = "rounded", -  },    on_attach_callback = nil,    on_init_callback = nil,    automatic_configuration = { @@ -106,11 +79,9 @@ return {            local config = vim.tbl_get(vim.diagnostic.config(), "float")            if config then -            return +            config.scope = "line" +            vim.diagnostic.open_float(0, config)            end - -          config.scope = "line" -          vim.diagnostic.open_float(0, config)          end,          "Show line diagnostics",        }, diff --git a/lua/lvim/lsp/handlers.lua b/lua/lvim/lsp/handlers.lua index f26bca1f..4a8c8319 100644 --- a/lua/lvim/lsp/handlers.lua +++ b/lua/lvim/lsp/handlers.lua @@ -2,42 +2,17 @@  -- Note: You can set a prefix per lsp server in the lv-globals.lua file  local M = {} -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 = "", -    format = function(d) -      local code = d.code or (d.user_data and d.user_data.lsp.code) -      if code then -        return string.format("%s [%s]", d.message, code):gsub("1. ", "") -      end -      return d.message -    end, -  }, -} +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, +  } -function M.load_defaults() -  vim.diagnostic.config(default_diagnostic_config) - -  vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, lvim.lsp.handlers) -  vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, lvim.lsp.handlers) +  vim.diagnostic.config(config)  end  return M diff --git a/lua/lvim/lsp/init.lua b/lua/lvim/lsp/init.lua index 62287b30..df63b39b 100644 --- a/lua/lvim/lsp/init.lua +++ b/lua/lvim/lsp/init.lua @@ -94,6 +94,8 @@ function M.setup()      return    end +  require("lvim.lsp.handlers").setup() +    if lvim.use_icons then      for _, sign in ipairs(vim.tbl_get(vim.diagnostic.config(), "signs", "values")) do        vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = sign.name }) | 
