From cf0e17dcc779083de74b7b8a724ecf8814ec3157 Mon Sep 17 00:00:00 2001 From: tinyleolin <44769204+tinyleolin@users.noreply.github.com> Date: Wed, 2 Jul 2025 14:40:08 +0800 Subject: [PATCH] canonicalize file path before check excluding --- crates/emmylua_code_analysis/src/config/mod.rs | 11 ++++++++--- crates/emmylua_code_analysis/src/vfs/loader.rs | 4 +++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/crates/emmylua_code_analysis/src/config/mod.rs b/crates/emmylua_code_analysis/src/config/mod.rs index 4a9f380bb..e453bf686 100644 --- a/crates/emmylua_code_analysis/src/config/mod.rs +++ b/crates/emmylua_code_analysis/src/config/mod.rs @@ -121,6 +121,11 @@ fn pre_process_path(path: &str, workspace: &Path) -> String { path = replace_placeholders(&path, workspace_str); + fn canonicalize_path(path_buf: PathBuf) -> String { + let new_path_buf = path_buf.canonicalize().unwrap_or(path_buf); + new_path_buf.to_string_lossy().to_string() + } + if path.starts_with('~') { let home_dir = match dirs::home_dir() { Some(path) => path, @@ -129,13 +134,13 @@ fn pre_process_path(path: &str, workspace: &Path) -> String { return path; } }; - path = home_dir.join(&path[1..]).to_string_lossy().to_string(); + path = canonicalize_path(home_dir.join(&path[1..])); } else if path.starts_with("./") { - path = workspace.join(&path[2..]).to_string_lossy().to_string(); + path = canonicalize_path(workspace.join(&path[2..])); } else if PathBuf::from(&path).is_absolute() { path = path.to_string(); } else { - path = workspace.join(&path).to_string_lossy().to_string(); + path = canonicalize_path(workspace.join(&path)); } path diff --git a/crates/emmylua_code_analysis/src/vfs/loader.rs b/crates/emmylua_code_analysis/src/vfs/loader.rs index 62cb84dc0..40a752128 100644 --- a/crates/emmylua_code_analysis/src/vfs/loader.rs +++ b/crates/emmylua_code_analysis/src/vfs/loader.rs @@ -61,7 +61,9 @@ pub fn load_workspace_files( .filter(|e| e.file_type().is_file()) { let path = entry.path(); - if exclude_dir.iter().any(|dir| path.starts_with(dir)) { + let raw_path_buf = path.to_path_buf(); + let path_buf = raw_path_buf.canonicalize().unwrap_or(raw_path_buf); + if exclude_dir.iter().any(|dir| path_buf.starts_with(dir)) { continue; }