Add PathExt trait (#2823)

This PR adds a `PathExt` trait. It pulls in our existing `compact()`
function, as a method, and then adds a method, and testing, for
`icon_suffix()`. A test was added to fix:

- https://github.com/zed-industries/community/issues/1877

Release Notes:

- Fixed a bug where file icons would not be registered for files with
with `.` characters in their name
([#1877](https://github.com/zed-industries/community/issues/1877)).
This commit is contained in:
Joseph T. Lyons 2023-08-03 18:57:43 -04:00 committed by GitHub
parent ad4fd7619b
commit ee1b4a52cc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 88 additions and 56 deletions

View file

@ -4,7 +4,7 @@ use collections::HashMap;
use gpui::{AppContext, AssetSource};
use serde_derive::Deserialize;
use util::iife;
use util::{iife, paths::PathExt};
#[derive(Deserialize, Debug)]
struct TypeConfig {
@ -48,14 +48,7 @@ impl FileAssociations {
// FIXME: Associate a type with the languages and have the file's langauge
// override these associations
iife!({
let suffix = path
.file_name()
.and_then(|os_str| os_str.to_str())
.and_then(|file_name| {
file_name
.find('.')
.and_then(|dot_index| file_name.get(dot_index + 1..))
})?;
let suffix = path.icon_suffix()?;
this.suffixes
.get(suffix)