Skip to content

Commit 20e2d30

Browse files
phanenibhagwan
authored andcommitted
fix(tsinjector): manually parse in on_win to fix the highlight on nightly
1 parent d0b7f80 commit 20e2d30

1 file changed

Lines changed: 19 additions & 4 deletions

File tree

lua/fzf-lua/win.lua

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function TSInjector.setup()
3030
and pcall(api.nvim_set_decoration_provider, TSInjector._ns, { on_range = function() end })
3131
or TSInjector._has_on_range
3232

33-
local function wrap_ts_hl_callback(name)
33+
local function wrap_ts_hl_callback(name, cb)
3434
return function(_, win, buf, ...)
3535
-- print(name, buf, win, TSInjector.cache[buf])
3636
if not TSInjector.cache[buf] then
@@ -40,6 +40,7 @@ function TSInjector.setup()
4040
if hl.enabled then
4141
vim.treesitter.highlighter.active[buf] = hl.highlighter
4242
if vim.treesitter.highlighter[name] then
43+
if cb then cb(hl.highlighter, buf, ...) end
4344
vim.treesitter.highlighter[name](_, win, buf, ...)
4445
end
4546
end
@@ -48,13 +49,27 @@ function TSInjector.setup()
4849
end
4950
end
5051

52+
local on_range = wrap_ts_hl_callback("_on_range")
53+
local on_line = TSInjector._has_on_range and function(_, win, buf, row)
54+
return on_range(_, win, buf, row, 0, row + 1, 0)
55+
end or wrap_ts_hl_callback("_on_line")
56+
57+
local on_win_pre = utils.__HAS_NVIM_012 and function(h, buf, topline, botline)
58+
if h.parsing then return end
59+
h.parsing = nil == h.tree:parse({ topline, botline + 1 }, function(_, trees)
60+
if trees and h.parsing then
61+
h.parsing = false
62+
api.nvim__redraw({ buf = buf, valid = false, flush = false })
63+
end
64+
end)
65+
end or nil
66+
5167
api.nvim_set_decoration_provider(TSInjector._ns, {
5268
-- NOTE: unsure why we need "on_start"
5369
-- causes issue with mixed lang regions (#2526)
5470
-- on_start = wrap_ts_hl_callback("_on_start"),
55-
on_win = wrap_ts_hl_callback("_on_win"),
56-
on_line = wrap_ts_hl_callback("_on_line"),
57-
on_range = TSInjector._has_on_range and wrap_ts_hl_callback("_on_range") or nil,
71+
on_win = wrap_ts_hl_callback("_on_win", on_win_pre),
72+
on_line = on_line,
5873
})
5974

6075
return true

0 commit comments

Comments
 (0)