Skip to content

feat: glob icon theme support#311376

Open
PKief wants to merge 4 commits intomicrosoft:mainfrom
PKief:feat/glob-icon-theme-support
Open

feat: glob icon theme support#311376
PKief wants to merge 4 commits intomicrosoft:mainfrom
PKief:feat/glob-icon-theme-support

Conversation

@PKief
Copy link
Copy Markdown

@PKief PKief commented Apr 20, 2026

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.*, or test_* in their fileNames, fileExtensions, folderNames, folderNamesExpanded, rootFolderNames, and rootFolderNamesExpanded definitions.

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:

  1. I've renamed getIconClasses() into getFileIconInfo(). This fn returns FileIconInfo instead of a classes string[]. The new return type carries both the existing CSS classes and optional data- attributes (data-file-name, data-file-ext, data-folder-name) that get set on the DOM element via IconLabel.

  2. fileIconThemeData.ts generates CSS attribute selectors for glob keys. When a theme key contains *, the CSS generator produces attribute selectors (^=, $=, *= with case-insensitive i flag) instead of class-based selectors. Exact keys continue to use the existing class-based system unchanged.

  3. Priority ordering is preserved through CSS specificity:

    • Exact fileNames > glob fileNames > exact fileExtensions > glob fileExtensions > language matches
    • Exact matches get a .name-file-icon specificity 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

  1. Create or modify an icon theme extension with glob patterns in fileNames, fileExtensions, or folderNames
  2. Apply the theme and open a workspace with matching files/folders
  3. Verify that:
    • Glob patterns match the expected files (e.g., *.test.ts matches app.test.ts, utils.test.ts)
    • Exact entries still take priority over glob patterns (e.g., tsconfig.json exact match beats tsconfig.*.json glob)
    • Folder globs work for collapsed, expanded, and root folders

PKief added 4 commits April 20, 2026 16:11
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.
@vs-code-engineering
Copy link
Copy Markdown
Contributor

vs-code-engineering bot commented Apr 20, 2026

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

@jrieken

Matched files:

  • src/vs/editor/contrib/suggest/browser/suggestWidgetRenderer.ts

@rzhao271

Matched files:

  • src/vs/workbench/contrib/preferences/browser/preferencesActions.ts

@alexr00

Matched files:

  • src/vs/workbench/services/dialogs/browser/simpleFileDialog.ts

@PKief PKief changed the title Feat/glob icon theme support feat: glob icon theme support Apr 20, 2026
@PKief
Copy link
Copy Markdown
Author

PKief commented Apr 20, 2026

@microsoft-github-policy-service agree

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.

[icon-themes] explore using attribute selectors to allow name patterns and simplify implementation

2 participants