Open
Conversation
Add wildcard (*) support to fileNames, fileExtensions, folderNames, folderNamesExpanded, rootFolderNames, and rootFolderNamesExpanded keys in icon theme JSON files, enabling patterns like 'webpack.*', '*.test.ts', '.env.*', 'docker-compose.*.yml', 'stories.*', and 'test_*'. Implementation uses CSS attribute selectors ([data-file-name^=...], [data-file-name$=...], [data-file-name*=...]) on DOM elements instead of adding more CSS class names, following the approach sketched in microsoft#177650. Key changes: - Refactor getIconClasses() to return FileIconInfo { classes, attributes } with data-file-name, data-file-ext, data-folder-name attributes - Add extraAttributes support to IconLabel and ResourceLabel - Generate CSS attribute selectors for glob patterns in fileIconThemeData - Update icon theme JSON schema descriptions to document glob support - Add unit tests for FileIconInfo and glob CSS generation Exact (non-glob) icon theme keys continue to use the existing class-based CSS selectors with no behavioral change. CSS specificity ensures exact matches always beat glob matches.
Contributor
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: @jriekenMatched files:
@rzhao271Matched files:
@alexr00Matched files:
|
Author
|
@microsoft-github-policy-service agree |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #177650 and #12493
Summary
Adds glob pattern support (
*wildcards) to file icon theme associations. Icon theme authors can now use patterns like*.test.ts,webpack.*,.env.*, ortest_*in theirfileNames,fileExtensions,folderNames,folderNamesExpanded,rootFolderNames, androotFolderNamesExpandeddefinitions.Worth mentioning: this doesn't introduce any breaking changes. The extension API continues supporting all existing icon themes, but just adds the glob support on top.
Approach
This follows the CSS attribute selector approach sketched by @aeschli in #177650. The implementation has three layers:
I've renamed
getIconClasses()intogetFileIconInfo(). This fn returnsFileIconInfoinstead of a classesstring[]. The new return type carries both the existing CSS classes and optionaldata-attributes (data-file-name,data-file-ext,data-folder-name) that get set on the DOM element viaIconLabel.fileIconThemeData.tsgenerates CSS attribute selectors for glob keys. When a theme key contains*, the CSS generator produces attribute selectors (^=,$=,*=with case-insensitiveiflag) instead of class-based selectors. Exact keys continue to use the existing class-based system unchanged.Priority ordering is preserved through CSS specificity:
fileNames> globfileNames> exactfileExtensions> globfileExtensions> language matches.name-file-iconspecificity boost; glob matches intentionally omit it so exact entries always win.Examples
An icon theme can now define:
{ "fileNames": { "*.test.ts": "_test_icon", ".env.*": "_env_icon", "docker-compose.*.yml": "_docker_icon" }, "fileExtensions": { "stories.*": "_stories_icon" }, "folderNames": { "test_*": "_test_folder_icon" } }How to test
fileNames,fileExtensions, orfolderNames*.test.tsmatchesapp.test.ts,utils.test.ts)tsconfig.jsonexact match beatstsconfig.*.jsonglob)