fix(colorify): clamp RGBA values to prevent invalid hex strings (reopened PR #500) #520
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.
Summary
This PR fixes a critical bug in
nvchad.colorify.methods.luawhere colors received from LSP viatextDocument/documentColorwere incorrectly converted from RGBA to hex strings.The original implementation directly multiplied floating-point values without clamping or rounding, producing invalid hex strings such as
#fe01fe01fe01, which caused runtime crashes when passed tonvim_set_hl()(see colorify/utils.lua: line #31).What was changed
Introduced a safe
to_hex(r, g, b, a)function that:+0.5)#rrggbbReplaced the direct
string.format(...)call with this safe method inside the LSP color handler.Why this matters
Without this fix, certain LSP servers (e.g. CSS, SCSS, Tailwind) may cause hard crashes when they return slightly invalid or unnormalized RGBA values. This bug is reproducible with color-aware LSPs (e.g. for CSS, SCSS, TailwindCSS, or Vue via Volar) that return fractional RGBA values.
Example Error
Error executing vim.schedule lua callback:
.../colorify/utils.lua:31:
Invalid highlight color: '#fe01fe01fe01'
Additional Notes
No visual or functional changes for users.