Add glob support for custom file type language (#12043)

Release Notes:

- Added glob support for file_types configuration
([#10765](https://github.com/zed-industries/zed/issues/10765)).

`file_types` can now be written like this:

```json
"file_types": {
  "Dockerfile": [
    "Dockerfile",
    "Dockerfile.*",
  ]
}
```
This commit is contained in:
Joshua Farayola 2024-05-20 09:13:35 +01:00 committed by GitHub
parent 4e935f9f0f
commit ab7ce32888
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 39 additions and 15 deletions

View file

@ -184,6 +184,10 @@ async fn test_language_for_file_with_custom_file_types(cx: &mut TestAppContext)
settings.file_types.extend([
("TypeScript".into(), vec!["js".into()]),
("C++".into(), vec!["c".into()]),
(
"Dockerfile".into(),
vec!["Dockerfile".into(), "Dockerfile.*".into()],
),
]);
})
});
@ -223,6 +227,14 @@ async fn test_language_for_file_with_custom_file_types(cx: &mut TestAppContext)
},
..Default::default()
},
LanguageConfig {
name: "Dockerfile".into(),
matcher: LanguageMatcher {
path_suffixes: vec!["Dockerfile".to_string()],
..Default::default()
},
..Default::default()
},
] {
languages.add(Arc::new(Language::new(config, None)));
}
@ -237,6 +249,11 @@ async fn test_language_for_file_with_custom_file_types(cx: &mut TestAppContext)
.await
.unwrap();
assert_eq!(language.name().as_ref(), "C++");
let language = cx
.read(|cx| languages.language_for_file(&file("Dockerfile.dev"), None, cx))
.await
.unwrap();
assert_eq!(language.name().as_ref(), "Dockerfile");
}
fn file(path: &str) -> Arc<dyn File> {