api: multiple decoration providers at once

This commit is contained in:
Björn Linse
2020-09-21 10:37:28 +02:00
parent 11ec53e558
commit 0b615dae07
16 changed files with 502 additions and 271 deletions

View File

@@ -6,6 +6,8 @@ TSHighlighter.__index = TSHighlighter
TSHighlighter.active = TSHighlighter.active or {}
local ns = a.nvim_create_namespace("treesitter/highlighter")
-- These are conventions defined by tree-sitter, though it
-- needs to be user extensible also.
TSHighlighter.hl_map = {
@@ -158,7 +160,11 @@ function TSHighlighter._on_line(_, _win, buf, line)
local start_row, start_col, end_row, end_col = node:range()
local hl = self.hl_cache[capture]
if hl and end_row >= line then
a.nvim__put_attr(start_row, start_col, { end_line = end_row, end_col = end_col, hl_group = hl })
a.nvim_buf_set_extmark(buf, ns, start_row, start_col,
{ end_line = end_row, end_col = end_col,
hl_group = hl,
ephemeral = true
})
end
if start_row > line then
self.nextrow = start_row
@@ -166,7 +172,7 @@ function TSHighlighter._on_line(_, _win, buf, line)
end
end
function TSHighlighter._on_start(_, buf, _tick)
function TSHighlighter._on_buf(_, buf)
local self = TSHighlighter.active[buf]
if self then
local tree = self.parser:parse()
@@ -187,10 +193,10 @@ function TSHighlighter._on_win(_, _win, buf, _topline, botline)
return true
end
a.nvim__set_luahl {
on_start = TSHighlighter._on_start;
a.nvim_set_decoration_provider(ns, {
on_buf = TSHighlighter._on_buf;
on_win = TSHighlighter._on_win;
on_line = TSHighlighter._on_line;
}
})
return TSHighlighter