nvim-pack.lua (2464B)
1 -- Highlighting 2 local ns = vim.api.nvim_create_namespace('nvim.pack.confirm') 3 vim.api.nvim_buf_clear_namespace(0, ns, 0, -1) 4 5 local priority = 100 6 local hi_range = function(lnum, start_col, end_col, hl, pr) 7 --- @type vim.api.keyset.set_extmark 8 local opts = { end_row = lnum - 1, end_col = end_col, hl_group = hl, priority = pr or priority } 9 -- Set expanding gravity for easier testing. Should not make big difference. 10 opts.right_gravity, opts.end_right_gravity = false, true 11 vim.api.nvim_buf_set_extmark(0, ns, lnum - 1, start_col, opts) 12 end 13 14 local header_hl_groups = 15 { Error = 'DiagnosticError', Update = 'DiagnosticWarn', Same = 'DiagnosticHint' } 16 local cur_header_hl_group = nil 17 18 local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false) 19 for i, l in ipairs(lines) do 20 local cur_group = l:match('^# (%S+)') 21 local cur_info = l:match('^Path: +') or l:match('^Source: +') or l:match('^Revision[^:]*: +') 22 if cur_group ~= nil then 23 --- @cast cur_group string 24 -- Header 1 25 cur_header_hl_group = header_hl_groups[cur_group] 26 hi_range(i, 0, l:len(), cur_header_hl_group) 27 elseif l:find('^## (.+)$') ~= nil then 28 -- Header 2 with possibly "(not active)" suffix 29 hi_range(i, 0, l:len(), cur_header_hl_group) 30 local col = l:match('() %(not active%)$') or l:len() 31 hi_range(i, col, l:len(), 'DiagnosticError', priority + 1) 32 elseif cur_info ~= nil then 33 -- Plugin info 34 local end_col = l:match('(). +%b()$') or l:len() 35 hi_range(i, cur_info:len(), end_col, 'DiagnosticInfo') 36 37 -- Plugin version after update 38 local col = l:match('() %b()$') 39 if col then 40 hi_range(i, col, l:len(), 'DiagnosticHint') 41 end 42 elseif l:match('^> ') then 43 -- Added change with possibly "breaking message" 44 hi_range(i, 0, l:len(), 'Added') 45 local col = l:match('│() %S+!:') or l:match('│() %S+%b()!:') or l:len() 46 hi_range(i, col, l:len(), 'DiagnosticWarn', priority + 1) 47 elseif l:match('^< ') then 48 -- Removed change 49 hi_range(i, 0, l:len(), 'Removed') 50 elseif l:match('^• ') then 51 -- Available newer tags 52 hi_range(i, 4, l:len(), 'DiagnosticHint') 53 end 54 end 55 56 -- Mappings 57 local map_section_jump = function(lhs, search_flags, desc) 58 vim.keymap.set({ 'n', 'x' }, lhs, function() 59 for _ = 1, vim.v.count1 do 60 vim.fn.search('^## ', search_flags) 61 end 62 end, { buffer = 0, desc = desc }) 63 end 64 65 map_section_jump('[[', 'bsW', 'Previous plugin') 66 map_section_jump(']]', 'sW', 'Next plugin')