mirror of
https://github.com/neovim/neovim.git
synced 2026-05-03 04:25:03 +00:00
feat(pack): hint in confirmation buffer that plugin is not active
Problem: After `vim.pack.update()` it is not clear if plugin is active or not. This can be useful to detect cases when plugin was removed from 'init.lua' but there was no `vim.pack.del()`. Solution: Add ` (not active)` suffix with distinctive highlighting to header of plugins that are not active. It will also be shown in in-process LSP document symbols to have quick reference about which plugins are not active.
This commit is contained in:
@@ -25,8 +25,10 @@ for i, l in ipairs(lines) do
|
|||||||
cur_header_hl_group = header_hl_groups[cur_group]
|
cur_header_hl_group = header_hl_groups[cur_group]
|
||||||
hi_range(i, 0, l:len(), cur_header_hl_group)
|
hi_range(i, 0, l:len(), cur_header_hl_group)
|
||||||
elseif l:find('^## (.+)$') ~= nil then
|
elseif l:find('^## (.+)$') ~= nil then
|
||||||
-- Header 2
|
-- Header 2 with possibly "(not active)" suffix
|
||||||
hi_range(i, 0, l:len(), cur_header_hl_group)
|
hi_range(i, 0, l:len(), cur_header_hl_group)
|
||||||
|
local col = l:match('() %(not active%)$') or l:len()
|
||||||
|
hi_range(i, col, l:len(), 'DiagnosticError', priority + 1)
|
||||||
elseif cur_info ~= nil then
|
elseif cur_info ~= nil then
|
||||||
-- Plugin info
|
-- Plugin info
|
||||||
local end_col = l:match('(). +%b()$') or l:len()
|
local end_col = l:match('(). +%b()$') or l:len()
|
||||||
|
|||||||
@@ -990,11 +990,12 @@ end
|
|||||||
--- @param p vim.pack.Plug
|
--- @param p vim.pack.Plug
|
||||||
--- @return string
|
--- @return string
|
||||||
local function compute_feedback_lines_single(p)
|
local function compute_feedback_lines_single(p)
|
||||||
|
local active_suffix = active_plugins[p.path] ~= nil and '' or ' (not active)'
|
||||||
if p.info.err ~= '' then
|
if p.info.err ~= '' then
|
||||||
return ('## %s\n\n %s'):format(p.spec.name, p.info.err:gsub('\n', '\n '))
|
return ('## %s%s\n\n %s'):format(p.spec.name, active_suffix, p.info.err:gsub('\n', '\n '))
|
||||||
end
|
end
|
||||||
|
|
||||||
local parts = { '## ' .. p.spec.name .. '\n' }
|
local parts = { ('## %s%s\n'):format(p.spec.name, active_suffix) }
|
||||||
local version_suffix = p.info.version_str == '' and '' or (' (%s)'):format(p.info.version_str)
|
local version_suffix = p.info.version_str == '' and '' or (' (%s)'):format(p.info.version_str)
|
||||||
|
|
||||||
if p.info.sha_head == p.info.sha_target then
|
if p.info.sha_head == p.info.sha_target then
|
||||||
@@ -1127,7 +1128,7 @@ local function get_update_map(bufnr)
|
|||||||
for _, l in ipairs(lines) do
|
for _, l in ipairs(lines) do
|
||||||
local name = l:match('^## (.+)$')
|
local name = l:match('^## (.+)$')
|
||||||
if name and is_in_update then
|
if name and is_in_update then
|
||||||
res[name] = true
|
res[name:gsub(' %(not active%)$', '')] = true
|
||||||
end
|
end
|
||||||
|
|
||||||
local group = l:match('^# (%S+)')
|
local group = l:match('^# (%S+)')
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ local get_plug_data_at_lnum = function(bufnr, lnum)
|
|||||||
if not (from <= lnum and lnum <= to) then
|
if not (from <= lnum and lnum <= to) then
|
||||||
return {}
|
return {}
|
||||||
end
|
end
|
||||||
return { group = group, name = name, from = from, to = to }
|
return { group = group, name = name:gsub(' %(not active%)$', ''), from = from, to = to }
|
||||||
end
|
end
|
||||||
|
|
||||||
--- @alias vim.pack.lsp.Position { line: integer, character: integer }
|
--- @alias vim.pack.lsp.Position { line: integer, character: integer }
|
||||||
|
|||||||
@@ -1622,6 +1622,29 @@ describe('vim.pack', function()
|
|||||||
ref_fetch_lock.rev = git_get_hash('main', 'fetch')
|
ref_fetch_lock.rev = git_get_hash('main', 'fetch')
|
||||||
eq(ref_fetch_lock, get_lock_tbl().plugins.fetch)
|
eq(ref_fetch_lock, get_lock_tbl().plugins.fetch)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('hints about not active plugins', function()
|
||||||
|
exec_lua(function()
|
||||||
|
vim.pack.update()
|
||||||
|
end)
|
||||||
|
|
||||||
|
for _, l in ipairs(api.nvim_buf_get_lines(0, 0, -1, false)) do
|
||||||
|
if l:match('^## ') then
|
||||||
|
matches(' %(not active%)$', l)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Should also hint in `textDocument/documentSymbol` of in-process LSP,
|
||||||
|
-- yet still work for navigation
|
||||||
|
exec_lua('vim.lsp.buf.document_symbol()')
|
||||||
|
local loclist = fn.getloclist(0)
|
||||||
|
matches(' %(not active%)$', loclist[2].text)
|
||||||
|
matches(' %(not active%)$', loclist[4].text)
|
||||||
|
matches(' %(not active%)$', loclist[5].text)
|
||||||
|
|
||||||
|
n.exec('llast')
|
||||||
|
eq(21, api.nvim_win_get_cursor(0)[1])
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('works with not active plugins', function()
|
it('works with not active plugins', function()
|
||||||
|
|||||||
Reference in New Issue
Block a user