Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions init.lua
Original file line number Diff line number Diff line change
@@ -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()
.. ". "
Expand All @@ -13,3 +13,5 @@ if vim.fn.has("nvim-0.11") ~= 1 then
end

require("peter.config")

require("vim._core.ui2").enable()
10 changes: 6 additions & 4 deletions lua/peter/config/keymaps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,15 @@ set("n", "<leader>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
97 changes: 49 additions & 48 deletions lua/peter/config/lsp.lua
Original file line number Diff line number Diff line change
@@ -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`.
--
Expand Down Expand Up @@ -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
3 changes: 1 addition & 2 deletions lua/peter/plugins/core/treesitter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
3 changes: 1 addition & 2 deletions lua/peter/plugins/lsp/mason.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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]])

Expand Down
27 changes: 12 additions & 15 deletions lua/peter/util/list.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 4 additions & 9 deletions lua/peter/util/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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", "<C-s>") -- Signature help.
Expand Down Expand Up @@ -296,7 +291,7 @@ function M.set_default_keymaps(client, bufnr)
has = "textDocument/codeLens",
})

map("<leader>cC", vim.lsp.codelens.refresh, {
map("<leader>cC", function() vim.lsp.codelens.enable(true) end, {
desc = "Refresh Codelens",
has = "textDocument/codeLens",
})
Expand Down
Loading