enyancc / vscode-ext-color-highlight

Extension adds colored border around css/web colors in the editor
GNU General Public License v3.0
262 stars 83 forks source link

Feature: add HSL Without Function + fix RGB double matching + support floats #200

Closed LucasMatuszewski closed 7 months ago

LucasMatuszewski commented 8 months ago

Hey :)

First, many thanks for your plugin! It's exactly what I needed. I appreciate the way you organized the files, it was very easy to understand how it works and add a new functionality.

Motivation for this PR

Many people use Tailwind right now, with CSS variables containing HSL color format without function name, like this:

--navy: 208 100% 25%;

It's a huge pain for many that there is no plugin supporting this format, here you can find some complaints:

My changes

Here is how it looks after my changes: image

And here is a link to download the packaged VSIX file: https://we.tl/t-VHTnVChsMR

To install it we can just go to "Extension", click three dots icon (up-right corner of extensions), and select Install from VSIX... or with CLI: code --install-extension myextension.vsix.

How to test

I'm new to VSCode plugins so maybe this is not the best way to test it, but maybe this will be helpful:

    --navy: 208 100% 25%;
    --red: 360 87% 44%;
    --redRGB: 255, 0, 0;
    --test: hsl(360 87% 44%);

Here you can test my RegEx and modify it if you want:

If the link expired: Regex ([.\d]{1,5})[^\S\n]*(?<commaOrSpace>[^\S\n]|,)[^\S\n]*([.\d]{1,5}%)[^\S\n]*\k<commaOrSpace>[^\S\n]*([.\d]{1,5}%)(?:;| |$)

My testing values:

--navy: 208 100% 25%;
--dark-blue: 208, 100%, 25%;
--navy_blue: 208, 100%, 25%;
--red: 360 87% 44%;
 --foreground: 224 71.4% 4.1%
--popover-foreground: 224 71.4% 4.1%;
    --background: 224 100% 4.1%;
    --primary-foreground: 220.9 39.3% 100%;
    --secondary: 215 27.9% 16.9%;
    --secondary-foreground: 210 20% 98%;   --ring: 224 71.4% 4.1%;
    --muted-foreground: 217.9 10.6% 64.9%;
--navy: 360 100% 100%;

// correct but will fail (out of scope for the plugin):
--navy_blue: hsla(208, 100%, 25%);
--navy_blue: hsl(208, 100%, 25% / 50%);
--navy_blue: hsla(0.3turn 100% 25% / .7);
  --red: hsl(360 87% 44%);

// Should fail:
--navy: 208% 100% 25%;
--navy: 208 100 25%;
--navy: 208 100 25;
--navy: 208 dfdf100% 25%;
--navy: #00ff33;
--foreground: 224 71.4% 4.1%dsfsf
--max-width: 1100px;
--radius: 0.5rem;
h1:hover { weight: bold };

Other suggestions

Separate Extension for Tailwind

Do you mind if I would create a separate extension named "Color Highlight Tailwind"? With full credentials and links to your extension of course.

I guess many people using Tailwind would like to use it only for CSS variables without function names, and/or only in CSS files. It would be much better for performance.

Do you mind if I create this minimalistic version based on your extension (by just removing unnecessary parts)? I have already created a Regex for this ;) https://regex101.com/r/h1nY7R/1

Unapprove?

If you would not approve this PR for any reason I would really like to create a separate forked plugin - we really need that plugin for Tailwind :)

boan-anbo commented 8 months ago

Great work and do need the feat. but this repo looks unmaintained for a long time. The last merged PR was from two years ago..

LucasMatuszewski commented 8 months ago

Great work and do need the feat. but this repo looks unmaintained for a long time. The last merged PR was from two years ago..

Thanks @boan-anbo ! We will see :) I can update the packages here in the separate pr if @enyancc will agree.

In the meantime you can install my VSIX file: https://we.tl/t-VHTnVChsMR

It works just fine. Or you can clone the repo with my branch and make your own build and vsix package if you don't install files from unknown sources 😂 I would totally understand this ;)

enyancc commented 8 months ago

Hi Lucas, thanks for your contribution, I will deploy it today

LucasMatuszewski commented 8 months ago

Hi Lucas, thanks for your contribution, I will deploy it today

Hi @enyancc - thank you very much! :)

Please let me know what you think about my other suggestions/questions.

Especially the activationEvents option - imho it would be best to set it now to onStartupFinished, maybe even in this PR, to optimize performance a little bit.

And in a separate PR I would consider creating a list of triggering languages. But it would require good research and testing.

If I understand correctly setting languages in activationEvents should be better for performance than your list of languages in configs, because it will not trigger your plugin at all in places where we don't want this plugin (like bash scripts, yaml, dockerfile, gitignore etc.). Now, it's triggering everywhere.

LucasMatuszewski commented 8 months ago

ahh, BTW @enyancc - on my screen --redRGB var is not colored because I didn't activate the "RGB without function" option. It works fine, I have just tested it - here is a screen:

image

But of course, it's better to test everything one more time :)

LucasMatuszewski commented 7 months ago

@enyancc - Thanks a lot for merging and mentioning me in the "contributors" section. It was a small contribution but I'm honored :)

jamesone commented 4 months ago

image I needed to goto my Color Highlight settings and enable this :)

Thank you!

paulovictor237 commented 3 months ago

settings.json

"color-highlight.matchHslWithNoFunction": true,