diff --git a/init.lua b/init.lua index 7393720..fcf0ee1 100644 --- a/init.lua +++ b/init.lua @@ -1,6 +1,6 @@ -if vim.fn.has("nvim-0.11") ~= 1 then +if vim.fn.has("nvim-0.12") ~= 1 then vim.notify_once( - "peter.nvim requires Neovim 0.11 or above. " + "peter.nvim requires Neovim 0.12 or above. " .. "Current version: " .. require("peter.util.version").string() .. ". " @@ -13,3 +13,5 @@ if vim.fn.has("nvim-0.11") ~= 1 then end require("peter.config") + +require("vim._core.ui2").enable() diff --git a/lua/peter/config/keymaps.lua b/lua/peter/config/keymaps.lua index f5eebeb..a620b2a 100644 --- a/lua/peter/config/keymaps.lua +++ b/lua/peter/config/keymaps.lua @@ -68,13 +68,15 @@ set("n", "cd", vim.diagnostic.open_float, { desc = "Line diagnostics" }) do local diagnostic = require("peter.util.diagnostic") local next, prev = diagnostic.next, diagnostic.prev + local ERROR = vim.diagnostic.severity.ERROR + local WARN = vim.diagnostic.severity.ERROR -- stylua: ignore start set("n", "]d", next, { desc = "Next Diagnostic" }) set("n", "[d", prev, { desc = "Prev Diagnostic" }) - set("n", "]e", function() next({ severity = "ERROR" }) end, { desc = "Next Error" }) - set("n", "[e", function() prev({ severity = "ERROR" }) end, { desc = "Prev Error" }) - set("n", "]w", function() next({ severity = "WARN" }) end, { desc = "Next Warning" }) - set("n", "[w", function() prev({ severity = "WARN" }) end, { desc = "Prev Warning" }) + set("n", "]e", function() next({ severity = ERROR }) end, { desc = "Next Error" }) + set("n", "[e", function() prev({ severity = ERROR }) end, { desc = "Prev Error" }) + set("n", "]w", function() next({ severity = WARN }) end, { desc = "Next Warning" }) + set("n", "[w", function() prev({ severity = WARN }) end, { desc = "Prev Warning" }) -- stylua: ignore end end diff --git a/lua/peter/config/lsp.lua b/lua/peter/config/lsp.lua index f5dc8a3..f5f2bbb 100644 --- a/lua/peter/config/lsp.lua +++ b/lua/peter/config/lsp.lua @@ -1,5 +1,4 @@ local lsp = require("peter.util.lsp") -local autocmds = require("peter.util.autocmds") -- Enable LSPs *after* 'mason.nvim' install directory has been added to `PATH`. -- @@ -27,50 +26,52 @@ lsp.on_attach(function(client, bufnr) lsp.try_enable_codelens(client, bufnr) end) -do - -- Store active progress tokens for all running clients. - local active_tokens_by_client = {} - - vim.api.nvim_create_autocmd("LspProgress", { - group = autocmds.augroup("LspProgressCodeLens"), - desc = "Refresh CodeLens whenever the LSP becomes idle", - callback = function(ev) - local client_id = ev.data.client_id - local client = vim.lsp.get_client_by_id(client_id) - - if not client or not client:supports_method("textDocument/codeLens") then - return - end - - local value = ev.data.params.value - local token = ev.data.params.token - - if not (value and token) then - return - end - - -- stylua: ignore - active_tokens_by_client[client_id] = active_tokens_by_client[client_id] or {} - - -- Active tokens for the current client. - local active_tokens = active_tokens_by_client[client_id] - - if value.kind == "begin" then - active_tokens[token] = true - elseif value.kind == "end" then - active_tokens[token] = nil - - -- Check if all tokens are done. - for _, active in pairs(active_tokens) do - if active then - return - end - end - - -- No more progress; the LSP is idle. - active_tokens_by_client[client_id] = nil - vim.lsp.codelens.refresh() - end - end, - }) -end +-- do +-- local autocmds = require("peter.util.autocmds") +-- +-- -- Store active progress tokens for all running clients. +-- local active_tokens_by_client = {} +-- +-- vim.api.nvim_create_autocmd("LspProgress", { +-- group = autocmds.augroup("LspProgressCodeLens"), +-- desc = "Refresh CodeLens whenever the LSP becomes idle", +-- callback = function(ev) +-- local client_id = ev.data.client_id +-- local client = vim.lsp.get_client_by_id(client_id) +-- +-- if not client or not client:supports_method("textDocument/codeLens") then +-- return +-- end +-- +-- local value = ev.data.params.value +-- local token = ev.data.params.token +-- +-- if not (value and token) then +-- return +-- end +-- +-- -- stylua: ignore +-- active_tokens_by_client[client_id] = active_tokens_by_client[client_id] or {} +-- +-- -- Active tokens for the current client. +-- local active_tokens = active_tokens_by_client[client_id] +-- +-- if value.kind == "begin" then +-- active_tokens[token] = true +-- elseif value.kind == "end" then +-- active_tokens[token] = nil +-- +-- -- Check if all tokens are done. +-- for _, active in pairs(active_tokens) do +-- if active then +-- return +-- end +-- end +-- +-- -- No more progress; the LSP is idle. +-- active_tokens_by_client[client_id] = nil +-- vim.lsp.codelens.enable(true) +-- end +-- end, +-- }) +-- end diff --git a/lua/peter/plugins/core/treesitter.lua b/lua/peter/plugins/core/treesitter.lua index 52cda3f..221803c 100644 --- a/lua/peter/plugins/core/treesitter.lua +++ b/lua/peter/plugins/core/treesitter.lua @@ -39,12 +39,11 @@ return { ---@param opts peter.treesitter.Config config = function(_, opts) local nts = require("nvim-treesitter") - local list = require("peter.util.list") local autocmds = require("peter.util.autocmds") nts.setup(opts --[[@as TSConfig]]) - local ensure_installed = list.uniq(opts.ensure_installed or {}) + local ensure_installed = vim.list.unique(opts.ensure_installed or {}) local already_installed = nts.get_installed() diff --git a/lua/peter/plugins/lsp/mason.lua b/lua/peter/plugins/lsp/mason.lua index 7cf9282..445b2aa 100644 --- a/lua/peter/plugins/lsp/mason.lua +++ b/lua/peter/plugins/lsp/mason.lua @@ -41,8 +41,7 @@ return { ---@param opts peter.mason.Opts config = function(_, opts) - local list = require("peter.util.list") - opts.ensure_installed = list.uniq(opts.ensure_installed or {}) + opts.ensure_installed = vim.list.unique(opts.ensure_installed or {}) require("mason").setup(opts --[[@as MasonSettings]]) diff --git a/lua/peter/util/list.lua b/lua/peter/util/list.lua index 698768f..76f3607 100644 --- a/lua/peter/util/list.lua +++ b/lua/peter/util/list.lua @@ -7,21 +7,18 @@ local M = {} -- --[[ ---------------------------------------------------------------------- ]] ----Remove duplicate elements from a list. ----@param list any[] List to remove duplicates from. ----@return any[] new_list List with duplicates removed. -function M.uniq(list) - local hash = {} - local ret = {} - - for _, v in ipairs(list) do - if not hash[v] then - ret[#ret + 1] = v - hash[v] = true - end - end - - return ret +---Removes duplicate values from a list-like table without modifying the original +---table. +--- +---The input table is not modified. A new table is created by this function. +--- +---For in-place deduplication, see `:h vim.list.unique`. +--- +---@generic T +---@param t T[] +---@return T[] t A new, deduplicated list. +function M.uniq_copy(t) + return vim.list.unique(vim.deepcopy(t)) end return M diff --git a/lua/peter/util/lsp.lua b/lua/peter/util/lsp.lua index ef9fb05..6a8bdf3 100644 --- a/lua/peter/util/lsp.lua +++ b/lua/peter/util/lsp.lua @@ -64,18 +64,12 @@ function M.try_enable_inlay_hints(client, bufnr) end ---Enable LSP Codelens for the current buffer if the LSP supports it. ----See `:h vim.lsp.codelens.refresh`. +---See `:h vim.lsp.codelens.enable`. ---@param client vim.lsp.Client ---@param bufnr integer function M.try_enable_codelens(client, bufnr) - local autocmds = require("peter.util.autocmds") if client:supports_method("textDocument/codeLens") then - vim.api.nvim_create_autocmd({ "BufEnter", "InsertLeave", "BufWritePost" }, { - group = autocmds.augroup("RefreshCodeLens"), - desc = "Refresh CodeLens", - buffer = bufnr, - callback = vim.lsp.codelens.refresh, - }) + vim.lsp.codelens.enable(true, { bufnr = bufnr }) end end @@ -89,6 +83,7 @@ function M.delete_global_defaults() del("n", "grn") -- Rename. del("n", "grr") -- References. del("n", "grt") -- Type definition. + del("n", "grx") -- Run codelens. del("n", "gO") -- Document symbols. del("i", "") -- Signature help. @@ -296,7 +291,7 @@ function M.set_default_keymaps(client, bufnr) has = "textDocument/codeLens", }) - map("cC", vim.lsp.codelens.refresh, { + map("cC", function() vim.lsp.codelens.enable(true) end, { desc = "Refresh Codelens", has = "textDocument/codeLens", })