facelessuser / ColorHelper

Sublime plugin that provides helpful color previews and tooltips
https://facelessuser.github.io/ColorHelper/
MIT License
256 stars 31 forks source link

Color preview is no longer showing in XML syntax #208

Closed dportalesr closed 2 years ago

dportalesr commented 2 years ago

Description

ColorHelper stopped working for XML syntax, specifically for sublime theme files (tmTheme). It used to work fine not long ago (not sure if this plugin was updated on my side recently).

image

It's working for CSS syntaxes (SCSS, CSS, SASS).

image

SublimeText's console shows this multiple times:

ColorHelper: Clear color class stash

ColorHelper: ColorHelper: 
Traceback (most recent call last):
  File "/Users/Dan/Library/Application Support/Sublime Text/Installed Packages/ColorHelper.sublime-package/ch_preview.py", line 538, in run
    self.do_search(force)
  File "/Users/Dan/Library/Application Support/Sublime Text/Installed Packages/ColorHelper.sublime-package/ch_preview.py", line 397, in do_search
    obj = color_class.match(source, start=start, filters=filters)
  File "/Users/Dan/Library/Application Support/Sublime Text/Installed Packages/ColorHelper.sublime-package/lib/coloraide/color.py", line 235, in match
    m = cls._match(string, start, fullmatch, filters=filters)
  File "/Users/Dan/Library/Application Support/Sublime Text/Installed Packages/ColorHelper.sublime-package/lib/coloraide/color.py", line 220, in _match
    color = space_class(*m[0])
TypeError: BaseSpace object argument after * must be a sequence, not NoneType

Support Info

Steps to Reproduce Issue

  1. Open a file with hexadecimal colors in XML syntax
  2. Color preview is not showing.
dportalesr commented 2 years ago

It seems that the error message mentioned is not related to my issue.

I managed to fix my problem by adding a custom user color rule:

    "user_color_rules": [
        {
            "name": "XML-tmTheme",
            "base_scopes": ["text.plist"],
            "color_class": "css-level-4",
            "scanning": [
                "text.plist -comment -string"
            ]
        },
    ]

I took a look to the settings file for the package and I noticed some changes compared to my customized version. But the actual problem seems to be related to my custom tmTheme that I've used for a long time, which I think it's now using an old syntax, since the default color rule defined in color_helper.sublime-settings seems different:

        {
            "name": "tmTheme",
            "color_trigger": "(?i)(?:\\b(?<![-#&$])[\\w]{3,}(?![(-])\\b|(?!<&)\\#)",
            "extensions": [".tmTheme"],
            "base_scopes": ["text.xml"],
            "color_class": "tmtheme",
            "scanning": [
                "text.xml -meta.tag.xml -comment -string, string.unquoted.cdata.xml"
            ]
        },

Probably it's a good idea to add that rule I added to the defaults to support old sublime theme files syntax.

facelessuser commented 2 years ago

Yes, there is a bug. A recent refactor of the underlying color library caused some changes in custom classes. Our built-in custom classes do not properly return the correct "match" value causing preview failures. I have a fix locally and will cut a release a little bit later.

facelessuser commented 2 years ago

Fix has been released but Package Control won't probably see it for a couple of hours.

dportalesr commented 2 years ago

Thank you! You rock 👊