diff options
| author | kylo252 <[email protected]> | 2021-12-06 17:04:46 +0100 | 
|---|---|---|
| committer | GitHub <[email protected]> | 2021-12-06 17:04:46 +0100 | 
| commit | 6770808bec1ffcada425ae514747f9380e3d3b8d (patch) | |
| tree | 657712b9a93588b16db9646446089f6f084c9b65 /lua | |
| parent | 38a172434027c9ac2a71cd658803ec3f7a39ab09 (diff) | |
feat: full compatibility with neovim v0.6 (#2037)
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/lvim/lsp/config.lua | 23 | ||||
| -rw-r--r-- | lua/lvim/lsp/handlers.lua | 70 | ||||
| -rw-r--r-- | lua/lvim/lsp/init.lua | 12 | ||||
| -rw-r--r-- | lua/lvim/plugins.lua | 2 | ||||
| -rw-r--r-- | lua/lvim/utils/hooks.lua | 11 | 
5 files changed, 55 insertions, 63 deletions
| diff --git a/lua/lvim/lsp/config.lua b/lua/lvim/lsp/config.lua index 18f1218d..a990f8c7 100644 --- a/lua/lvim/lsp/config.lua +++ b/lua/lvim/lsp/config.lua @@ -4,16 +4,31 @@ return {      signs = {        active = true,        values = { -        { name = "LspDiagnosticsSignError", text = "" }, -        { name = "LspDiagnosticsSignWarning", text = "" }, -        { name = "LspDiagnosticsSignHint", text = "" }, -        { name = "LspDiagnosticsSignInformation", text = "" }, +        { name = "DiagnosticSignError", text = "" }, +        { name = "DiagnosticSignWarn", text = "" }, +        { name = "DiagnosticSignHint", text = "" }, +        { name = "DiagnosticSignInfo", text = "" },        },      },      virtual_text = true,      update_in_insert = false,      underline = true,      severity_sort = true, +    float = { +      focusable = false, +      style = "minimal", +      border = "rounded", +      source = "always", +      header = "", +      prefix = "", +      format = function(d) +        local t = vim.deepcopy(d) +        if d.code then +          t.message = string.format("%s [%s]", t.message, t.code):gsub("1. ", "") +        end +        return t.message +      end, +    },    },    document_highlight = true,    code_lens_refresh = true, diff --git a/lua/lvim/lsp/handlers.lua b/lua/lvim/lsp/handlers.lua index 27ce8589..45f73e91 100644 --- a/lua/lvim/lsp/handlers.lua +++ b/lua/lvim/lsp/handlers.lua @@ -9,42 +9,10 @@ function M.setup()      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,    } -  if vim.fn.has "nvim-0.5.1" > 0 then -    vim.lsp.handlers["textDocument/publishDiagnostics"] = function(_, result, ctx, _) -      local uri = result.uri -      local bufnr = vim.uri_to_bufnr(uri) -      if not bufnr then -        return -      end - -      local diagnostics = result.diagnostics -      local ok, vim_diag = pcall(require, "vim.diagnostic") -      if ok then -        -- FIX: why can't we just use vim.diagnostic.get(buf_id)? -        config.signs = true -        for i, diagnostic in ipairs(diagnostics) do -          local rng = diagnostic.range -          diagnostics[i].lnum = rng["start"].line -          diagnostics[i].end_lnum = rng["end"].line -          diagnostics[i].col = rng["start"].character -          diagnostics[i].end_col = rng["end"].character -        end -        local namespace = vim.lsp.diagnostic.get_namespace(ctx.client_id) - -        vim_diag.set(namespace, bufnr, diagnostics, config) -        if not vim.api.nvim_buf_is_loaded(bufnr) then -          return -        end -        vim_diag.show(namespace, bufnr, diagnostics, config) -      else -        vim.lsp.diagnostic.save(diagnostics, bufnr, ctx.client_id) -        if not vim.api.nvim_buf_is_loaded(bufnr) then -          return -        end -        vim.lsp.diagnostic.display(diagnostics, bufnr, ctx.client_id, config) -      end -    end +  if vim.fn.has "nvim-0.6" == 1 then +    vim.diagnostic.config(config)    else      vim.lsp.handlers["textDocument/publishDiagnostics"] = function(_, _, params, client_id, _)        local uri = params.uri @@ -60,27 +28,29 @@ function M.setup()        end        vim.lsp.diagnostic.display(diagnostics, bufnr, client_id, config)      end -  end - -  vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { -    border = lvim.lsp.popup_border, -  }) -  vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, { -    border = lvim.lsp.popup_border, -  }) -end +    vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { +      border = lvim.lsp.popup_border, +    }) -local function split_by_chunk(text, chunkSize) -  local s = {} -  for i = 1, #text, chunkSize do -    s[#s + 1] = text:sub(i, i + chunkSize - 1) +    vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, { +      border = lvim.lsp.popup_border, +    })    end -  return s  end  function M.show_line_diagnostics() -  -- TODO: replace all this with vim.diagnostic.show_position_diagnostics() +  if vim.fn.has "nvim-0.6" == 1 then +    return vim.diagnostic.open_float(0, { scope = "line" }) +  end + +  local function split_by_chunk(text, chunkSize) +    local s = {} +    for i = 1, #text, chunkSize do +      s[#s + 1] = text:sub(i, i + chunkSize - 1) +    end +    return s +  end    local diagnostics = vim.lsp.diagnostic.get_line_diagnostics()    local severity_highlight = {      "LspDiagnosticsFloatingError", diff --git a/lua/lvim/lsp/init.lua b/lua/lvim/lsp/init.lua index 9764950d..68a64d6c 100644 --- a/lua/lvim/lsp/init.lua +++ b/lua/lvim/lsp/init.lua @@ -137,10 +137,10 @@ function M.get_common_opts()  end  local LSP_DEPRECATED_SIGN_MAP = { -  ["LspDiagnosticsSignError"] = "DiagnosticSignError", -  ["LspDiagnosticsSignWarning"] = "DiagnosticSignWarn", -  ["LspDiagnosticsSignHint"] = "DiagnosticSignHint", -  ["LspDiagnosticsSignInformation"] = "DiagnosticSignInfo", +  ["DiagnosticSignError"] = "LspDiagnosticsSignError", +  ["DiagnosticSignWarn"] = "LspDiagnosticsSignWarning", +  ["DiagnosticSignHint"] = "LspDiagnosticsSignHint", +  ["DiagnosticSignInfo"] = "LspDiagnosticsSignInformation",  }  function M.setup() @@ -151,11 +151,11 @@ function M.setup()      return    end -  local is_neovim_nightly = vim.fn.has "nvim-0.5.1" > 0 +  local is_neovim_5 = vim.fn.has "nvim-0.6" ~= 1    for _, sign in ipairs(lvim.lsp.diagnostics.signs.values) do      local lsp_sign_name = LSP_DEPRECATED_SIGN_MAP[sign.name] -    if is_neovim_nightly and lsp_sign_name then +    if is_neovim_5 and lsp_sign_name then        vim.fn.sign_define(lsp_sign_name, { texthl = lsp_sign_name, text = sign.text, numhl = lsp_sign_name })      end      vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = sign.name }) diff --git a/lua/lvim/plugins.lua b/lua/lvim/plugins.lua index a7d6c810..8b968a07 100644 --- a/lua/lvim/plugins.lua +++ b/lua/lvim/plugins.lua @@ -134,7 +134,7 @@ return {    {      "nvim-treesitter/nvim-treesitter",      commit = commit.treesitter, -    branch = "0.5-compat", +    branch = vim.fn.has "nvim-0.6" == 1 and "master" or "0.5-compat",      -- run = ":TSUpdate",      config = function()        require("lvim.core.treesitter").setup() diff --git a/lua/lvim/utils/hooks.lua b/lua/lvim/utils/hooks.lua index 0fe4a7fd..1d265482 100644 --- a/lua/lvim/utils/hooks.lua +++ b/lua/lvim/utils/hooks.lua @@ -7,7 +7,9 @@ local in_headless = #vim.api.nvim_list_uis() == 0  function M.run_pre_update()    Log:debug "Starting pre-update hook"    _G.__luacache.clear_cache() -  vim.cmd "LspStop" +  if package.loaded["lspconfig"] then +    vim.cmd [[ LspStop ]] +  end  end  ---Reset any startup cache files used by Packer and Impatient @@ -34,9 +36,14 @@ function M.run_post_update()    if not in_headless then      vim.schedule(function() +      if package.loaded["nvim-treesitter"] then +        vim.cmd [[ TSUpdateSync ]] +      end        -- TODO: add a changelog        vim.notify("Update complete", vim.log.levels.INFO) -      vim.cmd "LspRestart" +      if package.loaded["lspconfig"] then +        vim.cmd [[ LspRestart ]] +      end      end)    end  end | 
