fix(buffer): ignore stale extmark range errors - #214
Merged
Conversation
Owner
|
Can we do something like local function set_extmark_ignore_stale_range(bufnr, ns_id, line, col, opts)
local ok, err = pcall(vim.api.nvim_buf_set_extmark, bufnr, ns_id, line, col, opts)
if ok then
return true
end
if type(err) == "string" and err:find("Invalid 'end_col': out of range", 1, true) then
return false
end
error(err, 2)
end
-- replace your pcall with:
set_extmark_ignore_stale_range(bufnr, ns_id, linenr, hl.range[1], {
end_col = hl.range[2],
hl_group = hlname,
priority = priority,
})Perhaps using something like local stale_extmark_range_errors = {
"Invalid 'col': out of range",
"Invalid 'end_col': out of range",
"Invalid 'line': out of range",
}
local function is_stale_extmark_range_error(err)
if type(err) ~= "string" then
return false
end
for _, msg in ipairs(stale_extmark_range_errors) do
if err:find(msg, 1, true) then
return true
end
end
return false
endSo we don't swallow all errors, only specific extmark ones you are concerned about. |
Ignore stale column and line range errors when applying highlights. Re-raise other nvim_buf_set_extmark failures for both non-virtualtext and virtualtext highlights.
Author
|
Addressed, both non-virtualtext and virtualtext extmarks now use the helper. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When asynchronous updates or byte-offset misalignments produce stale ranges, nvim_buf_set_extmark() can raise an out-of-range error.
Ignore only stale
col,end_col, andlinerange errors for both non-virtualtext and virtualtext highlights. Re-raise all other extmark errors.