Skip to content

[icon-themes] Support glob keys in file icon associations #174286

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 55 commits into
base: main
Choose a base branch
from

Conversation

zm-cttae
Copy link

@zm-cttae zm-cttae commented Feb 13, 2023

Closes #12493.

Background

The feature request is for glob support in the key of icon mappings for file icon themes

This PR allows multiple use cases - see table:

Key to target a file or folder Example filename
* Makefile, Dockerfile
Jenkinsfile.* Jenkinsfile.prod
test_*.py test_component.py
*_test.go component_test.go
*Test.cs CalculatorTest.cs
.env.* .env.development
web.*.config web.prod.config
webpack.*.config.js webpack.dev.config.js
*.webpack.config.js shared.dev.webpack.config.js
.env.*.* .env.development.docker.example.env
*.md pop goes ...................................... the weasel.md

Specification

File icon theme keys are separated by the last dot into basename and ext.

The basename segment allows any number of . characters.

Both segments can be globbed like so:

  • Wildcard glob * accepts any value.
  • Prefix glob prefix*.
  • Suffix glob *suffix.
  • Prefix-suffix glob *middle*.
  • Middle glob prefix*suffix

Implementation

File/folder icon association keys that can be augmented by globs: folderNamesfolderNamesExpandedfileNames

Any * in the key of the file/folder icon mapping:

  • generates a different CSS attribute selector for basename and/or extname attr values in the file icon theme
  • removes the +2 score boost contributed by the name class

This PR introduces extraAttributes option to icon label APIs. These attributes are anchors that the CSS from the file icon theme side can target. This is necessary to prevent a FOUC after opening any collapsed folder or any text document, caused by file icon themes running 100s of globs per each file label.

EDIT:

This was updated to remove ** from this spec and sync with vscode.GlobPattern spec.
It previously meant >=2 dot segments - #174286 (comment)

EDIT 2:

Apply changeset from #174286 (comment)

EDIT 3:

Redesign implementation in line with #177650 - moves business logic of globs back to the frontend

@zm-cttae
Copy link
Author

@microsoft-github-policy-service agree

@aeschli
Copy link
Contributor

aeschli commented Feb 14, 2023

Can you explain what css classes you generate?

@zm-cttae
Copy link
Author

Done in PR description

@zm-cttae
Copy link
Author

While we are here:

@aeschli
Copy link
Contributor

aeschli commented Feb 14, 2023

Sorry, can you give examples how this works (maybe a table covering the various cases, prefix, suffix, **)

  • file/folder pattern in the icon theme
  • all classes in the css rules that are generated

Give some example of resources in the explorer and how the class names match. The tricky part is that file name matches are always stronger than file extension matches and stronger than fold name matches.

@zm-cttae

This comment was marked as outdated.

@zm-cttae
Copy link
Author

Now ready for review

@zm-cttae
Copy link
Author

Made some small tweaks in my work lunch, but please feel free to review now @aeschli

@aeschli
Copy link
Contributor

aeschli commented Feb 14, 2023

ok, now I understand. So * is only possible at the beginning or end of dot, underscore or minus separated segments.

The problem is to make sure the matching order holds:

'full file match' beats 'file match with pattern' beats 'file extension match' beats 'file extension with pattern' beats language beats folder name beats folder name with

How this is implemented is the number of classes matching

IMO we're at a dead end with CSS class name matching. I'm reluctant in adding even more class names.

@zm-cttae zm-cttae marked this pull request as draft February 14, 2023 15:11
@zm-cttae
Copy link
Author

zm-cttae commented Feb 14, 2023

NB: I wanted to add an extra level of depth in generating folderNamesfolderNamesExpandedfileNames but its not needed
I've had a change of tack ("let's use name-${kind}-icon") and we can bypass this issue in a saner manner

Refs: [#issuecomment-1429874059](github.com/microsoft/pull/174286#issuecomment-1429874059)
@zm-cttae zm-cttae marked this pull request as ready for review February 14, 2023 16:26
@zm-cttae

This comment was marked as outdated.

@zm-cttae zm-cttae changed the title Support globs in file icon themes [icon-themes] Support globs in file icon associations Feb 14, 2023
@zm-cttae zm-cttae force-pushed the feat-file-icon-theme-glob branch from 344562d to 6cf396e Compare November 10, 2024 20:57
@zm-cttae zm-cttae marked this pull request as ready for review November 10, 2024 21:26
@adreo00
Copy link

adreo00 commented Jan 23, 2025

Looking forward to this PR merging!

@zm-cttae zm-cttae marked this pull request as ready for review March 16, 2025 10:15
@aeschli
Copy link
Contributor

aeschli commented Mar 17, 2025

@zm-cttae Thanks for all the work.

I didn't realize the ripples we get from adding extraAttributes.
getIconClasses needs to return typed object, e.g. FileIconInfo, that we keep as long as possible,

I think its best to tackle that first, in a separate PR.

@zm-cttae
Copy link
Author

zm-cttae commented Mar 17, 2025

I take it the signature is, then will be { classes, [attributes ...] }?

@arkthur
Copy link

arkthur commented Jun 19, 2025

Hi! Thanks for all the work done so far.
That said, is there anything I can help with? What is stalling this?

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] Support for globs in file associations (Icon themes)
10 participants