Skip to content

Commit

Permalink
perf(hl): use real hl_group ids on nightly instead of ffi
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Nov 18, 2024
1 parent 221ffbc commit d5483a0
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lua/noice/text/block.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ local Highlight = require("noice.text.highlight")
local NuiLine = require("nui.line")
local Object = require("nui.object")

---@alias NoiceChunk { [0]: integer, [1]: string}
---@alias NoiceChunk { [0]: integer, [1]: string, [2]?: integer}
---@alias NoiceContent string|NoiceChunk|NuiLine|NuiText|NoiceBlock

---@class NoiceBlock
Expand Down Expand Up @@ -165,7 +165,7 @@ function Block:append(contents, highlight)
---@cast content NoiceChunk
-- Handle newlines
---@type number|string|table, string
local attr_id, text = unpack(content)
local attr_id, text, hl_id = unpack(content)
-- msg_show messages can contain invalid \r characters
if self.fix_cr ~= false then
text = text:gsub("%^M", "\r")
Expand All @@ -174,7 +174,9 @@ function Block:append(contents, highlight)

---@type string|table|nil
local hl_group
if type(attr_id) == "number" then
if type(hl_id) == "number" then
hl_group = vim.fn.synIDattr(hl_id, "name")

This comment has been minimized.

Copy link
@luukvbaal

luukvbaal Nov 18, 2024

You can use the chunk's highlight ID directly as input to nvim_buf_set_extmark(.., {hl_group = hl_id }) @folke. I forgot about this when writing the commit message for the PR and later updated the docs in neovim/neovim#31195.

This comment has been minimized.

Copy link
@folke

folke Nov 18, 2024

Author Owner

Oh nice! That's even better

This comment has been minimized.

Copy link
@folke

folke Nov 18, 2024

Author Owner

Just updated. Works great. Thank again for all your work on ui_attach!

elseif type(attr_id) == "number" then
hl_group = attr_id ~= 0 and Highlight.get_hl_group(attr_id) or nil
else
hl_group = attr_id
Expand Down

0 comments on commit d5483a0

Please sign in to comment.