Add icon support for files without extensions (#8453)

Release Notes:

- Added support for showing file icons for files without suffixes.

Before:

<img width="281" alt="image"
src="https://github.com/zed-industries/zed/assets/25414681/ab4c00ed-72c7-458f-8dda-61c68165590f">


After:

<img width="242" alt="Screenshot 2024-02-27 at 1 51 20 AM"
src="https://github.com/zed-industries/zed/assets/25414681/8f3082c4-9424-4bc3-9100-a527b9adc315">


This screenshot is to show if the file has extension, then the extension
takes precedence.

<img width="193" alt="image"
src="https://github.com/zed-industries/zed/assets/25414681/72fcebd1-361f-444b-8890-f59932963083">


<br>

- Added icons for
    - Docker - https://www.svgrepo.com/svg/473589/docker
    - License - https://www.svgrepo.com/svg/477704/license-1
    - Heroku - https://www.svgrepo.com/svg/341904/heroku
 
 - Updated tests
This commit is contained in:
Sai Gokula Krishnan 2024-02-28 07:06:38 +05:30 committed by GitHub
parent d545fe9fe4
commit bd8896a3dc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 53 additions and 16 deletions

View file

@ -13,6 +13,7 @@ struct TypeConfig {
#[derive(Deserialize, Debug)]
pub struct FileAssociations {
stems: HashMap<String, String>,
suffixes: HashMap<String, String>,
types: HashMap<String, TypeConfig>,
}
@ -38,6 +39,7 @@ impl FileAssociations {
.map_err(Into::into)
})
.unwrap_or_else(|_| FileAssociations {
stems: HashMap::default(),
suffixes: HashMap::default(),
types: HashMap::default(),
})
@ -49,7 +51,14 @@ impl FileAssociations {
// FIXME: Associate a type with the languages and have the file's language
// override these associations
maybe!({
let suffix = path.icon_suffix()?;
let suffix = path.icon_stem_or_suffix()?;
if let Some(type_str) = this.stems.get(suffix) {
return this
.types
.get(type_str)
.map(|type_config| type_config.icon.clone());
}
this.suffixes
.get(suffix)