-
-
Notifications
You must be signed in to change notification settings - Fork 173
fix(colorify): clamp rgba to prevent invalid hex string #500
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
can you show me an example file |
|
@StefanBartl why closed and deleted it? 😨 |
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. |
|
@StefanBartl i was inactive due to work 😓 , please keep the PR opened. i will merge it when I'm free, probably this weekend. |

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.