From caab22d09173f286fc36f742259894424fbc735e Mon Sep 17 00:00:00 2001 From: Dongdong Zhou Date: Wed, 12 Jun 2024 22:20:30 +0100 Subject: [PATCH] Fix lanaguage from path --- lapce-core/src/language.rs | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/lapce-core/src/language.rs b/lapce-core/src/language.rs index b370da34..b6033733 100644 --- a/lapce-core/src/language.rs +++ b/lapce-core/src/language.rs @@ -1544,11 +1544,14 @@ fn from_path_raw(path: &Path) -> Option { if properties .files .iter() - .zip(properties.extensions) - .any(|(f, e)| { - Some(*f) == filename.as_deref() - || Some(*e) == extension.as_deref() - }) + .any(|f| Some(*f) == filename.as_deref()) + { + return Some(properties.id); + } + if properties + .extensions + .iter() + .any(|e| Some(*e) == extension.as_deref()) { return Some(properties.id); } @@ -1908,3 +1911,16 @@ pub(crate) fn walk_tree_bracket_ast( 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); + } +}