diff --git a/neovim/lua/_colors.lua b/neovim/lua/_colors.lua index 57436bf..50c0db1 100644 --- a/neovim/lua/_colors.lua +++ b/neovim/lua/_colors.lua @@ -1,3 +1,9 @@ +-- TODO: Don't add these if it's already set +vim.cmd([[ + :highlight link LspReferenceRead MatchParen + :highlight link LspReferenceText MatchParen + :highlight link LspReferenceWrite MatchParen +]]) -- Update colors based on environment variables function _G.update_colors() local function maybe_set(scope, name, val, force) @@ -61,16 +67,11 @@ end -- Don't need the autocommand when dark-notify is installed local utils = require("utils") 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" }, { - pattern = "*", - callback = _G.update_colors, - group = vim.api.nvim_create_augroup("auto_colors", { clear = true }), - }) - else - utils.autocmd("auto_colors", "FocusGained * call v:lua.update_colors()") - end + vim.api.nvim_create_autocmd({ "FocusGained" }, { + pattern = "*", + callback = _G.update_colors, + group = vim.api.nvim_create_augroup("auto_colors", { clear = true }), + }) end -- Initial setting of colors diff --git a/neovim/lua/init.lua b/neovim/lua/init.lua index 5cbb876..817acbc 100644 --- a/neovim/lua/init.lua +++ b/neovim/lua/init.lua @@ -1,3 +1,7 @@ +if vim.fn.has("nvim-0.7.0") ~= 1 then + print("ERROR: Requires nvim >= 0.7.0") +end + local o = vim.o -- Helpers diff --git a/neovim/lua/plugins/lsp.lua b/neovim/lua/plugins/lsp.lua index 79a8f46..b0fbe32 100644 --- a/neovim/lua/plugins/lsp.lua +++ b/neovim/lua/plugins/lsp.lua @@ -92,32 +92,53 @@ local function get_default_attach(override_capabilities) -- Mappings -- TODO: use functions instead of strings when dropping 0.6 local lsp_keymap = utils.curry_keymap("n", "l", { buffer = bufnr }) - lsp_keymap("h", "lua vim.lsp.buf.hover()", { desc = "Display hover" }) - lsp_keymap("rn", "lua vim.lsp.buf.rename()", { desc = "Refactor rename" }) - lsp_keymap("e", "lua vim.diagnostic.open_float()", { desc = "Open float dialog" }) - lsp_keymap("D", "lua vim.lsp.buf.declaration()", { desc = "Go to declaration" }) - lsp_keymap("d", "lua vim.lsp.buf.definition()", { desc = "Go to definition" }) - lsp_keymap("t", "lua vim.lsp.buf.type_definition()", { desc = "Go to type definition" }) - lsp_keymap("i", "lua vim.lsp.buf.implementation()", { desc = "Show implementations" }) - lsp_keymap("s", "lua vim.lsp.buf.signature_help()", { desc = "Show signature help" }) - lsp_keymap("wa", "lua vim.lsp.buf.add_workspace_folder()", { desc = "Workspace: Add folder" }) - lsp_keymap("wr", "lua vim.lsp.buf.remove_workspace_folder()", { desc = "Workspace: Remove folder" }) - lsp_keymap( - "wl", - "lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))", - { desc = "Workspace: List folders" } - ) - lsp_keymap("r", "lua vim.lsp.buf.references()", { desc = "References" }) - lsp_keymap("p", "lua vim.lsp.diagnostic.goto_prev()", { desc = "Diagnostics: Go to previous" }) - lsp_keymap("n", "lua vim.lsp.diagnostic.goto_next()", { desc = "Diagnostics: Go to next" }) + lsp_keymap("h", function() + vim.lsp.buf.hover() + end, { desc = "Display hover" }) + lsp_keymap("rn", function() + vim.lsp.buf.rename() + end, { desc = "Refactor rename" }) + lsp_keymap("e", function() + vim.diagnostic.open_float() + end, { desc = "Open float dialog" }) + lsp_keymap("D", function() + vim.lsp.buf.declaration() + end, { desc = "Go to declaration" }) + lsp_keymap("d", function() + vim.lsp.buf.definition() + end, { desc = "Go to definition" }) + lsp_keymap("t", function() + vim.lsp.buf.type_definition() + end, { desc = "Go to type definition" }) + lsp_keymap("i", function() + vim.lsp.buf.implementation() + end, { desc = "Show implementations" }) + lsp_keymap("s", function() + vim.lsp.buf.signature_help() + end, { desc = "Show signature help" }) + lsp_keymap("wa", function() + vim.lsp.buf.add_workspace_folder() + end, { desc = "Workspace: Add folder" }) + lsp_keymap("wr", function() + vim.lsp.buf.remove_workspace_folder() + end, { desc = "Workspace: Remove folder" }) + lsp_keymap("wl", function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, { desc = "Workspace: List folders" }) + lsp_keymap("r", function() + vim.lsp.buf.references() + end, { desc = "References" }) + lsp_keymap("p", function() + vim.lsp.diagnostic.goto_prev() + end, { desc = "Diagnostics: Go to previous" }) + lsp_keymap("n", function() + vim.lsp.diagnostic.goto_next() + end, { desc = "Diagnostics: Go to next" }) -- Set insert keymap for signature help - utils.keymap_set( - "i", - "", - "lua vim.lsp.buf.signature_help()", - { buffer = bufnr, desc = "Show signature help" } - ) + utils.keymap_set("i", "", function() + vim.lsp.buf.signature_help() + end, { buffer = bufnr, desc = "Show signature help" }) -- Older keymaps --[[ @@ -153,12 +174,12 @@ local function get_default_attach(override_capabilities) -- Set some keybinds conditional on server capabilities if vim.fn.has("nvim-0.8") == 1 then - lsp_keymap("f", "lua vim.lsp.buf.format({async=true})", { desc = "Format code" }) - lsp_keymap( - "f", - "lua vim.lsp.buf.format({async=true})", - { mode = "v", desc = "Format selected code" } - ) + lsp_keymap("f", function() + vim.lsp.buf.format({ async = true }) + end, { desc = "Format code" }) + lsp_keymap("f", function() + vim.lsp.buf.format({ async = true }) + end, { mode = "v", desc = "Format selected code" }) if server_capabilities.documentFormattingProvider then vim.api.nvim_create_autocmd({ "BufWritePre" }, { pattern = { "*.rs", "*.go", "*.sh", "*.lua" }, @@ -171,34 +192,41 @@ local function get_default_attach(override_capabilities) end else -- HACK: Support for <0.8 - lsp_keymap("f", "lua vim.lsp.buf.formatting()", { desc = "Format code" }) - lsp_keymap( - "f", - "lua vim.lsp.buf.range_formatting()", - { mode = "v", desc = "Format selected code" } - ) + lsp_keymap("f", function() + vim.lsp.buf.formatting() + end, { desc = "Format code" }) + lsp_keymap("f", function() + vim.lsp.buf.range_formatting() + end, { mode = "v", desc = "Format selected code" }) if server_capabilities.documentFormattingProvider then - vim.cmd([[ - augroup lsp_format - autocmd! - autocmd BufWritePre lua vim.lsp.buf.formatting_sync(nil, 1000) - augroup END - ]]) + vim.api.nvim_create_autocmd({ "BufWritePre" }, { + pattern = { "*.rs", "*.go", "*.sh", "*.lua" }, + callback = function() + vim.lsp.buf.formatting_sync(nil, 1000) + end, + group = vim.api.nvim_create_augroup("lsp_format", { clear = true }), + desc = "Auto format code on save", + }) end end -- Set autocommands conditional on server_capabilities if server_capabilities.documentHighlightProvider then - vim.cmd([[ - :highlight link LspReferenceRead MatchParen - :highlight link LspReferenceText MatchParen - :highlight link LspReferenceWrite MatchParen - augroup lsp_document_highlight - autocmd! - autocmd CursorHold lua vim.lsp.buf.document_highlight() - autocmd CursorMoved lua vim.lsp.buf.clear_references() - augroup END - ]]) + local lsp_document_highlight = vim.api.nvim_create_augroup("lsp_document_highlight", { clear = true }) + vim.api.nvim_create_autocmd({ "CursorHold" }, { + buffer = bufnr, + callback = function() + vim.lsp.buf.document_highlight() + end, + group = lsp_document_highlight, + }) + vim.api.nvim_create_autocmd({ "CursorMoved" }, { + buffer = bufnr, + callback = function() + vim.lsp.buf.clear_references() + end, + group = lsp_document_highlight, + }) end -- Some override some fuzzy finder bindings to use lsp sources