spacevim/bundle/coc.nvim-release/lua/coc/highlight.lua
JIe 2bb7059579
Some checks failed
Detach Plugins / check (FlyGrep.vim) (push) Has been cancelled
Detach Plugins / check (GitHub.vim) (push) Has been cancelled
Detach Plugins / check (JavaUnit.vim) (push) Has been cancelled
Detach Plugins / check (SourceCounter.vim) (push) Has been cancelled
Detach Plugins / check (cpicker.nvim) (push) Has been cancelled
Detach Plugins / check (dein-ui.vim) (push) Has been cancelled
Detach Plugins / check (git.vim) (push) Has been cancelled
Detach Plugins / check (iedit.vim) (push) Has been cancelled
Detach Plugins / check (scrollbar.vim) (push) Has been cancelled
Detach Plugins / check (vim-chat) (push) Has been cancelled
Detach Plugins / check (vim-cheat) (push) Has been cancelled
Detach Plugins / check (vim-todo) (push) Has been cancelled
Detach Plugins / check (xmake.vim) (push) Has been cancelled
test / Linux (nvim, nightly) (push) Has been cancelled
test / Linux (nvim, v0.3.8) (push) Has been cancelled
test / Linux (nvim, v0.4.0) (push) Has been cancelled
test / Linux (nvim, v0.4.2) (push) Has been cancelled
test / Linux (nvim, v0.4.3) (push) Has been cancelled
test / Linux (nvim, v0.4.4) (push) Has been cancelled
test / Linux (nvim, v0.5.0) (push) Has been cancelled
test / Linux (nvim, v0.5.1) (push) Has been cancelled
test / Linux (nvim, v0.6.0) (push) Has been cancelled
test / Linux (nvim, v0.6.1) (push) Has been cancelled
test / Linux (nvim, v0.7.0) (push) Has been cancelled
test / Linux (nvim, v0.7.2) (push) Has been cancelled
test / Linux (nvim, v0.8.0) (push) Has been cancelled
test / Linux (nvim, v0.8.1) (push) Has been cancelled
test / Linux (nvim, v0.8.2) (push) Has been cancelled
test / Linux (nvim, v0.8.3) (push) Has been cancelled
test / Linux (nvim, v0.9.0) (push) Has been cancelled
test / Linux (nvim, v0.9.1) (push) Has been cancelled
test / Linux (true, vim, v7.4.052) (push) Has been cancelled
test / Linux (true, vim, v7.4.1689) (push) Has been cancelled
test / Linux (true, vim, v7.4.629) (push) Has been cancelled
test / Linux (true, vim, v8.0.0027) (push) Has been cancelled
test / Linux (true, vim, v8.0.0183) (push) Has been cancelled
test / Linux (vim, nightly) (push) Has been cancelled
test / Linux (vim, v8.0.0184) (push) Has been cancelled
test / Linux (vim, v8.0.1453) (push) Has been cancelled
test / Linux (vim, v8.1.2269) (push) Has been cancelled
test / Linux (vim, v8.2.2434) (push) Has been cancelled
test / Linux (vim, v8.2.3995) (push) Has been cancelled
test / Windows (nvim, nightly) (push) Has been cancelled
test / Windows (nvim, v0.3.8) (push) Has been cancelled
test / Windows (nvim, v0.4.2) (push) Has been cancelled
test / Windows (nvim, v0.4.3) (push) Has been cancelled
test / Windows (nvim, v0.4.4) (push) Has been cancelled
test / Windows (nvim, v0.5.0) (push) Has been cancelled
test / Windows (nvim, v0.5.1) (push) Has been cancelled
test / Windows (nvim, v0.6.0) (push) Has been cancelled
test / Windows (nvim, v0.6.1) (push) Has been cancelled
test / Windows (nvim, v0.7.0) (push) Has been cancelled
test / Windows (nvim, v0.7.2) (push) Has been cancelled
test / Windows (nvim, v0.8.0) (push) Has been cancelled
test / Windows (nvim, v0.8.1) (push) Has been cancelled
test / Windows (nvim, v0.8.2) (push) Has been cancelled
test / Windows (nvim, v0.8.3) (push) Has been cancelled
test / Windows (nvim, v0.9.0) (push) Has been cancelled
test / Windows (nvim, v0.9.1) (push) Has been cancelled
test / Windows (vim, nightly) (push) Has been cancelled
test / Windows (vim, v7.4.1185) (push) Has been cancelled
test / Windows (vim, v7.4.1689) (push) Has been cancelled
test / Windows (vim, v8.0.0027) (push) Has been cancelled
test / Windows (vim, v8.0.1453) (push) Has been cancelled
test / Windows (vim, v8.1.2269) (push) Has been cancelled
test / Windows (vim, v8.2.2434) (push) Has been cancelled
test / Windows (vim, v8.2.3995) (push) Has been cancelled
docker / docker (push) Has been cancelled
mirror / check (coding) (push) Has been cancelled
mirror / check (gitee) (push) Has been cancelled
mirror / check (gitlab) (push) Has been cancelled
init
2024-08-21 14:17:26 +08:00

86 lines
2.3 KiB
Lua

local api = vim.api
local M = {}
-- Get single line extmarks
function M.getHighlights(bufnr, key, s, e)
if not api.nvim_buf_is_loaded(bufnr) then
return nil
end
s = s or 0
e = e or -1
local max = e == -1 and api.nvim_buf_line_count(bufnr) or e + 1
local ns = api.nvim_create_namespace('coc-' .. key)
local markers = api.nvim_buf_get_extmarks(bufnr, ns, {s, 0}, {e, -1}, {details = true})
local res = {}
for _, mark in ipairs(markers) do
local id = mark[1]
local line = mark[2]
local startCol = mark[3]
local details = mark[4]
local endCol = details.end_col
if line < max then
local delta = details.end_row - line
if delta <= 1 and (delta == 0 or endCol == 0) then
if startCol == endCol then
api.nvim_buf_del_extmark(bufnr, ns, id)
else
if delta == 1 then
local text = api.nvim_buf_get_lines(bufnr, line, line + 1, false)[1] or ''
endCol = #text
end
table.insert(res, {details.hl_group, line, startCol, endCol, id})
end
end
end
end
return res
end
local function addHighlights(bufnr, ns, highlights, priority)
for _, items in ipairs(highlights) do
local hlGroup = items[1]
local line = items[2]
local startCol = items[3]
local endCol = items[4]
local hlMode = items[5] and 'combine' or 'replace'
-- Error: col value outside range
pcall(api.nvim_buf_set_extmark, bufnr, ns, line, startCol, {
end_col = endCol,
hl_group = hlGroup,
hl_mode = hlMode,
right_gravity = true,
priority = type(priority) == 'number' and math.min(priority, 4096) or 4096
})
end
end
local function addHighlightTimer(bufnr, ns, highlights, priority, maxCount)
local hls = {}
local next = {}
for i, v in ipairs(highlights) do
if i < maxCount then
table.insert(hls, v)
else
table.insert(next, v)
end
end
addHighlights(bufnr, ns, hls, priority)
if #next > 0 then
vim.defer_fn(function()
addHighlightTimer(bufnr, ns, next, priority, maxCount)
end, 30)
end
end
function M.set(bufnr, ns, highlights, priority)
local maxCount = vim.g.coc_highlight_maximum_count
if #highlights > maxCount then
addHighlightTimer(bufnr, ns, highlights, priority, maxCount)
else
addHighlights(bufnr, ns, highlights, priority)
end
end
return M