refactor: uplift neovim's minimum version requirement to 0.6.0 (#2093)

Co-authored-by: kylo252 <59826753+kylo252@users.noreply.github.com>
This commit is contained in:
Abouzar Parvan 2021-12-23 13:03:20 +03:30 committed by GitHub
parent 5593499828
commit 655fd1b0ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 38 additions and 158 deletions

View file

@ -26,7 +26,7 @@ You can find all the documentation for LunarVim at [lunarvim.org](https://www.lu
## Install In One Command! ## Install In One Command!
Make sure you have the release version of Neovim (0.5). Make sure you have the release version of Neovim (0.6).
```bash ```bash
bash <(curl -s https://raw.githubusercontent.com/lunarvim/lunarvim/master/utils/installer/install.sh) bash <(curl -s https://raw.githubusercontent.com/lunarvim/lunarvim/master/utils/installer/install.sh)

View file

@ -78,7 +78,7 @@ local get_format_on_save_opts = function()
end end
function M.enable_format_on_save(opts) function M.enable_format_on_save(opts)
local fmd_cmd = string.format(":silent lua vim.lsp.buf.formatting_sync({}, %s)", opts.timeout_ms) local fmd_cmd = string.format(":silent lua vim.lsp.buf.formatting_sync({}, %s)", opts.timeout)
M.define_augroups { M.define_augroups {
format_on_save = { { "BufWritePre", opts.pattern, fmd_cmd } }, format_on_save = { { "BufWritePre", opts.pattern, fmd_cmd } },
} }

View file

@ -61,12 +61,12 @@ M.config = function()
-- NOTE: Prefer using : over <cmd> as the latter avoids going back in normal-mode. -- NOTE: Prefer using : over <cmd> as the latter avoids going back in normal-mode.
-- see https://neovim.io/doc/user/map.html#:map-cmd -- see https://neovim.io/doc/user/map.html#:map-cmd
vmappings = { vmappings = {
["/"] = { "<ESC><CMD>lua require('Comment.api').gc(vim.fn.visualmode())<CR>", "Comment" }, ["/"] = { "<ESC><CMD>lua require('Comment.api').toggle_linewise_op(vim.fn.visualmode())<CR>", "Comment" },
}, },
mappings = { mappings = {
["w"] = { "<cmd>w!<CR>", "Save" }, ["w"] = { "<cmd>w!<CR>", "Save" },
["q"] = { "<cmd>q!<CR>", "Quit" }, ["q"] = { "<cmd>q!<CR>", "Quit" },
["/"] = { "<cmd>lua require('Comment').toggle()<CR>", "Comment" }, ["/"] = { "<cmd>lua require('Comment.api').toggle_current_linewise()<CR>", "Comment" },
["c"] = { "<cmd>BufferClose!<CR>", "Close Buffer" }, ["c"] = { "<cmd>BufferClose!<CR>", "Close Buffer" },
["f"] = { require("lvim.core.telescope.custom-finders").find_project_files, "Find File" }, ["f"] = { require("lvim.core.telescope.custom-finders").find_project_files, "Find File" },
["h"] = { "<cmd>nohlsearch<CR>", "No Highlight" }, ["h"] = { "<cmd>nohlsearch<CR>", "No Highlight" },
@ -152,11 +152,11 @@ M.config = function()
i = { "<cmd>LspInfo<cr>", "Info" }, i = { "<cmd>LspInfo<cr>", "Info" },
I = { "<cmd>LspInstallInfo<cr>", "Installer Info" }, I = { "<cmd>LspInstallInfo<cr>", "Installer Info" },
j = { j = {
"<cmd>lua vim.lsp.diagnostic.goto_next({popup_opts = {border = lvim.lsp.popup_border}})<cr>", "<cmd>lua vim.diagnostic.goto_next()<cr>",
"Next Diagnostic", "Next Diagnostic",
}, },
k = { k = {
"<cmd>lua vim.lsp.diagnostic.goto_prev({popup_opts = {border = lvim.lsp.popup_border}})<cr>", "<cmd>lua vim.diagnostic.goto_prev()<cr>",
"Prev Diagnostic", "Prev Diagnostic",
}, },
l = { "<cmd>lua vim.lsp.codelens.run()<cr>", "CodeLens Action" }, l = { "<cmd>lua vim.lsp.codelens.run()<cr>", "CodeLens Action" },
@ -166,7 +166,7 @@ M.config = function()
t = { "<cmd>lua require('lvim.lsp.peek').Peek('typeDefinition')<cr>", "Type Definition" }, t = { "<cmd>lua require('lvim.lsp.peek').Peek('typeDefinition')<cr>", "Type Definition" },
i = { "<cmd>lua require('lvim.lsp.peek').Peek('implementation')<cr>", "Implementation" }, i = { "<cmd>lua require('lvim.lsp.peek').Peek('implementation')<cr>", "Implementation" },
}, },
q = { "<cmd>lua vim.lsp.diagnostic.set_loclist()<cr>", "Quickfix" }, q = { "<cmd>lua vim.diagnostic.setloclist()<cr>", "Quickfix" },
r = { "<cmd>lua vim.lsp.buf.rename()<cr>", "Rename" }, r = { "<cmd>lua vim.lsp.buf.rename()<cr>", "Rename" },
s = { "<cmd>Telescope lsp_document_symbols<cr>", "Document Symbols" }, s = { "<cmd>Telescope lsp_document_symbols<cr>", "Document Symbols" },
S = { S = {

View file

@ -11,126 +11,15 @@ function M.setup()
severity_sort = lvim.lsp.diagnostics.severity_sort, severity_sort = lvim.lsp.diagnostics.severity_sort,
float = lvim.lsp.diagnostics.float, float = lvim.lsp.diagnostics.float,
} }
if vim.fn.has "nvim-0.6" == 1 then vim.diagnostic.config(config)
vim.diagnostic.config(config)
else
vim.lsp.handlers["textDocument/publishDiagnostics"] = function(_, _, params, client_id, _)
local uri = params.uri
local bufnr = vim.uri_to_bufnr(uri)
if not bufnr then
return
end
local diagnostics = params.diagnostics
vim.lsp.diagnostic.save(diagnostics, bufnr, client_id)
if not vim.api.nvim_buf_is_loaded(bufnr) then
return
end
vim.lsp.diagnostic.display(diagnostics, bufnr, client_id, config)
end
end
vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, lvim.lsp.float) 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) vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, lvim.lsp.float)
end end
function M.show_line_diagnostics() function M.show_line_diagnostics()
if vim.fn.has "nvim-0.6" == 1 then local config = lvim.lsp.diagnostics.float
return vim.diagnostic.open_float(0, { scope = "line" }) config.scope = "line"
end return vim.diagnostic.open_float(0, config)
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",
"LspDiagnosticsFloatingWarning",
"LspDiagnosticsFloatingInformation",
"LspDiagnosticsFloatingHint",
}
local ok, vim_diag = pcall(require, "vim.diagnostic")
if ok then
local buf_id = vim.api.nvim_win_get_buf(0)
local win_id = vim.api.nvim_get_current_win()
local cursor_position = vim.api.nvim_win_get_cursor(win_id)
severity_highlight = {
"DiagnosticFloatingError",
"DiagnosticFloatingWarn",
"DiagnosticFloatingInfo",
"DiagnosticFloatingHint",
}
diagnostics = vim_diag.get(buf_id, { lnum = cursor_position[1] - 1 })
end
local lines = {}
local max_width = vim.fn.winwidth(0) - 5
local height = #diagnostics
local width = 0
local opts = {}
local close_events = { "CursorMoved", "CursorMovedI", "BufHidden", "InsertCharPre" }
if height == 0 then
return
end
local bufnr = vim.api.nvim_create_buf(false, true)
local diag_message
table.sort(diagnostics, function(a, b)
return a.severity < b.severity
end)
local hash = {}
local diagnostics_no_dupes = {}
for _, v in ipairs(diagnostics) do
if not hash[v["message"]] then
diagnostics_no_dupes[#diagnostics_no_dupes + 1] = v -- you could print here instead of saving to result table if you wanted
hash[v["message"]] = true
end
end
-- print(vim.inspect(diagnostics_no_dupes))
for i, diagnostic in ipairs(diagnostics_no_dupes) do
local source = diagnostic.source
diag_message = diagnostic.message:gsub("[\n\r]", " ")
if source then
if string.find(source, "/") then
source = string.sub(diagnostic.source, string.find(diagnostic.source, "([%w-_]+)$"))
end
diag_message = string.format("%d. %s: %s", i, source, diag_message)
else
diag_message = string.format("%d. %s", i, diag_message)
end
if diagnostic.code then
diag_message = string.format("%s [%s]", diag_message, diagnostic.code)
end
local msgs = split_by_chunk(diag_message, max_width)
for _, diag in ipairs(msgs) do
table.insert(lines, { message = diag, severity = diagnostic.severity })
width = math.max(diag:len(), width)
end
end
height = #lines
opts = vim.lsp.util.make_floating_popup_options(width, height, opts)
opts["style"] = "minimal"
opts["border"] = "rounded"
opts["focusable"] = true
vim.api.nvim_buf_set_option(bufnr, "bufhidden", "wipe")
local winnr = vim.api.nvim_open_win(bufnr, false, opts)
vim.api.nvim_win_set_option(winnr, "winblend", 0)
vim.api.nvim_buf_set_var(bufnr, "lsp_floating_window", winnr)
for i, diag in ipairs(lines) do
vim.api.nvim_buf_set_lines(bufnr, i - 1, i - 1, 0, { diag.message })
vim.api.nvim_buf_add_highlight(bufnr, -1, severity_highlight[diag.severity], i - 1, 0, diag.message:len())
end
vim.api.nvim_command(
"autocmd QuitPre <buffer> ++nested ++once lua pcall(vim.api.nvim_win_close, " .. winnr .. ", true)"
)
vim.lsp.util.close_preview_autocmd(close_events, winnr)
end end
return M return M

View file

@ -9,14 +9,8 @@ function M:setup()
return return
end end
null_ls.config(lvim.lsp.null_ls.config)
local default_opts = require("lvim.lsp").get_common_opts() local default_opts = require("lvim.lsp").get_common_opts()
null_ls.setup(vim.tbl_deep_extend("force", default_opts, lvim.lsp.null_ls.setup))
if vim.tbl_isempty(lvim.lsp.null_ls.setup or {}) then
lvim.lsp.null_ls.setup = default_opts
end
require("lspconfig")["null-ls"].setup(lvim.lsp.null_ls.setup)
end end
return M return M

View file

@ -1,35 +1,35 @@
local commit = { local commit = {
barbar = "6e638309efcad2f308eb9c5eaccf6f62b794bbab", barbar = "6e638309efcad2f308eb9c5eaccf6f62b794bbab",
cmp_buffer = "a0fe52489ff6e235d62407f8fa72aef80222040a", cmp_buffer = "e26cdfb26f645cd4c6330b541b7e74ff69daa483",
cmp_luasnip = "7bd2612533db6863381193df83f9934b373b21e1", cmp_luasnip = "7bd2612533db6863381193df83f9934b373b21e1",
cmp_nvim_lsp = "134117299ff9e34adde30a735cd8ca9cf8f3db81", cmp_nvim_lsp = "134117299ff9e34adde30a735cd8ca9cf8f3db81",
cmp_nvim_lua = "d276254e7198ab7d00f117e88e223b4bd8c02d21", cmp_nvim_lua = "d276254e7198ab7d00f117e88e223b4bd8c02d21",
cmp_path = "d83839ae510d18530c6d36b662a9e806d4dceb73", cmp_path = "81d88dfcafe26cc0cc856fc66f4677b20e6a9ffc",
comment = "eb0a84a2ea42858a2bb3cdf5fabe54e7c700555d", comment = "9e80d5146013275277238c89bbcaf4164f4e5140",
dapinstall = "dd09e9dd3a6e29f02ac171515b8a089fb82bb425", dapinstall = "dd09e9dd3a6e29f02ac171515b8a089fb82bb425",
fixcursorhold = "0e4e22d21975da60b0fd2d302285b3b603f9f71e", fixcursorhold = "0e4e22d21975da60b0fd2d302285b3b603f9f71e",
friendly_snippets = "4bd6974bd3fcf036a29810bf0570acea55cecfb6", friendly_snippets = "24481f883c980ed8c4c5c08bf8fcdd0fef57c16f",
gitsigns = "a451f97117bd1ede582a6b9db61c387c48d880b6", gitsigns = "a451f97117bd1ede582a6b9db61c387c48d880b6",
lualine = "c4a09735a68c30981c223310848f0649235ec2be", lualine = "a5b3895b57a0ca2e8fec0040afc6cfa81b2a95a4",
luasnip = "21bdf396438b98e12d5cd7c0210804e379babae3", luasnip = "3e4da0cfea0a2f0b4749369bc7ed247c1412a854",
nlsp_settings = "5647a930a0883362b609acb6bfe29cce4202f75d", nlsp_settings = "053495bfc97c9c61bebf740acbbcaeb1ebc0704c",
null_ls = "fb9e2a64ae8e43c2255025064cfee37dc7d6a752", null_ls = "b7de45a0e62bf93f19db2b43ecded48c5763248d",
nvim_autopairs = "04cd1779f81e9d50d5a116c5dccd054b275bd191", nvim_autopairs = "e90e12c789851f2e0a61dd63e4b2e76701a8e2b7",
nvim_cmp = "47d7cfc06abd8661e28dc919882a2fcf01c99729", nvim_cmp = "4a19645374b3c10538bd363e92099d94221efaea",
nvim_dap = "9b8c27d6dcc21b69834fe9c2d344e49030783390", nvim_dap = "a6fa644f9de62c594a8a9cf6f2aaf324b5a6108b",
nvim_lsp_installer = "4d4677739f52b4aeab8909548b37cc88479c315e", nvim_lsp_installer = "81125c9d4c076f55dab58c0ec2e282412767d134",
nvim_lspconfig = "c018b1e92e66b3429a2f167d59211846774f1e3b", nvim_lspconfig = "f84f592816a6b0c55e2a655b56c480683ad92c63",
nvim_notify = "ef027e34b618eac42fb0111c1db670ba01793039", nvim_notify = "243811198d3a937be03535bbe899446f235dda75",
nvim_tree = "f408781a463c2edc3a49091b1bca5a18f790ee3d", nvim_tree = "0aec64d56c9448a039408228d410a01c41125d48",
nvim_treesitter = "7474cb06c2be750eae92da51ff7791deb3b21397", nvim_treesitter = "56634f49ab3d8122153c8c5582c581fb6a6af075",
nvim_ts_context_commentstring = "097df33c9ef5bbd3828105e4bee99965b758dc3f", nvim_ts_context_commentstring = "097df33c9ef5bbd3828105e4bee99965b758dc3f",
nvim_web_devicons = "344331467509802e1af200f08ec3da278be5cbba", nvim_web_devicons = "ac71ca88b1136e1ecb2aefef4948130f31aa40d1",
packer = "851c62c5ecd3b5adc91665feda8f977e104162a5", packer = "851c62c5ecd3b5adc91665feda8f977e104162a5",
plenary = "e6267f79481064eee53950571f53cbaafb08417d", plenary = "a672e11c816d4a91ef01253ba1a2567d20e08e55",
popup = "b7404d35d5d3548a82149238289fa71f7f6de4ac", popup = "b7404d35d5d3548a82149238289fa71f7f6de4ac",
project = "71d0e23dcfc43cfd6bb2a97dc5a7de1ab47a6538", project = "71d0e23dcfc43cfd6bb2a97dc5a7de1ab47a6538",
structlog = "6f1403a192791ff1fa7ac845a73de9e860f781f1", structlog = "6f1403a192791ff1fa7ac845a73de9e860f781f1",
telescope = "80cdb00b221f69348afc4fb4b701f51eb8dd3120", -- see telescope.nvim#1549 telescope = "9aaaa0c5f3eb665b51bbcafda084de4b0952fef0",
telescope_fzf_native = "b8662b076175e75e6497c59f3e2799b879d7b954", telescope_fzf_native = "b8662b076175e75e6497c59f3e2799b879d7b954",
toggleterm = "265bbff68fbb8b2a5fb011272ec469850254ec9f", toggleterm = "265bbff68fbb8b2a5fb011272ec469850254ec9f",
which_key = "0fd9de78fe09215e1b7c6173ff1b0b90c8ed6ec4", which_key = "0fd9de78fe09215e1b7c6173ff1b0b90c8ed6ec4",

View file

@ -73,10 +73,10 @@ _G.load_config = function()
buf_set_keymap("n", "<space>lD", "<cmd>lua vim.lsp.buf.type_definition()<CR>", opts) buf_set_keymap("n", "<space>lD", "<cmd>lua vim.lsp.buf.type_definition()<CR>", opts)
buf_set_keymap("n", "<space>lr", "<cmd>lua vim.lsp.buf.rename()<CR>", opts) buf_set_keymap("n", "<space>lr", "<cmd>lua vim.lsp.buf.rename()<CR>", opts)
buf_set_keymap("n", "gr", "<cmd>lua vim.lsp.buf.references()<CR>", opts) buf_set_keymap("n", "gr", "<cmd>lua vim.lsp.buf.references()<CR>", opts)
buf_set_keymap("n", "gl", "<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>", opts) buf_set_keymap("n", "gl", "<cmd>lua vim.diagnostic.open_float(0,{scope='line'})<CR>", opts)
buf_set_keymap("n", "<space>lk", "<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>", opts) buf_set_keymap("n", "<space>lk", "<cmd>lua vim.diagnostic.goto_prev()<CR>", opts)
buf_set_keymap("n", "<space>lj", "<cmd>lua vim.lsp.diagnostic.goto_next()<CR>", opts) buf_set_keymap("n", "<space>lj", "<cmd>lua vim.diagnostic.goto_next()<CR>", opts)
buf_set_keymap("n", "<space>lq", "<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>", opts) buf_set_keymap("n", "<space>lq", "<cmd>lua vim.diagnostic.setloclist()<CR>", opts)
buf_set_keymap("n", "<space>li", "<cmd>LspInfo<CR>", opts) buf_set_keymap("n", "<space>li", "<cmd>LspInfo<CR>", opts)
buf_set_keymap("n", "<space>lI", "<cmd>LspInstallInfo<CR>", opts) buf_set_keymap("n", "<space>lI", "<cmd>LspInstallInfo<CR>", opts)
end end

View file

@ -100,9 +100,7 @@ lvim.builtin.treesitter.highlight.enabled = true
-- buf_set_option("omnifunc", "v:lua.vim.lsp.omnifunc") -- buf_set_option("omnifunc", "v:lua.vim.lsp.omnifunc")
-- end -- end
-- you can overwrite the null_ls setup table (useful for setting the root_dir function) -- you can overwrite the null_ls setup table (useful for setting the root_dir function)
-- lvim.lsp.null_ls.setup = { -- lvim.lsp.null_ls.setup.root_dir = require("lspconfig").util.root_pattern("Makefile", ".git", "node_modules")
-- root_dir = require("lspconfig").util.root_pattern("Makefile", ".git", "node_modules"),
-- }
-- or if you need something more advanced -- or if you need something more advanced
-- lvim.lsp.null_ls.setup.root_dir = function(fname) -- lvim.lsp.null_ls.setup.root_dir = function(fname)
-- if vim.bo.filetype == "javascript" then -- if vim.bo.filetype == "javascript" then

View file

@ -171,12 +171,11 @@ function print_missing_dep_msg() {
} }
function check_neovim_min_version() { function check_neovim_min_version() {
# TODO: consider locking the requirement to 0.6+ local verify_version_cmd='if !has("nvim-0.6.0") | cquit | else | quit | endif'
local verify_version_cmd='if !has("nvim-0.5.1") | cquit | else | quit | endif'
# exit with an error if min_version not found # exit with an error if min_version not found
if ! nvim --headless -u NONE -c "$verify_version_cmd"; then if ! nvim --headless -u NONE -c "$verify_version_cmd"; then
echo "[ERROR]: LunarVim requires at least Neovim v0.5.1 or higher" echo "[ERROR]: LunarVim requires at least Neovim v0.6.0 or higher"
exit 1 exit 1
fi fi
} }