Fix incorrect assumption about Path.extension() (#24443)

Release Notes:

- N/A
This commit is contained in:
Ben Kunkle 2025-02-07 09:37:07 -06:00 committed by GitHub
parent 4f65cfa93d
commit a1544f47ad
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -659,7 +659,10 @@ impl LanguageRegistry {
user_file_types: Option<&HashMap<Arc<str>, GlobSet>>,
) -> Option<AvailableLanguage> {
let filename = path.file_name().and_then(|name| name.to_str());
let extension = path.extension().and_then(|ext| ext.to_str());
// `Path.extension()` returns None for files with a leading '.'
// and no other extension which is not the desired behavior here,
// as we want `.zshrc` to result in extension being `Some("zshrc")`
let extension = filename.and_then(|filename| filename.split('.').last());
let path_suffixes = [extension, filename, path.to_str()];
let empty = GlobSet::empty();