feat: full compatibility with neovim v0.6 (#2037)

This commit is contained in:
kylo252 2021-12-06 17:04:46 +01:00 committed by GitHub
commit 6770808bec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 69 additions and 65 deletions

View file

@ -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,

View file

@ -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,7 +28,6 @@ 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,
@ -70,6 +37,12 @@ function M.setup()
border = lvim.lsp.popup_border,
})
end
end
function M.show_line_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 = {}
@ -78,9 +51,6 @@ local function split_by_chunk(text, chunkSize)
end
return s
end
function M.show_line_diagnostics()
-- TODO: replace all this with vim.diagnostic.show_position_diagnostics()
local diagnostics = vim.lsp.diagnostic.get_line_diagnostics()
local severity_highlight = {
"LspDiagnosticsFloatingError",

View file

@ -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 })

View file

@ -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()

View file

@ -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

View file

@ -174,6 +174,17 @@ function print_missing_dep_msg() {
fi
}
function check_neovim_min_version() {
# TODO: consider locking the requirement to 0.6+
local verify_version_cmd='if !has("nvim-0.5.1") | cquit | else | quit | endif'
# exit with an error if min_version not found
if ! nvim --headless -u NONE -c "$verify_version_cmd"; then
echo "[ERROR]: LunarVim requires at least Neovim v0.5.1 or higher"
exit 1
fi
}
function check_system_deps() {
if ! command -v git &>/dev/null; then
print_missing_dep_msg "git"
@ -183,6 +194,7 @@ function check_system_deps() {
print_missing_dep_msg "neovim"
exit 1
fi
check_neovim_min_version
}
function __install_nodejs_deps_npm() {