Enhance icon detection for files with custom suffixes (#34170)

Fixes custom file suffixes (module.ts) of some icon themes like: 

- **Symbols Icon Theme** 
<img width="212" alt="image"
src="https://github.com/user-attachments/assets/419ba1b4-9d8e-46cd-891b-62fb63a8c5ae"
/>

- **Bearded Icon Theme**
<img width="209" alt="image"
src="https://github.com/user-attachments/assets/72974fce-fa72-4368-8d96-7feea7b59b7a"
/>

Release Notes:

- Fixed icon detection for files with custom suffixes like `module.ts`
that are overwritten by the language's icon `.ts`
This commit is contained in:
Gilmar Sales 2025-08-13 12:59:59 -03:00 committed by GitHub
parent 23cd5b59b2
commit 6c1f19571a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -33,13 +33,23 @@ impl FileIcons {
// TODO: Associate a type with the languages and have the file's language
// override these associations
// check if file name is in suffixes
// e.g. catch file named `eslint.config.js` instead of `.eslint.config.js`
if let Some(typ) = path.file_name().and_then(|typ| typ.to_str()) {
if let Some(mut typ) = path.file_name().and_then(|typ| typ.to_str()) {
// check if file name is in suffixes
// e.g. catch file named `eslint.config.js` instead of `.eslint.config.js`
let maybe_path = get_icon_from_suffix(typ);
if maybe_path.is_some() {
return maybe_path;
}
// check if suffix based on first dot is in suffixes
// e.g. consider `module.js` as suffix to angular's module file named `auth.module.js`
while let Some((_, suffix)) = typ.split_once('.') {
let maybe_path = get_icon_from_suffix(suffix);
if maybe_path.is_some() {
return maybe_path;
}
typ = suffix;
}
}
// primary case: check if the files extension or the hidden file name