Fix lanaguage from path

This commit is contained in:
Dongdong Zhou 2024-06-12 22:20:30 +01:00
parent 73a1c79d12
commit caab22d091
1 changed files with 21 additions and 5 deletions

View File

@ -1544,11 +1544,14 @@ fn from_path_raw(path: &Path) -> Option<LapceLanguage> {
if properties if properties
.files .files
.iter() .iter()
.zip(properties.extensions) .any(|f| Some(*f) == filename.as_deref())
.any(|(f, e)| { {
Some(*f) == filename.as_deref() return Some(properties.id);
|| Some(*e) == extension.as_deref() }
}) if properties
.extensions
.iter()
.any(|e| Some(*e) == extension.as_deref())
{ {
return Some(properties.id); return Some(properties.id);
} }
@ -1908,3 +1911,16 @@ pub(crate) fn walk_tree_bracket_ast(
cursor.goto_parent(); cursor.goto_parent();
} }
} }
#[cfg(test)]
mod tests {
use std::path::PathBuf;
use super::LapceLanguage;
#[test]
fn test_lanaguage_from_path() {
let l = LapceLanguage::from_path(&PathBuf::new().join("test.rs"));
assert_eq!(l, LapceLanguage::Rust);
}
}