mirror of https://github.com/lapce/lapce.git
fix file language detection from path
detection was broken due to Option's returning early on file_stem() and extension()
This commit is contained in:
parent
890438883e
commit
d4c562fcae
|
@ -1532,13 +1532,23 @@ pub fn from_path(path: &Path) -> LapceLanguage {
|
|||
}
|
||||
|
||||
fn from_path_raw(path: &Path) -> Option<LapceLanguage> {
|
||||
let filename = path.file_stem()?.to_str()?.to_lowercase();
|
||||
let extension = path.extension()?.to_str()?.to_lowercase();
|
||||
let filename = path
|
||||
.file_stem()
|
||||
.and_then(|s| s.to_str().map(|s| s.to_lowercase()));
|
||||
let extension = path
|
||||
.extension()
|
||||
.and_then(|s| s.to_str().map(|s| s.to_lowercase()));
|
||||
// NOTE: This is a linear search. It is assumed that this function
|
||||
// isn't called in any tight loop.
|
||||
for properties in LANGUAGES {
|
||||
if properties.files.contains(&filename.as_str())
|
||||
|| properties.extensions.contains(&extension.as_str())
|
||||
if properties
|
||||
.files
|
||||
.iter()
|
||||
.zip(properties.extensions)
|
||||
.any(|(f, e)| {
|
||||
Some(*f) == filename.as_deref()
|
||||
|| Some(*e) == extension.as_deref()
|
||||
})
|
||||
{
|
||||
return Some(properties.id);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue