Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
file_icons: Resolve icon for files with stem-based name (#51891)
Bryan Pothon80f1bb45fa5b
diff --git a/crates/file_icons/src/file_icons.rs b/crates/file_icons/src/file_icons.rsindex 6524089eecb..6acd9d1c13f 100644--- a/crates/file_icons/src/file_icons.rs+++ b/crates/file_icons/src/file_icons.rs@@ -38,7 +38,7 @@ impl FileIcons {// TODO: Associate a type with the languages and have the file's language// override these associations- if let Some(mut typ) = path.file_name().and_then(|typ| typ.to_str()) {+ if let Some(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);@@ -46,14 +46,27 @@ impl FileIcons {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 let Some((stem, mut suffix)) = typ.split_once('.') {+ // check if stem (before first dot) is in stems+ // e.g. catch file named `Dockerfile.prod` or `Podfile.lock`+ let maybe_path = get_icon_from_suffix(stem);if maybe_path.is_some() {return maybe_path;}- typ = suffix;++ loop {+ // 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`+ let maybe_path = get_icon_from_suffix(suffix);+ if maybe_path.is_some() {+ return maybe_path;+ }++ let Some((_, next_suffix)) = suffix.split_once('.') else {+ break;+ };+ suffix = next_suffix;+ }}}