diff --git a/after/lsp/rust_analyzer.lua b/after/lsp/rust_analyzer.lua new file mode 100644 index 0000000..042de44 --- /dev/null +++ b/after/lsp/rust_analyzer.lua @@ -0,0 +1,13 @@ +-- Rust Analyzer +-- https://rust-analyzer.github.io/book/index.html +-- https://rust-analyzer.github.io/book/configuration.html + +---@type vim.lsp.Config +return { + ---@type lspconfig.settings.rust_analyzer + settings = { + ["rust-analyzer"] = { + lens = { location = "above_whole_item" }, + }, + }, +} 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/lazy-lock.json b/lazy-lock.json index 490facb..4148aae 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -4,7 +4,7 @@ "blink.cmp": { "branch": "main", "commit": "78336bc89ee5365633bcf754d93df01678b5c08f" }, "conform.nvim": { "branch": "master", "commit": "016802de402556da54c36bd7359b441266b01cdd" }, "diffview.nvim": { "branch": "main", "commit": "4516612fe98ff56ae0415a259ff6361a89419b0a" }, - "flash.nvim": { "branch": "main", "commit": "b6346946d10d07998efee029fb0f7a593806d0cd" }, + "flash.nvim": { "branch": "main", "commit": "5f0f270fdc7c5b0c21d903ee85b9cb06f2ac636a" }, "haskell-tools.nvim": { "branch": "master", "commit": "d223712c767011350ed887c3152da4955d9b1457" }, "kanagawa.nvim": { "branch": "master", "commit": "bb85e4bfc8d89b0e62c8fa53ccdd13d12e2f77b3" }, "lazy.nvim": { "branch": "main", "commit": "306a05526ada86a7b30af95c5cc81ffba93fef97" }, @@ -14,15 +14,14 @@ "mini.align": { "branch": "main", "commit": "77d7446b9f2452193f13ced9fb73a8b3aa4a4f4d" }, "mini.icons": { "branch": "main", "commit": "98faae31e9be1cc054ae63485e58ceb185efcad0" }, "mini.surround": { "branch": "main", "commit": "8d5d0c5aa92449368ac251e85451d79d8f69d296" }, - "neogit": { "branch": "master", "commit": "e43a7e83158fc98cd41b732dcb5e1721abb9f164" }, + "neogit": { "branch": "master", "commit": "5adc81b26232954cd7a90f158aa7844c18fc3165" }, "nvim-ansible": { "branch": "main", "commit": "c7f595d568b588942d4d0c37b5cd6cae3764a148" }, - "nvim-autopairs": { "branch": "master", "commit": "7b9923abad60b903ece7c52940e1321d39eccc79" }, + "nvim-autopairs": { "branch": "master", "commit": "430522f95fe4fb7c511ec64f8c1a90cc6a66c05c" }, "nvim-lint": { "branch": "master", "commit": "0370fe965697aa8f04252a1562441bdc13723cd1" }, - "nvim-lspconfig": { "branch": "master", "commit": "bff1bd61cb1455040533201ca1edf1e84efa578f" }, + "nvim-lspconfig": { "branch": "master", "commit": "221c43884319e791519f0d6c94a7f2fbcd653278" }, "nvim-treesitter": { "branch": "main", "commit": "ecdae44baefeffceade8b0c752d80ececad28e76" }, "nvim-treesitter-textobjects": { "branch": "main", "commit": "898ee307df58f854d11cd7edd06472574d48014e" }, "oil.nvim": { "branch": "master", "commit": "b73018b75affd13fa38e2fc94ef753b465f770d7" }, - "plenary.nvim": { "branch": "master", "commit": "74b06c6c75e4eeb3108ec01852001636d85a932b" }, "snacks.nvim": { "branch": "main", "commit": "882c996cf28183f4d63640de0b4c02ec886d01f2" }, "vim-matchup": { "branch": "master", "commit": "5e3c4a3274a9766aee520caebb52572c007fc4f8" }, "which-key.nvim": { "branch": "main", "commit": "3aab2147e74890957785941f0c1ad87d0a44c15a" } 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/git.lua b/lua/peter/plugins/core/git.lua index fe96984..39956aa 100644 --- a/lua/peter/plugins/core/git.lua +++ b/lua/peter/plugins/core/git.lua @@ -12,7 +12,6 @@ return { { "NeogitOrg/neogit", dependencies = { - "nvim-lua/plenary.nvim", "sindrets/diffview.nvim", "nvim-mini/mini.icons", }, 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", })