Skip to content

Conversation

hahn-kev
Copy link
Contributor

@hahn-kev hahn-kev commented Jul 23, 2022

Not sure this will really be useful the way it's written right now but it works for my fork and I thought I'd contribute it back upstream in-case this could be used in conjunction with some kind of Color type.

With some configuration settings it could probably be made useful to others. The hard part is mapping a color to text and back again kinda has to be custom, but we could make some templates that could cover most cases, maybe even as a plugin someone could provide the converting and testing code?

Basically it enables color decorators when it finds a string with 8 hex chars in it's current configuration.
image

@Nexela
Copy link
Contributor

Nexela commented Jul 24, 2022

Nice, How easy would this be to adapt to these kinds of table patterns with the fourth in each being optional (alpha)

{.5,  .5,  .5,  .5} --  0-1
{245,  245,  245,  245} ---1-255
{r = 245, g = 255, b = 255, a = 255 } --- 1-255 indexed by r, g, b, a ---Either in that order, or any order
{r =  .5, g = 0.5, b =  0.5, a = 0.5} --- 0-1 indexed by r, g, b, a   ---Either in that order, or any order

@sumneko sumneko merged commit a2052c1 into LuaLS:master Jul 24, 2022
@sumneko
Copy link
Collaborator

sumneko commented Jul 24, 2022

Thank you!

@hahn-kev
Copy link
Contributor Author

Nice, How easy would this be to adapt to these kinds of table patterns with the fourth in each being optional (alpha)

{.5,  .5,  .5,  .5} --  0-1
{245,  245,  245,  245} ---1-255
{r = 245, g = 255, b = 255, a = 255 } --- 1-255 indexed by r, g, b, a ---Either in that order, or any order
{r =  .5, g = 0.5, b =  0.5, a = 0.5} --- 0-1 indexed by r, g, b, a   ---Either in that order, or any order

Probably not too hard, the problem is that I don't see any way to make it customizable outside of a plugin.

There's a couple ways each case are different

  • How a color is identified, in my case it's a hex string 8 chars long, in your case it's a table with specific fields.
  • How the color channels are specified, very similar to above, but in my case I had to split each pair of characters out of the string
  • The color format, RGB or whatever else, it would nees to be converted to RGBA
  • The number format, in my case it was a hext number and it needs to be converted into a float 0-1.

The other hard part is once you do all that you need to be able to reverse the conversion to take the color from vscode and write it into the editor.

We could hard code support for your case, but I'm sure there's a hundred others that wouldn't be covered and it would end up being an endless maintenance issue.

@Nexela
Copy link
Contributor

Nexela commented Jul 25, 2022

I gave this a shot and made some good progress. was able to read and write into an {r =...} table.
The easiest way I can see to make this customizable would be a setting to switch between color types, but I think a plugin callback would be even better.

@hahn-kev hahn-kev deleted the add-color-support branch August 1, 2022 04:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants