Refactor to drop 0.6 support

Lightly tested: Finish up refactor

Remove old lspconfig hack

Refactor to avoid deprecated function when not needed
This commit is contained in:
ViViDboarder 2024-05-29 13:16:28 -07:00
parent 4a042358f6
commit 62e83d83f5
13 changed files with 152 additions and 343 deletions

View File

@ -40,31 +40,19 @@ utils.keymap_set("i", "``", "<esc>", { desc = "Escape insert" })
utils.keymap_set("v", "``", "<esc>", { desc = "Escape visual" }) utils.keymap_set("v", "``", "<esc>", { desc = "Escape visual" })
-- C-Space completion -- C-Space completion
function _G.complete_space() utils.keymap_set("i", "<C-Space>", function()
if vim.fn.pumvisible() == 1 then if vim.fn.pumvisible() == 1 then
return utils.t("<C-n>") return utils.t("<C-n>")
elseif utils.is_plugin_loaded("completion-nvim") then
return utils.t("<Plug>(completion_trigger)")
elseif utils.is_plugin_loaded("nvim-compe") then
return vim.fn["compe#complete"]()
elseif utils.is_plugin_loaded("nvim-cmp") then elseif utils.is_plugin_loaded("nvim-cmp") then
return utils.t("<Plug>(cmp_complete)") return utils.t("<Plug>(cmp_complete)")
else else
return utils.t("<C-x><C-o>") return utils.t("<C-x><C-o>")
end end
end end, { expr = true })
utils.keymap_set("i", "<C-Space>", "v:lua.complete_space()", { expr = true })
-- TODO: remove check when dropping v0.6.0
if vim.fn.has("nvim-0.7.0") == 1 then
vim.api.nvim_create_user_command("TagsUpdate", "!ctags -R .", { desc = "Update ctags" }) vim.api.nvim_create_user_command("TagsUpdate", "!ctags -R .", { desc = "Update ctags" })
vim.api.nvim_create_user_command("Todo", "grep TODO", { desc = "Search for TODO tags" }) vim.api.nvim_create_user_command("Todo", "grep TODO", { desc = "Search for TODO tags" })
vim.api.nvim_create_user_command("Spell", "setlocal spell! spelllang=en_us", { desc = "Toggle spelling" }) vim.api.nvim_create_user_command("Spell", "setlocal spell! spelllang=en_us", { desc = "Toggle spelling" })
else
vim.cmd("command! TagsUpdate !ctags -R .")
vim.cmd("command! Todo grep TODO")
vim.cmd("command Spell setlocal spell! spelllang=en_us")
end
-- Pop spelling completion for word under cursor -- Pop spelling completion for word under cursor
utils.keymap_set("n", "<leader>s", "viw<esc>a<c-x>s", { desc = "Show spelling suggestions" }) utils.keymap_set("n", "<leader>s", "viw<esc>a<c-x>s", { desc = "Show spelling suggestions" })

View File

@ -61,16 +61,11 @@ end
-- Don't need the autocommand when dark-notify is installed -- Don't need the autocommand when dark-notify is installed
local utils = require("utils") local utils = require("utils")
if not utils.is_plugin_loaded("dark-notify") then if not utils.is_plugin_loaded("dark-notify") then
-- TODO: remove check when dropping v0.6.0
if vim.fn.has("nvim-0.7.0") == 1 then
vim.api.nvim_create_autocmd({ "FocusGained" }, { vim.api.nvim_create_autocmd({ "FocusGained" }, {
pattern = "*", pattern = "*",
callback = _G.update_colors, callback = _G.update_colors,
group = vim.api.nvim_create_augroup("auto_colors", { clear = true }), group = vim.api.nvim_create_augroup("auto_colors", { clear = true }),
}) })
else
utils.autocmd("auto_colors", "FocusGained * call v:lua.update_colors()")
end
end end
-- Initial setting of colors -- Initial setting of colors

View File

@ -37,16 +37,11 @@ o.mouse = "a"
-- Autocomplete options -- Autocomplete options
o.completeopt = "menuone,noinsert,noselect,preview" o.completeopt = "menuone,noinsert,noselect,preview"
-- TODO: remove check when dropping v0.6.0
if vim.fn.has("nvim-0.7.0") == 1 then
vim.api.nvim_create_autocmd({ "CompleteDone" }, { vim.api.nvim_create_autocmd({ "CompleteDone" }, {
pattern = "*", pattern = "*",
command = "if pumvisible() == 0 | pclose | endif", command = "if pumvisible() == 0 | pclose | endif",
group = vim.api.nvim_create_augroup("close_preview", { clear = true }), group = vim.api.nvim_create_augroup("close_preview", { clear = true }),
}) })
else
utils.autocmd("close_preview", "CompleteDone * if pumvisible() == 0 | pclose | endif", true)
end
local has = vim.fn.has local has = vim.fn.has
g.is_mac = (has("mac") or has("macunix") or has("gui_macvim") or vim.fn.system("uname"):find("^darwin") ~= nil) g.is_mac = (has("mac") or has("macunix") or has("gui_macvim") or vim.fn.system("uname"):find("^darwin") ~= nil)

View File

@ -1,5 +1,5 @@
if vim.fn.has("nvim-0.6.0") ~= 1 then if vim.fn.has("nvim-0.7.0") ~= 1 then
print("ERROR: Requires nvim >= 0.6.0") print("ERROR: Requires nvim >= 0.7.0")
end end
local o = vim.o local o = vim.o
@ -26,4 +26,6 @@ vim.g.polyglot_disabled = { "go", "rust" }
-- Plugins -- Plugins
-- Packer auto installs and then lazy loads itself on PackerCommand and require the plugins module -- Packer auto installs and then lazy loads itself on PackerCommand and require the plugins module
-- This command should only really be needed to bootstrap a new system -- This command should only really be needed to bootstrap a new system
vim.cmd([[command! PackerBootstrap lua require("plugins")]]) vim.api.nvim_create_user_command("PackerBootstrap", function()
require("plugins")
end, { desc = "Bootstrap Packer" })

View File

@ -190,16 +190,9 @@ use({
}) })
-- Custom status line -- Custom status line
use({
"https://github.com/SmiteshP/nvim-gps",
requires = "https://github.com/nvim-treesitter/nvim-treesitter",
disable = vim.fn.has("nvim-0.7.0") == 1,
})
-- Replaces gps for 0.7+
use({ use({
"https://github.com/SmiteshP/nvim-navic", "https://github.com/SmiteshP/nvim-navic",
requires = "https://github.com/neovim/nvim-lspconfig", requires = "https://github.com/neovim/nvim-lspconfig",
disable = vim.fn.has("nvim-0.7.0") ~= 1,
}) })
use({ use({
@ -207,7 +200,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
@ -305,8 +298,6 @@ use({
"https://github.com/neovim/nvim-lspconfig", "https://github.com/neovim/nvim-lspconfig",
"https://github.com/williamboman/mason-lspconfig.nvim", "https://github.com/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
@ -318,7 +309,6 @@ use({
-- Rust analyzer -- Rust analyzer
use({ use({
"https://github.com/simrat39/rust-tools.nvim", "https://github.com/simrat39/rust-tools.nvim",
disable = vim.fn.has("nvim-0.7.0") ~= 1,
}) })
-- Better display of lsp diagnostics -- Better display of lsp diagnostics
@ -388,16 +378,6 @@ use({
require("utils").require_with_local("plugins.treesitter").setup() require("utils").require_with_local("plugins.treesitter").setup()
end, end,
}) })
--[[ TODO: Enable this as an alterantive or fallback for LSPs
use({
"https://github.com/nvim-treesitter/nvim-treesitter-refactor",
requires = "https://github.com/nvim-treesitter/nvim-treesitter",
commit = utils.map_version_rule({
[">=0.7.0"] = utils.nil_val,
["<0.7.0"] = "75f5895",
}),
})
--]]
use({ use({
"https://github.com/nvim-treesitter/nvim-treesitter-textobjects", "https://github.com/nvim-treesitter/nvim-treesitter-textobjects",
requires = "https://github.com/nvim-treesitter/nvim-treesitter", requires = "https://github.com/nvim-treesitter/nvim-treesitter",
@ -497,13 +477,17 @@ use("https://github.com/hsanson/vim-android")
use({ use({
"https://github.com/sheerun/vim-polyglot", "https://github.com/sheerun/vim-polyglot",
config = function() config = function()
-- TODO: Replace with api calls when dropping 0.6 local gid = vim.api.nvim_create_augroup("polyglot_fts", { clear = true })
vim.cmd([[ vim.api.nvim_create_autocmd({ "BufRead", "BufNewFile" }, {
augroup polyglot_fts pattern = { "*/playbooks/*.yml", "*/playbooks/*.yaml" },
au BufRead,BufNewFile */playbooks/*.yml,*/playbooks/*.yaml set filetype=yaml.ansible command = "set filetype=yaml.ansible",
au BufRead,BufNewFile go.mod,go.sum set filetype=gomod group = gid,
augroup end })
]]) vim.api.nvim_create_autocmd({ "BufRead", "BufNewFile" }, {
pattern = { "go.mod", "go.sum" },
command = "set filetype=gomod",
group = gid,
})
end, end,
}) })

View File

@ -48,7 +48,9 @@ function M.config_cmp()
-- Add a plug mapping to use in C-Space binding -- Add a plug mapping to use in C-Space binding
local utils = require("utils") local utils = require("utils")
utils.keymap_set("i", "<Plug>(cmp_complete)", "<cmd>lua require('cmp').complete()<CR>", { desc = "Autocomplete" }) utils.keymap_set("i", "<Plug>(cmp_complete)", function()
require("cmp").complete()
end, { desc = "Autocomplete" })
-- Maybe add obsidian and obsidian new. This is done here in case obsidian.nvim is loaded before cmp -- Maybe add obsidian and obsidian new. This is done here in case obsidian.nvim is loaded before cmp
utils.try_require("cmp_obsidian", function(cmp_obsidian) utils.try_require("cmp_obsidian", function(cmp_obsidian)

View File

@ -16,7 +16,7 @@ function M.setup()
local utils = require("utils") local utils = require("utils")
if utils.try_require("telescope") ~= nil then if utils.try_require("telescope") ~= nil then
local cc_keymap = utils.curry_keymap("n", "<leader>cc") local cc_keymap = utils.curry_keymap("n", "<leader>cc", { group_desc = "CopilotChat" })
cc_keymap("h", function() cc_keymap("h", function()
local actions = require("CopilotChat.actions") local actions = require("CopilotChat.actions")

View File

@ -15,16 +15,9 @@ require("utils").keymap_set({ "n", "x" }, "gs", "<plug>(GrepperOperator)", {
}) })
-- Override Todo command to use Grepper -- Override Todo command to use Grepper
-- TODO: Remove check when dropping 0.6
if vim.fn.has("nvim-0.7.0") == 1 then
vim.api.nvim_create_user_command("Todo", ":Grepper -noprompt -query TODO", { desc = "Search for TODO tags" }) vim.api.nvim_create_user_command("Todo", ":Grepper -noprompt -query TODO", { desc = "Search for TODO tags" })
else
vim.cmd("command! Todo :Grepper -noprompt -query TODO")
end
-- Make some shortands for various grep programs -- Make some shortands for various grep programs
-- TODO: Remove check when dropping 0.6
if vim.fn.has("nvim-0.7.0") == 1 then
if vim.fn.executable("rg") == 1 then if vim.fn.executable("rg") == 1 then
vim.api.nvim_create_user_command("Rg", ":GrepperRg <args>", { nargs = "+", desc = "Ripgrep" }) vim.api.nvim_create_user_command("Rg", ":GrepperRg <args>", { nargs = "+", desc = "Ripgrep" })
end end
@ -34,14 +27,3 @@ if vim.fn.has("nvim-0.7.0") == 1 then
if vim.fn.executable("ack") == 1 then if vim.fn.executable("ack") == 1 then
vim.api.nvim_create_user_command("Ack", ":GrepperAck <args>", { nargs = "+", desc = "Ack search" }) vim.api.nvim_create_user_command("Ack", ":GrepperAck <args>", { nargs = "+", desc = "Ack search" })
end end
else
if vim.fn.executable("rg") == 1 then
vim.cmd("command -nargs=+ Rg :GrepperRg <args>")
end
if vim.fn.executable("ag") == 1 then
vim.cmd("command -nargs=+ Ag :GrepperAg <args>")
end
if vim.fn.executable("ack") == 1 then
vim.cmd("command -nargs=+ Ack :GrepperAck <args>")
end
end

View File

@ -73,107 +73,64 @@ local function get_default_attach(override_capabilities)
server_capabilities = vim.tbl_extend("force", server_capabilities, override_capabilities or {}) server_capabilities = vim.tbl_extend("force", server_capabilities, override_capabilities or {})
end end
local function buf_set_option(...)
vim.api.nvim_buf_set_option(bufnr, ...)
end
-- Set built in features to use lsp functions (automatic in nvim-0.8) -- Set built in features to use lsp functions (automatic in nvim-0.8)
-- HACK: Support for <0.8 -- HACK: Support for <0.8
if vim.fn.has("nvim-0.8") ~= 1 then if vim.fn.has("nvim-0.8") ~= 1 then
buf_set_option("omnifunc", "v:lua.vim.lsp.omnifunc") vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc")
if server_capabilities.documentSymbolProvider then if server_capabilities.documentSymbolProvider then
buf_set_option("tagfunc", "v:lua.vim.lsp.tagfunc") vim.api.nvim_buf_set_option(bufnr, "tagfunc", "v:lua.vim.lsp.tagfunc")
end end
if server_capabilities.documentFormattingProvider then if server_capabilities.documentFormattingProvider then
buf_set_option("formatexpr", "v:lua.vim.lsp.formatexpr()") vim.api.nvim_buf_set_option(bufnr, "formatexpr", "v:lua.vim.lsp.formatexpr()")
end end
end end
-- Mappings -- Mappings
-- TODO: use functions instead of strings when dropping 0.6 local lsp_keymap = utils.curry_keymap("n", "<leader>l", { buffer = bufnr, group_desc = "LSP" })
local lsp_keymap = utils.curry_keymap("n", "<leader>l", { buffer = bufnr }) lsp_keymap("h", vim.lsp.buf.hover, { desc = "Display hover" })
lsp_keymap("h", "<cmd>lua vim.lsp.buf.hover()<CR>", { desc = "Display hover" }) lsp_keymap("rn", vim.lsp.buf.rename, { desc = "Refactor rename" })
lsp_keymap("rn", "<cmd>lua vim.lsp.buf.rename()<CR>", { desc = "Refactor rename" }) lsp_keymap("e", vim.diagnostic.open_float, { desc = "Open float dialog" })
lsp_keymap("e", "<cmd>lua vim.diagnostic.open_float()<CR>", { desc = "Open float dialog" }) lsp_keymap("D", vim.lsp.buf.declaration, { desc = "Go to declaration" })
lsp_keymap("D", "<cmd>lua vim.lsp.buf.declaration()<CR>", { desc = "Go to declaration" }) lsp_keymap("d", vim.lsp.buf.definition, { desc = "Go to definition" })
lsp_keymap("d", "<cmd>lua vim.lsp.buf.definition()<CR>", { desc = "Go to definition" }) lsp_keymap("t", vim.lsp.buf.type_definition, { desc = "Go to type definition" })
lsp_keymap("t", "<cmd>lua vim.lsp.buf.type_definition()<CR>", { desc = "Go to type definition" }) lsp_keymap("i", vim.lsp.buf.implementation, { desc = "Show implementations" })
lsp_keymap("i", "<cmd>lua vim.lsp.buf.implementation()<CR>", { desc = "Show implementations" }) lsp_keymap("s", vim.lsp.buf.signature_help, { desc = "Show signature help" })
lsp_keymap("s", "<cmd>lua vim.lsp.buf.signature_help()<CR>", { desc = "Show signature help" }) lsp_keymap("wa", vim.lsp.buf.add_workspace_folder, { desc = "Workspace: Add folder" })
lsp_keymap("wa", "<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>", { desc = "Workspace: Add folder" }) lsp_keymap("wr", vim.lsp.buf.remove_workspace_folder, { desc = "Workspace: Remove folder" })
lsp_keymap("wr", "<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>", { desc = "Workspace: Remove folder" }) lsp_keymap("wl", function()
lsp_keymap( print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
"wl", end, { desc = "Workspace: List folders" })
"<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>", lsp_keymap("r", vim.lsp.buf.references, { desc = "References" })
{ desc = "Workspace: List folders" } lsp_keymap("p", vim.diagnostic.goto_prev, { desc = "Previous diagnostic" })
) lsp_keymap("n", vim.diagnostic.goto_next, { desc = "Next diagnostic" })
lsp_keymap("r", "<cmd>lua vim.lsp.buf.references()<CR>", { desc = "References" }) if server_capabilities.codeActionProvider then
lsp_keymap("p", "<cmd>lua vim.diagnostic.goto_prev()<CR>", { desc = "Previous diagnostic" }) lsp_keymap("A", vim.lsp.buf.code_action, { desc = "Select code actions" })
lsp_keymap("n", "<cmd>lua vim.diagnostic.goto_next()<CR>", { desc = "Next diagnostic" }) lsp_keymap("A", vim.lsp.buf.code_action, { mode = "v", desc = "Select code actions" })
end
-- Set insert keymap for signature help -- Set insert keymap for signature help
utils.keymap_set( utils.keymap_set("i", "<C-k>", vim.lsp.buf.signature_help, { buffer = bufnr, desc = "Show signature help" })
"i",
"<C-k>",
"<cmd>lua vim.lsp.buf.signature_help()<CR>",
{ buffer = bufnr, desc = "Show signature help" }
)
-- Some top level aliases or remaps -- Some top level aliases or remaps
utils.keymap_set("n", "K", "<cmd>lua vim.lsp.buf.hover()<CR>", { buffer = bufnr, desc = "Display hover" }) utils.keymap_set("n", "K", vim.lsp.buf.hover, { buffer = bufnr, desc = "Display hover" })
utils.keymap_set( utils.keymap_set("n", "gD", vim.lsp.buf.declaration, { buffer = bufnr, desc = "Go to declaration" })
"n", utils.keymap_set("n", "gd", vim.lsp.buf.definition, { buffer = bufnr, desc = "Go to definition" })
"gD", utils.keymap_set("n", "<leader>rn", vim.lsp.buf.rename, { buffer = bufnr, desc = "Refactor rename" })
"<Cmd>lua vim.lsp.buf.declaration()<CR>", utils.keymap_set("n", "[d", vim.diagnostic.goto_prev, { buffer = bufnr, desc = "Previous diagnostic" })
{ buffer = bufnr, desc = "Go to declaration" } utils.keymap_set("n", "]d", vim.diagnostic.goto_next, { buffer = bufnr, desc = "Next diagnostic" })
)
utils.keymap_set(
"n",
"gd",
"<Cmd>lua vim.lsp.buf.definition()<CR>",
{ buffer = bufnr, desc = "Go to definition" }
)
utils.keymap_set(
"n",
"<leader>rn",
"<cmd>lua vim.lsp.buf.rename()<CR>",
{ buffer = bufnr, desc = "Refactor rename" }
)
utils.keymap_set(
"n",
"[d",
"<cmd>lua vim.diagnostic.goto_prev()<CR>",
{ buffer = bufnr, desc = "Previous diagnostic" }
)
utils.keymap_set(
"n",
"]d",
"<cmd>lua vim.diagnostic.goto_next()<CR>",
{ buffer = bufnr, desc = "Next diagnostic" }
)
-- Older keymaps
--[[
buf_set_keymap("n", "gi", "<cmd>lua vim.lsp.buf.implementation()<CR>", opts)
buf_set_keymap("n", "<leader>wa", "<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>", opts)
buf_set_keymap("n", "<leader>wr", "<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>", opts)
buf_set_keymap("n", "<leader>wl", "<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>", opts)
buf_set_keymap("n", "<leader>D", "<cmd>lua vim.lsp.buf.type_definition()<CR>", opts)
buf_set_keymap("n", "<leader>rn", "<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", "<leader>e", "<cmd>lua vim.diagnostic.open_float()<CR>", opts)
buf_set_keymap("n", "<leader>q", "<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>", opts)
--]]
-- Open diagnostic on hold -- Open diagnostic on hold
if vim["diagnostic"] ~= nil then vim.api.nvim_create_autocmd({ "CursorHold" }, {
-- TODO: When dropping 0.6, use lua aucommand api pattern = "<buffer>",
vim.cmd([[autocmd CursorHold * lua vim.diagnostic.open_float(nil, {focus=false, scope="cursor"})]]) callback = function()
end vim.diagnostic.open_float(nil, { focus = false, scope = "cursor" })
end,
group = vim.api.nvim_create_augroup("diagnostic_float", { clear = true }),
desc = "Open float dialog on hold",
})
-- Use IncRename if available -- Use IncRename if available
if utils.try_require("inc_rename") ~= nil then if utils.try_require("inc_rename") ~= nil then
-- TODO: Should I be using this for calling lua functions from keymaps?
vim.keymap.set("n", "<leader>rn", function() vim.keymap.set("n", "<leader>rn", function()
return ":IncRename " .. vim.fn.expand("<cword>") return ":IncRename " .. vim.fn.expand("<cword>")
end, { expr = true, buffer = true, desc = "Rename current symbol" }) end, { expr = true, buffer = true, desc = "Rename current symbol" })
@ -181,12 +138,12 @@ local function get_default_attach(override_capabilities)
-- Set some keybinds conditional on server capabilities -- Set some keybinds conditional on server capabilities
if vim.fn.has("nvim-0.8") == 1 then if vim.fn.has("nvim-0.8") == 1 then
lsp_keymap("f", "<cmd>lua vim.lsp.buf.format({async=true})<CR>", { desc = "Format code" }) lsp_keymap("f", function()
lsp_keymap( vim.lsp.buf.format({ async = true })
"f", end, { desc = "Format code" })
"<cmd>lua vim.lsp.buf.format({async=true})<CR>", lsp_keymap("f", function()
{ mode = "v", desc = "Format selected code" } vim.lsp.buf.format({ async = true })
) end, { mode = "v", desc = "Format selected code" })
if server_capabilities.documentFormattingProvider then if server_capabilities.documentFormattingProvider then
vim.api.nvim_create_autocmd({ "BufWritePre" }, { vim.api.nvim_create_autocmd({ "BufWritePre" }, {
pattern = { "*.rs", "*.go", "*.sh", "*.lua" }, pattern = { "*.rs", "*.go", "*.sh", "*.lua" },
@ -198,60 +155,58 @@ local function get_default_attach(override_capabilities)
}) })
end end
else else
-- HACK: Support for <0.8 -- HACK: Support for <0.8 with older formatting
lsp_keymap("f", "<cmd>lua vim.lsp.buf.formatting()<CR>", { desc = "Format code" }) lsp_keymap("f", vim.lsp.buf.formatting, { desc = "Format code" })
lsp_keymap( lsp_keymap("f", vim.lsp.buf.range_formatting, { mode = "v", desc = "Format selected code" })
"f",
"<cmd>lua vim.lsp.buf.range_formatting()<CR>",
{ mode = "v", desc = "Format selected code" }
)
if server_capabilities.documentFormattingProvider then if server_capabilities.documentFormattingProvider then
vim.cmd([[ vim.api.nvim_create_autocmd({ "BufWritePre" }, {
augroup lsp_format pattern = { "*.rs", "*.go", "*.sh", "*.lua" },
autocmd! callback = function()
autocmd BufWritePre lua vim.lsp.buf.formatting_sync(nil, 1000) vim.lsp.buf.formatting_sync(nil, 1000)
augroup END end,
]]) group = vim.api.nvim_create_augroup("lsp_format", { clear = true }),
desc = "Auto format code on save",
})
end end
end end
-- Set autocommands conditional on server_capabilities -- Set autocommands conditional on server_capabilities
if server_capabilities.documentHighlightProvider then if server_capabilities.documentHighlightProvider then
vim.cmd([[ vim.api.nvim_set_hl(0, "LspReferenceRead", { link = "MatchParen" })
:highlight link LspReferenceRead MatchParen vim.api.nvim_set_hl(0, "LspReferenceText", { link = "MatchParen" })
:highlight link LspReferenceText MatchParen vim.api.nvim_set_hl(0, "LspReferenceWrite", { link = "MatchParen" })
:highlight link LspReferenceWrite MatchParen local hl_group = vim.api.nvim_create_augroup("lsp_document_highlight", { clear = true })
augroup lsp_document_highlight vim.api.nvim_create_autocmd(
autocmd! { "CursorHold" },
autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight() { pattern = "<buffer>", callback = vim.lsp.buf.document_highlight, group = hl_group }
autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references() )
augroup END vim.api.nvim_create_autocmd(
]]) { "CursorMoved" },
{ pattern = "<buffer>", callback = vim.lsp.buf.clear_references, group = hl_group }
)
end end
-- Some override some fuzzy finder bindings to use lsp sources -- Some override some fuzzy finder bindings to use lsp sources
if utils.try_require("telescope") ~= nil then utils.try_require("telescope.builtin", function(telescope_builtin)
-- Replace some Telescope bindings with LSP versions -- Replace some Telescope bindings with LSP versions
local telescope_keymap = utils.curry_keymap("n", "<leader>f", { buffer = bufnr }) local telescope_keymap = utils.curry_keymap("n", "<leader>f", { buffer = bufnr, group_desc = "Finder" })
if server_capabilities.documentSymbolProvider then if server_capabilities.documentSymbolProvider then
telescope_keymap("t", "<cmd>Telescope lsp_document_symbols<CR>", { desc = "Find buffer tags" }) telescope_keymap("t", telescope_builtin.lsp_document_symbols, { desc = "Find buffer tags" })
end end
if server_capabilities.workspaceSymbolProvider then if server_capabilities.workspaceSymbolProvider then
telescope_keymap("T", "<cmd>Telescope lsp_dynamic_workspace_symbols<CR>", { desc = "Find tags" }) telescope_keymap("T", telescope_builtin.lsp_dynamic_workspace_symbols, { desc = "Find tags" })
end end
-- Replace some LSP bindings with Telescope ones -- Replace some LSP bindings with Telescope ones
if server_capabilities.definitionProvider then if server_capabilities.definitionProvider then
lsp_keymap("d", "<cmd>Telescope lsp_definitions<CR>", { desc = "Find definition" }) lsp_keymap("d", telescope_builtin.lsp_definitions, { desc = "Find definition" })
end end
if server_capabilities.typeDefinitionProvider then if server_capabilities.typeDefinitionProvider then
lsp_keymap("t", "<cmd>Telescope lsp_type_definition<CR>", { desc = "Find type definition" }) lsp_keymap("t", telescope_builtin.lsp_type_definitions, { desc = "Find type definition" })
end
lsp_keymap("i", "<cmd>Telescope lsp_implementations<CR>", { desc = "Find implementations" })
lsp_keymap("r", "<cmd>Telescope lsp_references<CR>", { desc = "Find references" })
lsp_keymap("A", "<cmd>Telescope lsp_code_actions<CR>", { desc = "Select code actions" })
lsp_keymap("A", "<cmd>Telescope lsp_range_code_actions<CR>", { mode = "v", desc = "Select code actions" })
end end
lsp_keymap("i", telescope_builtin.lsp_implementations, { desc = "Find implementations" })
lsp_keymap("r", telescope_builtin.lsp_references, { desc = "Find references" })
end)
-- Attach navic for statusline location -- Attach navic for statusline location
if server_capabilities.documentSymbolProvider then if server_capabilities.documentSymbolProvider then
@ -342,13 +297,7 @@ function M.config_lsp()
-- Auto setup mason installed servers -- Auto setup mason installed servers
utils.try_require("mason-lspconfig", function(mason_lspconfig) utils.try_require("mason-lspconfig", function(mason_lspconfig)
-- Get list of servers that are installed but not set up -- Get list of servers that are installed but not set up
local already_setup local already_setup = lsp_config.util.available_servers()
if lsp_config["util"] and lsp_config.util["available_servers"] then
already_setup = lsp_config.util.available_servers()
else
-- HACK: For lspconfig versions lower than 0.1.4, which is required for nvim <0.7.0
already_setup = lsp_config.available_servers()
end
local needs_setup = vim.tbl_filter(function(server) local needs_setup = vim.tbl_filter(function(server)
return not vim.tbl_contains(already_setup, server) return not vim.tbl_contains(already_setup, server)
end, mason_lspconfig.get_installed_servers()) end, mason_lspconfig.get_installed_servers())

View File

@ -56,22 +56,8 @@ function M.config_lualine(theme_name)
theme_name = "wombat" theme_name = "wombat"
end end
-- gps / navic -- navic
local code_loc = {} local code_loc = {}
utils.try_require("nvim-gps", function(gps)
gps.setup({
icons = {
["class-name"] = "(c) ",
["function-name"] = "(ƒ) ",
["method-name"] = "(m) ",
["container-name"] = "",
["tag-name"] = "(t) ",
},
})
code_loc = { gps.get_location, cond = gps.is_available }
end)
utils.try_require("nvim-navic", function(navic) utils.try_require("nvim-navic", function(navic)
navic.setup({ navic.setup({
icons = { icons = {
@ -89,12 +75,6 @@ function M.config_lualine(theme_name)
code_loc = { "navic" } code_loc = { "navic" }
end) end)
local diagnostic_plugin = "nvim_diagnostic"
-- HACK: Support for <0.6
if vim.fn.has("nvim-0.6.0") ~= 1 then
diagnostic_plugin = "nvim_lsp"
end
require("lualine").setup({ require("lualine").setup({
options = { options = {
theme = theme_name, theme = theme_name,
@ -116,7 +96,7 @@ function M.config_lualine(theme_name)
lualine_x = { M.custom_ffenc, "filetype" }, lualine_x = { M.custom_ffenc, "filetype" },
lualine_y = { "progress", "location" }, lualine_y = { "progress", "location" },
lualine_z = { lualine_z = {
{ "diagnostics", sources = { diagnostic_plugin } }, { "diagnostics", sources = { "nvim_diagnostic" } },
{ M.mixed_indent, color = { bg = "#de4f1f" } }, { M.mixed_indent, color = { bg = "#de4f1f" } },
{ M.trailing_whitespace, color = { bg = "#de4f1f" } }, { M.trailing_whitespace, color = { bg = "#de4f1f" } },
}, },

View File

@ -6,12 +6,7 @@ local function disable_formatter_filetypes_for_existing_servers(sources, preserv
local server_filetypes = {} local server_filetypes = {}
utils.try_require("lspconfig", function(lsp_config) utils.try_require("lspconfig", function(lsp_config)
local available_servers local available_servers
if lsp_config["util"] and lsp_config.util["available_servers"] then
available_servers = lsp_config.util.available_servers() available_servers = lsp_config.util.available_servers()
else
-- HACK: For lspconfig versions lower than 0.1.4, which is required for nvim <0.7.0
available_servers = lsp_config.available_servers()
end
vim.tbl_map(function(server) vim.tbl_map(function(server)
if lsp_config[server].filetypes ~= nil then if lsp_config[server].filetypes ~= nil then
vim.list_extend(server_filetypes, lsp_config[server].filetypes) vim.list_extend(server_filetypes, lsp_config[server].filetypes)

View File

@ -22,43 +22,27 @@ local function config_telescope()
}) })
local utils = require("utils") local utils = require("utils")
utils.keymap_set("n", "<C-t>", "<cmd>lua require('telescope.builtin').find_files()<CR>", { desc = "Find files" }) local telescope_builtin = require("telescope.builtin")
utils.keymap_set("n", "<leader>b", "<cmd>lua require('telescope.builtin').buffers()<CR>", { desc = "Find buffers" })
utils.keymap_set(
"n",
"<leader>t",
"<cmd>lua require('telescope.builtin').current_buffer_tags()<CR>",
{ desc = "Find buffer tags" }
)
utils.keymap_set(
"n",
"<leader>*",
"<cmd>lua require('telescope.builtin').grep_string()<CR>",
{ desc = "Find string under cursor" }
)
-- Better spelling replacement for word under cursor
utils.keymap_set(
"n",
"<leader>s",
"<cmd>lua require('telescope.builtin').spell_suggest(require('telescope.themes').get_cursor())<CR>",
{ desc = "Spell check" }
)
local finder_keymap = utils.curry_keymap("n", "<leader>f") utils.keymap_set("n", "<C-t>", telescope_builtin.find_files, { desc = "Find files" })
finder_keymap("b", "<cmd>lua require('telescope.builtin').buffers()<CR>", { desc = "Find buffers" }) utils.keymap_set("n", "<leader>b", telescope_builtin.buffers, { desc = "Find buffers" })
finder_keymap("f", "<cmd>lua require('telescope.builtin').find_files()<CR>", { desc = "Find file" }) utils.keymap_set("n", "<leader>t", telescope_builtin.current_buffer_tags, { desc = "Find buffer tags" })
finder_keymap("g", "<cmd>lua require('telescope.builtin').live_grep()<CR>", { desc = "Live grep" }) utils.keymap_set("n", "<leader>*", telescope_builtin.grep_string, { desc = "Find string under cursor" })
finder_keymap("h", "<cmd>lua require('telescope.builtin').help_tags()<CR>", { desc = "Find help tags" }) utils.keymap_set("n", "<leader>s", function()
finder_keymap("l", "<cmd>lua require('telescope.builtin').resume()<CR>", { desc = "Resume finding" }) require("telescope.builtin").spell_suggest(require("telescope.themes").get_cursor())
finder_keymap("t", "<cmd>lua require('telescope.builtin').current_buffer_tags()<CR>", { desc = "Find buffer tags" }) end, { desc = "Spell check" })
finder_keymap("T", "<cmd>lua require('telescope.builtin').tags()<CR>", { desc = "Find tags" })
local finder_keymap = utils.curry_keymap("n", "<leader>f", { group_desc = "Finder" })
finder_keymap("b", telescope_builtin.buffers, { desc = "Find buffers" })
finder_keymap("f", telescope_builtin.find_files, { desc = "Find file" })
finder_keymap("g", telescope_builtin.live_grep, { desc = "Live grep" })
finder_keymap("h", telescope_builtin.help_tags, { desc = "Find help tags" })
finder_keymap("l", telescope_builtin.resume, { desc = "Resume finding" })
finder_keymap("t", telescope_builtin.current_buffer_tags, { desc = "Find buffer tags" })
finder_keymap("T", telescope_builtin.tags, { desc = "Find tags" })
if utils.can_require("sg.telescope") then if utils.can_require("sg.telescope") then
finder_keymap( finder_keymap("G", require("sg.telescope").fuzzy_search_results, { desc = "Search Sourcegraph" })
"G",
"<cmd>lua require('sg.telescope').fuzzy_search_results()<CR>",
{ desc = "Search Sourcegraph" }
)
end end
load_extensions() load_extensions()

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,36 +178,19 @@ 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 })
local group_desc = M.tbl_pop(default_opts, "group_desc")
-- TODO: Remove when dropping 0.6 if group_desc ~= nil then
if vim.fn.has("nvim-0.7") ~= 1 then M.try_require("which-key", function(wk)
-- NOTE: This is incompatible with a lua function on rhs and a bool buffer instead of number wk.register({
return M.keymap_group(mode, prefix, default_opts) [prefix] = "+" .. group_desc,
}, default_opts)
end)
end end
return function(lhs, rhs, opts) return function(lhs, rhs, opts)
@ -234,19 +200,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 = "🔥",