fix(colorify): clamp rgba to prevent invalid hex string#500
Closed
StefanBartl wants to merge 1 commit intoNvChad:v3.0from
StefanBartl:fix-colorify-invalid-rgba
Closed
fix(colorify): clamp rgba to prevent invalid hex string#500StefanBartl wants to merge 1 commit intoNvChad:v3.0from StefanBartl:fix-colorify-invalid-rgba
StefanBartl wants to merge 1 commit intoNvChad:v3.0from
StefanBartl:fix-colorify-invalid-rgba
Conversation
Member
|
can you show me an example file |
Author
Member
|
@StefanBartl why closed and deleted it? 😨 |
Author
Hi @siduck, I closed the PR because there was no reply on my last comment and it had been inactive for a few months, so I assumed it might not be relevant anymore or perhaps was being handled differently internally. There was no intention to drop the contribution — just to keep everything clean. If the fix is still useful, I’d be happy to reopen or recreate the PR. |
Member
|
@StefanBartl i was inactive due to work 😓 , please keep the PR opened. i will merge it when I'm free, probably this weekend. |
Author
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.

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.