Skip to content

headlines.nvim: guard against nil hl_group (E5108) on filewatch reload #670

Description

@dotrakoun-clearstreet

Problem

Intermittent crash when a filewatch-triggered reload fires FileType/Syntax autocmds while treesitter is mid-reparse:

...headlines.nvim/lua/headlines/init.lua:199: attempt to concatenate local 'name' (a nil value)
  make_reverse_highlight (init.lua:199)
  refresh (init.lua:303)

Cause

During the racy reload the heading node text comes back empty, so level = #vim.trim(...) = 0, making c.headline_highlights[math.min(level, #c.headline_highlights)]headline_highlights[0]nil. That nil hl_group is passed to make_reverse_highlight, which concatenates name .. "Reverse" and throws E5108. Only happens with fat_headlines = true (the only caller).

Workaround

Monkeypatch in nvim/lua/dko/plugins/markdown.lua — wrap make_reverse_highlight to return "Normal" when name is nil, then call setup:

config = function(_, opts)
  local headlines = require("headlines")
  local make_reverse_highlight = headlines.make_reverse_highlight
  headlines.make_reverse_highlight = function(name)
    if not name then return "Normal" end
    return make_reverse_highlight(name)
  end
  headlines.setup(opts)
end,

TODO

  • Revisit/remove the monkeypatch if headlines.nvim guards the nil hl_group upstream.

Metadata

Metadata

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions