KamiKillertO / vscode-colorize

A vscode extension to help visualize css colors in files
Apache License 2.0
272 stars 37 forks source link

colorize.include is not working #890

Open reefhound opened 1 year ago

reefhound commented 1 year ago

The Colorize tray icon says "Colorize is not activated for this file"

I'm trying to colorize qss files, Python's PyQt styling. I have my settings as: "colorize.include": [ "*/.qss" ],

The content is similar to CSS and colorizes fine when pasted into a file with a .css extension so the issue is it's not processing the .qss file. I have not seen one person report getting this to work. Is there some additional step required?

I've tried both the original version by Kami and the newer fork.

Also, the "colorize.exclude" doesn't work either. I added to exclude .css and it still colorizes it even after restart. "colorize.exclude": ["*/.css", "*/.scss"],

reefhound commented 1 year ago

Found the issue. In Extensions.js (In Kami's version, Yuteng's is obfuscated) is this function:

function isIncludedFile(fileName) { return config.filesToIncludes.find((globPattern) => globToRegexp(globPattern).test(fileName)) !== undefined; }

Replacing the return to just check for hardcoded extension makes files of that extension work. function isIncludedFile(fileName) { return fileName.endsWith(".qss"); )

So there is something whacked with the regex and my regex skills are weak.

tjx666 commented 1 year ago

https://marketplace.visualstudio.com/items?itemName=YuTengjing.vscode-colorize-plus

reefhound commented 1 year ago

Nope. Same fail.

reefhound commented 1 year ago

Besides, the forked version has essentially the same code as the original in the function isIncludedFile. line 164 of Extensions.js of fork return config.filesToIncludes.find((globPattern: string) => globToRegexp(globPattern).test(fileName)) !== undefined;

line 149 of Extensions.js of original return config.filesToIncludes.find((globPattern) => globToRegexp(globPattern).test(fileName)) !== undefined;

tjx666 commented 1 year ago

@reefhound try latest version

reefhound commented 1 year ago

@reefhound try latest version

Did you actually try the latest version? You can add a non-Language Supported file pattern in "colorize.include" and get it to activate and colorize?

I have the latest code in the repo. The canColorize function is what determines if the page is activated. It does not even look at "colorize.exclude". In fact, there is a comment that it needs to be added and the include needs to be reworked. And the isIncludedFile function is the same as what I posted in post #2 so it hasn't been changed.

/**

/**

tjx666 commented 1 year ago

@reefhound I mean try my latest version. I publish a new version instead of official version. The official version is not maintained any more. I fixed it in this commit: https://github.com/tjx666/vscode-colorize/commit/1f913876944ff1e49fbc002d4559b4106ca916e5

image
reefhound commented 1 year ago

I'm not installing "open source" that has been obfuscated. Where is the development repo? I'll be able to tell if it's fixed from looking at the code itself.

reefhound commented 1 year ago

I've already fixed Kami's for myself. Since all I care about is absolute extensions, I only check the extension. I get the extension and do a simple check that the filename ends with the extension. I added an exclude function and allowed an exclude match to short circuit the canColorize function.

reefhound commented 1 year ago

/**

reefhound commented 1 year ago

never mind, found your code. Looks like you replaced find with some and added the exclude check inline rather than separate function, I'll test.

reefhound commented 1 year ago

I installed your latest and still not working for me. My settings: "colorize.include": ["/*.qss"], "colorize.exclude": ["*/.css", "/*.scss"], "colorize.colorized_colors": ["BROWSERS_COLORS", "HEXA", "RGB", "HSL"], "colorize.languages": ["css", "sass", "scss", "less", "xml", "svg"]

My snippet to colorize: QLineEdit { background-color:#D8BFD8; border:2px solid #6272a4; color:#586796; }

This snippet, in a filename with an included qss extension, does not activate and colorize yet in an excluded css extension continues to active and colorize.

reefhound commented 1 year ago

Note that your exclusion check comes after your language check so an excluded file that is language supported will never get excluded. In my fix, I do the exclusion check first.

function isIncludedFile(fileName: string): boolean { if (config.filesToExcludes.some((globPattern) => globToRegexp(globPattern).test(fileName))) { return false; } return config.filesToIncludes.some((globPattern: string) => globToRegexp(globPattern).test(fileName), ); }

/**

tjx666 commented 1 year ago

you need write **/*.qss, not /*.qss

reefhound commented 1 year ago

"colorize.include": ["/*.qss"], "colorize.exclude": ["*/.css", "/*.scss"],

I have it as double asterisk, slash, asterisk extension. It's this discussion board software changing it.

tjx666 commented 1 year ago

I will fix the exclude logic tomorrow, I need to sleep now.

tjx666 commented 1 year ago

The qss file can be colorized in my local machine, I will show you my settings and screenshot tomorrow

tjx666 commented 1 year ago
image
{
    "colorize.languages": ["css", "scss", "less", "xml", "svg"],
    "colorize.enable_search_variables": false,
    "colorize.include": [
        "**/*.css",
        "**/*.scss",
        "**/*.sass",
        "**/*.less",
        "**/*.styl",
        "**/*.qss"
    ],
}

I had publish a new version fix the exclude logic https://github.com/tjx666/vscode-colorize/commit/6aa0231c1c6369645bccb9a07fe9f55a3cad66d8

reefhound commented 1 year ago

Just tried latest, still doesn't work for me. I did a complete uninstall, restart, install cycle. I think something else is going on. The code in the commit looks ok. Are you sure the build pipeline is working right? Have you confirmed it working on your end with the production version? I'm just wondering if the package reg-to-exp is the problem.

I'm using the latest version of Vscode on Windows 10. The extension version shows as 0.12.8

reefhound commented 1 year ago

I think you're not using Windows. Could be the way Windows uses backslashes instead of forward slashes in filenames. Not sure if glob-to-regexp supports Windows.

There's a later version forked. kd-glob-to-regexp 0.4.2

reefhound commented 1 year ago

Looking at index.js of the dependency glob-to-regexp, it appears to be a single function that parses the input string one character at a time and builds the regex string. In the switch cases I don't see a check for "\" which is how the Windows path separator would look.

tjx666 commented 1 year ago

can you provide a screenshot of this extension homepage in vscode. I want to ensure you are using my latest version

tjx666 commented 1 year ago

can you provide a screenshot of this extension homepage in vscode? I want to ensure you are using my latest version

reefhound commented 1 year ago

Capture

reefhound commented 1 year ago

Pretty sure it's the latest. I can see the newest functions in the extension code, though obfuscated and minified.

function fr(r){return f.filesToExcludes.some(e=>(0,he.default)(e).test(r))}function hr(r){return f.filesToIncludes.some(e=>(0,he.default)(e).test(r))}

tjx666 commented 1 year ago

I'm outside visiting my relatives.I will test it on windows tonight

tjx666 commented 1 year ago
image

You need write **\\*.qss on windows:

image
tjx666 commented 1 year ago

@reefhound try latest version

reefhound commented 1 year ago

Works now. Great job.