Now using v0.7+ API functions in many places

This preserves backwards compatibility still, but that will be removed at
some point when dropping .6. At that point, another refactor can
simplify many of the functions used.
This commit is contained in:
ViViDboarder 2023-06-09 12:10:55 -07:00
parent 03df97c0d2
commit 92550be390
2 changed files with 3 additions and 98 deletions

View File

@ -194,17 +194,9 @@ use({
end, end,
}) })
-- Custom status line
use({
"SmiteshP/nvim-gps",
requires = "nvim-treesitter/nvim-treesitter",
disable = vim.fn.has("nvim-0.7.0") == 1,
})
-- Replaces gps for 0.7+
use({ use({
"SmiteshP/nvim-navic", "SmiteshP/nvim-navic",
requires = "neovim/nvim-lspconfig", requires = "neovim/nvim-lspconfig",
disable = vim.fn.has("nvim-0.7.0") ~= 1,
}) })
use({ use({
@ -212,7 +204,7 @@ use({
config = function() config = function()
require("plugins.lualine").config_lualine() require("plugins.lualine").config_lualine()
end, end,
after = vim.fn.has("nvim-0.7.0") == 1 and "nvim-navic" or "nvim-gps", after = "nvim-navic",
}) })
-- On Mac, update colors when dark mode changes -- On Mac, update colors when dark mode changes
@ -253,8 +245,6 @@ use({
"neovim/nvim-lspconfig", "neovim/nvim-lspconfig",
"williamboman/mason-lspconfig.nvim", "williamboman/mason-lspconfig.nvim",
}, },
-- Only supports >=0.7.0
disable = vim.fn.has("nvim-0.7.0") ~= 1,
}) })
-- Lua dev for vim -- Lua dev for vim
@ -266,7 +256,6 @@ use({
-- Rust analyzer -- Rust analyzer
use({ use({
"simrat39/rust-tools.nvim", "simrat39/rust-tools.nvim",
disable = vim.fn.has("nvim-0.7.0") ~= 1,
}) })
-- Better display of lsp diagnostics -- Better display of lsp diagnostics
@ -296,14 +285,6 @@ use({
branch = utils.map_version_rule({ branch = utils.map_version_rule({
[">=0.8.0"] = utils.nil_val, [">=0.8.0"] = utils.nil_val,
[">=0.7.0"] = "0.7-compat", [">=0.7.0"] = "0.7-compat",
["<0.7.0"] = utils.nil_val, -- use pinned commits
}),
commit = utils.map_version_rule({
[">=0.8.0"] = utils.nil_val,
[">=0.7.0"] = utils.nil_val, -- Use pinned branch
[">=0.6.0"] = "4b403d2d724f48150ded41189ae4866492a8158b",
[">=0.5.1"] = "739a98c12bedaa2430c4a3c08d1d22ad6c16513e",
[">=0.5.0"] = "3e7390735501d0507bf2c2b5c2e7a16f58deeb81",
}), }),
requires = { "nvim-lua/plenary.nvim", "neovim/nvim-lspconfig" }, requires = { "nvim-lua/plenary.nvim", "neovim/nvim-lspconfig" },
}) })
@ -332,8 +313,6 @@ use({
commit = utils.map_version_rule({ commit = utils.map_version_rule({
[">=0.8.0"] = utils.nil_val, [">=0.8.0"] = utils.nil_val,
[">=0.7.0"] = "4cccb6f494eb255b32a290d37c35ca12584c74d0", [">=0.7.0"] = "4cccb6f494eb255b32a290d37c35ca12584c74d0",
[">=0.6.0"] = "bc25a6a5",
[">=0.5.0"] = "a189323454d1215c682c7ad7db3e6739d26339c4",
}), }),
config = function() config = function()
require("utils").require_with_local("plugins.treesitter").setup() require("utils").require_with_local("plugins.treesitter").setup()
@ -352,10 +331,6 @@ use({
use({ use({
"nvim-treesitter/nvim-treesitter-textobjects", "nvim-treesitter/nvim-treesitter-textobjects",
requires = "nvim-treesitter/nvim-treesitter", requires = "nvim-treesitter/nvim-treesitter",
commit = utils.map_version_rule({
[">=0.7.0"] = utils.nil_val,
["<0.7.0"] = "eca3bf30334f85259d41dc060d50994f8f91ef7d",
}),
}) })
-- Completion -- Completion
@ -369,28 +344,16 @@ use({
config = function() config = function()
require("plugins.completion").config_cmp() require("plugins.completion").config_cmp()
end, end,
commit = utils.map_version_rule({
[">=0.7.0"] = utils.nil_val,
[">=0.5.0"] = "bba6fb67fdafc0af7c5454058dfbabc2182741f4",
}),
requires = { requires = {
{ {
"hrsh7th/cmp-nvim-lsp", "hrsh7th/cmp-nvim-lsp",
after = "nvim-cmp", after = "nvim-cmp",
commit = utils.map_version_rule({
[">=0.7.0"] = utils.nil_val,
["<0.7.0"] = "3cf38d9c957e95c397b66f91967758b31be4abe6",
}),
}, },
{ "hrsh7th/cmp-buffer", after = "nvim-cmp" }, { "hrsh7th/cmp-buffer", after = "nvim-cmp" },
{ "f3fora/cmp-spell", after = "nvim-cmp" }, { "f3fora/cmp-spell", after = "nvim-cmp" },
{ {
"saadparwaiz1/cmp_luasnip", "saadparwaiz1/cmp_luasnip",
after = "nvim-cmp", after = "nvim-cmp",
commit = utils.map_version_rule({
[">0.7.0"] = utils.nil_val,
[">=0.5.0"] = "b10829736542e7cc9291e60bab134df1273165c9",
}),
}, },
"L3MON4D3/LuaSnip", "L3MON4D3/LuaSnip",
}, },
@ -430,10 +393,7 @@ use({
}, },
tag = utils.map_version_rule({ tag = utils.map_version_rule({
-- Follow stable release tag -- Follow stable release tag
[">=0.7.0"] = "0.1.0", [">=0.7.0"] = "0.1.*",
[">=0.6.0"] = "nvim-0.6",
["<0.6.0"] = "nvim-0.5.1",
["==0.5.0"] = "nvim-0.5.0",
}), }),
config = function() config = function()
require("plugins.telescope") require("plugins.telescope")

View File

@ -5,23 +5,6 @@ function M.get_color(synID, what, mode)
return vim.fn.synIDattr(vim.fn.synIDtrans(vim.fn.hlID(synID)), what, mode) return vim.fn.synIDattr(vim.fn.synIDtrans(vim.fn.hlID(synID)), what, mode)
end end
-- Create an autocmd
-- TODO: Remove this and use nvim_create_autocmd and nvim_create_augroup when dropping .6
function M.autocmd(group, cmds, clear)
clear = clear == nil and false or clear
if type(cmds) == "string" then
cmds = { cmds }
end
vim.cmd("augroup " .. group)
if clear then
vim.cmd([[au!]])
end
for _, cmd in ipairs(cmds) do
vim.cmd("autocmd " .. cmd)
end
vim.cmd([[augroup END]])
end
-- Terminal escape a given string -- Terminal escape a given string
function M.t(str) function M.t(str)
return vim.api.nvim_replace_termcodes(str, true, true, true) return vim.api.nvim_replace_termcodes(str, true, true, true)
@ -195,38 +178,13 @@ end
-- Calls keymap_set with preferred defaults -- Calls keymap_set with preferred defaults
function M.keymap_set(mode, lhs, rhs, opts) function M.keymap_set(mode, lhs, rhs, opts)
opts = vim.tbl_extend("keep", opts, { noremap = true, silent = true }) opts = vim.tbl_extend("keep", opts, { noremap = true, silent = true })
-- TODO: Remove this check when dropping 0.6 support
if vim.fn.has("nvim-0.7") == 1 then
vim.keymap.set(mode, lhs, rhs, opts) vim.keymap.set(mode, lhs, rhs, opts)
else
-- Desc is not supported in 0.6
opts["desc"] = nil
if type(mode) ~= "string" then
for _, m in pairs(mode) do
M.keymap_set(m, lhs, rhs, opts)
end
return
end
-- Buffer requires a different function
local buffer = M.tbl_pop(opts, "buffer")
if buffer == nil then
vim.api.nvim_set_keymap(mode, lhs, rhs, opts)
else
vim.api.nvim_buf_set_keymap(buffer, mode, lhs, rhs, opts)
end
end
end end
-- Returns a curried function for passing data into vim.keymap.set -- Returns a curried function for passing data into vim.keymap.set
function M.curry_keymap(mode, prefix, default_opts) function M.curry_keymap(mode, prefix, default_opts)
default_opts = vim.tbl_extend("keep", default_opts or {}, { noremap = true, silent = true }) default_opts = vim.tbl_extend("keep", default_opts or {}, { noremap = true, silent = true })
-- TODO: Remove when dropping 0.6
if vim.fn.has("nvim-0.7") ~= 1 then
-- NOTE: This is incompatible with a lua function on rhs and a bool buffer instead of number
return M.keymap_group(mode, prefix, default_opts)
end
return function(lhs, rhs, opts) return function(lhs, rhs, opts)
opts = vim.tbl_extend("keep", opts or {}, default_opts) opts = vim.tbl_extend("keep", opts or {}, default_opts)
local opt_mode = M.tbl_pop(opts, "mode") local opt_mode = M.tbl_pop(opts, "mode")
@ -234,19 +192,6 @@ function M.curry_keymap(mode, prefix, default_opts)
end end
end end
-- Returns a function used to create keymaps with consistent prefixes
function M.keymap_group(mode, prefix, default_opts)
-- TODO: Remove when dropping 0.6 since curry_keymap exists
return function(lhs, rhs, opts)
opts = opts or default_opts
if opts ~= nil and default_opts ~= nil and opts ~= default_opts then
opts = vim.tbl_extend("keep", opts, default_opts)
end
local opt_mode = M.tbl_pop(opts, "mode")
M.keymap_set(opt_mode or mode, prefix .. lhs, rhs, opts)
end
end
-- Diagnostics signs -- Diagnostics signs
M.diagnostic_signs = { M.diagnostic_signs = {
Error = "🔥", Error = "🔥",