mirror of
https://github.com/neovim/neovim.git
synced 2025-09-07 11:58:17 +00:00
Merge #29021 TOhtml fixes
This commit is contained in:
@@ -57,6 +57,26 @@
|
|||||||
--- @field [3] any[][] virt_text
|
--- @field [3] any[][] virt_text
|
||||||
--- @field [4] any[][] overlay_text
|
--- @field [4] any[][] overlay_text
|
||||||
|
|
||||||
|
--- @type string[]
|
||||||
|
local notifications = {}
|
||||||
|
|
||||||
|
---@param msg string
|
||||||
|
local function notify(msg)
|
||||||
|
if #notifications == 0 then
|
||||||
|
vim.schedule(function()
|
||||||
|
if #notifications > 1 then
|
||||||
|
vim.notify(
|
||||||
|
('TOhtml: %s (+ %d more warnings)'):format(notifications[1], tostring(#notifications - 1))
|
||||||
|
)
|
||||||
|
elseif #notifications == 1 then
|
||||||
|
vim.notify('TOhtml: ' .. notifications[1])
|
||||||
|
end
|
||||||
|
notifications = {}
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
table.insert(notifications, msg)
|
||||||
|
end
|
||||||
|
|
||||||
local HIDE_ID = -1
|
local HIDE_ID = -1
|
||||||
-- stylua: ignore start
|
-- stylua: ignore start
|
||||||
local cterm_8_to_hex={
|
local cterm_8_to_hex={
|
||||||
@@ -215,7 +235,7 @@ local function cterm_to_hex(colorstr)
|
|||||||
if hex then
|
if hex then
|
||||||
cterm_color_cache[color] = hex
|
cterm_color_cache[color] = hex
|
||||||
else
|
else
|
||||||
vim.notify_once("Info(TOhtml): Couldn't get terminal colors, using fallback")
|
notify("Couldn't get terminal colors, using fallback")
|
||||||
local t_Co = tonumber(vim.api.nvim_eval('&t_Co'))
|
local t_Co = tonumber(vim.api.nvim_eval('&t_Co'))
|
||||||
if t_Co <= 8 then
|
if t_Co <= 8 then
|
||||||
cterm_color_cache = cterm_8_to_hex
|
cterm_color_cache = cterm_8_to_hex
|
||||||
@@ -241,7 +261,7 @@ local function get_background_color()
|
|||||||
end
|
end
|
||||||
local hex = try_query_terminal_color('background')
|
local hex = try_query_terminal_color('background')
|
||||||
if not hex or not hex:match('#%x%x%x%x%x%x') then
|
if not hex or not hex:match('#%x%x%x%x%x%x') then
|
||||||
vim.notify_once("Info(TOhtml): Couldn't get terminal background colors, using fallback")
|
notify("Couldn't get terminal background colors, using fallback")
|
||||||
hex = vim.o.background == 'light' and '#ffffff' or '#000000'
|
hex = vim.o.background == 'light' and '#ffffff' or '#000000'
|
||||||
end
|
end
|
||||||
background_color_cache = hex
|
background_color_cache = hex
|
||||||
@@ -259,7 +279,7 @@ local function get_foreground_color()
|
|||||||
end
|
end
|
||||||
local hex = try_query_terminal_color('foreground')
|
local hex = try_query_terminal_color('foreground')
|
||||||
if not hex or not hex:match('#%x%x%x%x%x%x') then
|
if not hex or not hex:match('#%x%x%x%x%x%x') then
|
||||||
vim.notify_once("Info(TOhtml): Couldn't get terminal foreground colors, using fallback")
|
notify("Couldn't get terminal foreground colors, using fallback")
|
||||||
hex = vim.o.background == 'light' and '#000000' or '#ffffff'
|
hex = vim.o.background == 'light' and '#000000' or '#ffffff'
|
||||||
end
|
end
|
||||||
foreground_color_cache = hex
|
foreground_color_cache = hex
|
||||||
@@ -467,7 +487,7 @@ local function _styletable_extmarks_highlight(state, extmark, namespaces)
|
|||||||
---TODO(altermo) LSP semantic tokens (and some other extmarks) are only
|
---TODO(altermo) LSP semantic tokens (and some other extmarks) are only
|
||||||
---generated in visible lines, and not in the whole buffer.
|
---generated in visible lines, and not in the whole buffer.
|
||||||
if (namespaces[extmark[4].ns_id] or ''):find('vim_lsp_semantic_tokens') then
|
if (namespaces[extmark[4].ns_id] or ''):find('vim_lsp_semantic_tokens') then
|
||||||
vim.notify_once('Info(TOhtml): lsp semantic tokens are not supported, HTML may be incorrect')
|
notify('lsp semantic tokens are not supported, HTML may be incorrect')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local srow, scol, erow, ecol =
|
local srow, scol, erow, ecol =
|
||||||
@@ -481,10 +501,17 @@ end
|
|||||||
|
|
||||||
--- @param state vim.tohtml.state
|
--- @param state vim.tohtml.state
|
||||||
--- @param extmark {[1]:integer,[2]:integer,[3]:integer,[4]:vim.api.keyset.set_extmark|any}
|
--- @param extmark {[1]:integer,[2]:integer,[3]:integer,[4]:vim.api.keyset.set_extmark|any}
|
||||||
local function _styletable_extmarks_virt_text(state, extmark)
|
--- @param namespaces table<integer,string>
|
||||||
|
local function _styletable_extmarks_virt_text(state, extmark, namespaces)
|
||||||
if not extmark[4].virt_text then
|
if not extmark[4].virt_text then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
---TODO(altermo) LSP semantic tokens (and some other extmarks) are only
|
||||||
|
---generated in visible lines, and not in the whole buffer.
|
||||||
|
if (namespaces[extmark[4].ns_id] or ''):find('vim_lsp_inlayhint') then
|
||||||
|
notify('lsp inlay hints are not supported, HTML may be incorrect')
|
||||||
|
return
|
||||||
|
end
|
||||||
local styletable = state.style
|
local styletable = state.style
|
||||||
--- @type integer,integer
|
--- @type integer,integer
|
||||||
local row, col = extmark[2], extmark[3]
|
local row, col = extmark[2], extmark[3]
|
||||||
@@ -521,11 +548,9 @@ local function _styletable_extmarks_virt_text(state, extmark)
|
|||||||
hl_mode = 'blend',
|
hl_mode = 'blend',
|
||||||
hl_group = 'combine',
|
hl_group = 'combine',
|
||||||
}
|
}
|
||||||
for opt, val in ipairs(not_supported) do
|
for opt, val in pairs(not_supported) do
|
||||||
if extmark[4][opt] == val then
|
if extmark[4][opt] == val then
|
||||||
vim.notify_once(
|
notify(('extmark.%s="%s" is not supported, HTML may be incorrect'):format(opt, val))
|
||||||
('Info(TOhtml): extmark.%s="%s" is not supported, HTML may be incorrect'):format(opt, val)
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -586,7 +611,7 @@ local function styletable_extmarks(state)
|
|||||||
_styletable_extmarks_conceal(state, v)
|
_styletable_extmarks_conceal(state, v)
|
||||||
end
|
end
|
||||||
for _, v in ipairs(extmarks) do
|
for _, v in ipairs(extmarks) do
|
||||||
_styletable_extmarks_virt_text(state, v)
|
_styletable_extmarks_virt_text(state, v, namespaces)
|
||||||
end
|
end
|
||||||
for _, v in ipairs(extmarks) do
|
for _, v in ipairs(extmarks) do
|
||||||
_styletable_extmarks_virt_lines(state, v)
|
_styletable_extmarks_virt_lines(state, v)
|
||||||
@@ -611,9 +636,7 @@ local function styletable_folds(state)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
if has_folded and type(({ pcall(vim.api.nvim_eval, vim.o.foldtext) })[2]) == 'table' then
|
if has_folded and type(({ pcall(vim.api.nvim_eval, vim.o.foldtext) })[2]) == 'table' then
|
||||||
vim.notify_once(
|
notify('foldtext returning a table with highlights is not supported, HTML may be incorrect')
|
||||||
'Info(TOhtml): foldtext returning a table is half supported, HTML may be incorrect'
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user