feat(spell): support nospell in treesitter queries

(cherry picked from commit 07eb4263ca)
This commit is contained in:
Lewis Russell
2022-10-28 13:09:22 +01:00
committed by github-actions[bot]
parent 7a49cf4da9
commit 3d0ddd2d1f
2 changed files with 17 additions and 5 deletions

View File

@@ -432,6 +432,9 @@ capture marks comments as to be checked: >
(comment) @spell
<
There is also `@nospell` which disables spellchecking regions with `@spell`.
*treesitter-highlight-conceal*
Treesitter highlighting supports |conceal| via the `conceal` metadata. By
convention, nodes to be concealed are captured as `@conceal`, but any capture

View File

@@ -164,7 +164,7 @@ function TSHighlighter:get_query(lang)
end
---@private
local function on_line_impl(self, buf, line, spell)
local function on_line_impl(self, buf, line, is_spell_nav)
self.tree:for_each_tree(function(tstree, tree)
if not tstree then
return
@@ -201,17 +201,26 @@ local function on_line_impl(self, buf, line, spell)
local start_row, start_col, end_row, end_col = node:range()
local hl = highlighter_query.hl_cache[capture]
local is_spell = highlighter_query:query().captures[capture] == 'spell'
local capture_name = highlighter_query:query().captures[capture]
local spell = nil
if capture_name == 'spell' then
spell = true
elseif capture_name == 'nospell' then
spell = false
end
if hl and end_row >= line and (not spell or is_spell) then
-- Give nospell a higher priority so it always overrides spell captures.
local spell_pri_offset = capture_name == 'nospell' and 1 or 0
if hl and end_row >= line and (not is_spell_nav or spell ~= nil) then
a.nvim_buf_set_extmark(buf, ns, start_row, start_col, {
end_line = end_row,
end_col = end_col,
hl_group = hl,
ephemeral = true,
priority = tonumber(metadata.priority) or 100, -- Low but leaves room below
priority = (tonumber(metadata.priority) or 100) + spell_pri_offset, -- Low but leaves room below
conceal = metadata.conceal,
spell = is_spell,
spell = spell,
})
end
if start_row > line then