mirror of
https://github.com/neovim/neovim.git
synced 2026-11-06 13:26:57 +00:00
Problem: Argument type mismatches are excluded from EmmyLua checks. Solution: Correct runtime annotations and calls, document local checker workarounds, and enable the diagnostic. AI-assisted
80 lines
2.6 KiB
Lua
80 lines
2.6 KiB
Lua
-- Highlighting
|
|
local ns = vim.api.nvim_create_namespace('nvim.pack.confirm')
|
|
vim.api.nvim_buf_clear_namespace(0, ns, 0, -1)
|
|
|
|
local priority = 100
|
|
|
|
--- @param lnum integer
|
|
--- @param start_col integer
|
|
--- @param end_col integer
|
|
--- @param hl string?
|
|
--- @param pr? integer
|
|
local function hi_range(lnum, start_col, end_col, hl, pr)
|
|
vim.api.nvim_buf_set_extmark(0, ns, lnum - 1, start_col, {
|
|
end_row = lnum - 1,
|
|
end_col = end_col,
|
|
hl_group = hl,
|
|
priority = pr or priority,
|
|
-- Set expanding gravity for easier testing. Should not make big difference.
|
|
right_gravity = false,
|
|
end_right_gravity = true,
|
|
})
|
|
end
|
|
|
|
local header_hl_groups =
|
|
{ Error = 'DiagnosticError', Update = 'DiagnosticWarn', Same = 'DiagnosticHint' }
|
|
local cur_header_hl_group --- @type string?
|
|
|
|
local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false)
|
|
for i, l in ipairs(lines) do
|
|
local cur_group = l:match('^# (%S+)')
|
|
local cur_info = l:match('^Path: +') or l:match('^Source: +') or l:match('^Revision[^:]*: +')
|
|
if cur_group ~= nil then
|
|
--- @cast cur_group string
|
|
-- Header 1
|
|
cur_header_hl_group = header_hl_groups[cur_group]
|
|
hi_range(i, 0, l:len(), cur_header_hl_group)
|
|
elseif l:find('^## (.+)$') ~= nil then
|
|
-- Header 2 with possibly "(not active)" suffix
|
|
hi_range(i, 0, l:len(), cur_header_hl_group)
|
|
local col = (l:match('() %(not active%)$') or l:len()) --[[@as integer]]
|
|
hi_range(i, col, l:len(), 'DiagnosticError', priority + 1)
|
|
elseif cur_info ~= nil then
|
|
-- Plugin info
|
|
local end_col = (l:match('(). +%b()$') or l:len()) --[[@as integer]]
|
|
hi_range(i, cur_info:len(), end_col, 'DiagnosticInfo')
|
|
|
|
-- Plugin version after update
|
|
local col = l:match('() %b()$') --[[@as integer?]]
|
|
if col then
|
|
hi_range(i, col, l:len(), 'DiagnosticHint')
|
|
end
|
|
elseif l:match('^> ') then
|
|
-- Added change with possibly "breaking message"
|
|
hi_range(i, 0, l:len(), 'Added')
|
|
local col = (l:match('│() %S+!:') or l:match('│() %S+%b()!:') or l:len()) --[[@as integer]]
|
|
hi_range(i, col, l:len(), 'DiagnosticWarn', priority + 1)
|
|
elseif l:match('^< ') then
|
|
-- Removed change
|
|
hi_range(i, 0, l:len(), 'Removed')
|
|
elseif l:match('^• ') then
|
|
-- Available newer tags
|
|
hi_range(i, 4, l:len(), 'DiagnosticHint')
|
|
end
|
|
end
|
|
|
|
--- Mappings
|
|
--- @param lhs string
|
|
--- @param search_flags string
|
|
--- @param desc string
|
|
local function map_section_jump(lhs, search_flags, desc)
|
|
vim.keymap.set({ 'n', 'x' }, lhs, function()
|
|
for _ = 1, vim.v.count1 do
|
|
vim.fn.search('^## ', search_flags)
|
|
end
|
|
end, { buf = 0, desc = desc })
|
|
end
|
|
|
|
map_section_jump('[[', 'bsW', 'Previous plugin')
|
|
map_section_jump(']]', 'sW', 'Next plugin')
|