From 17a749533247b6e2d1078ac8ab94da608791afbe Mon Sep 17 00:00:00 2001 From: Danilo Leal <67129314+danilo-leal@users.noreply.github.com> Date: Wed, 5 Feb 2025 13:15:41 -0300 Subject: [PATCH] edit prediction: Fix license detection error logging + check for different spellings (#24281) Follow-up to https://github.com/zed-industries/zed/pull/24278 This PR ensures we're checking if there's a license-type file in both US & UK English spelling, and fixes the error logging again, treating for when the worktree contains just a single file or multiple. Release Notes: - N/A Co-authored-by: Bennet Bo Fenner <53836821+bennetbo@users.noreply.github.com> --- crates/zeta/src/zeta.rs | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/crates/zeta/src/zeta.rs b/crates/zeta/src/zeta.rs index 0be88b3c6a93a2e30fb1c331379da474e3996022..6e68a957c9bd92cccb932ca3b69b97ff5a207d08 100644 --- a/crates/zeta/src/zeta.rs +++ b/crates/zeta/src/zeta.rs @@ -953,20 +953,33 @@ impl LicenseDetectionWatcher { pub fn new(worktree: &Worktree, cx: &mut Context) -> Self { let (mut is_open_source_tx, is_open_source_rx) = watch::channel_with::(false); - let loaded_file_fut = worktree.load_file(Path::new("LICENSE"), cx); + const LICENSE_FILES_TO_CHECK: [&'static str; 2] = ["LICENSE", "LICENCE"]; // US and UK English spelling - Self { - is_open_source_rx, - _is_open_source_task: cx.spawn(|_, _| async move { - let Ok(loaded_file) = loaded_file_fut.await else { - return; - }; + // Check if worktree is a single file, if so we do not need to check for a LICENSE file + let task = if worktree.abs_path().is_file() { + Task::ready(()) + } else { + let loaded_files_task = futures::future::join_all( + LICENSE_FILES_TO_CHECK + .iter() + .map(|file| worktree.load_file(Path::new(file), cx)), + ); - let is_loaded_file_open_source_thing: bool = - is_license_eligible_for_data_collection(&loaded_file.text); + cx.background_executor().spawn(async move { + for loaded_file in loaded_files_task.await { + if let Some(content) = loaded_file.log_err() { + if is_license_eligible_for_data_collection(&content.text) { + *is_open_source_tx.borrow_mut() = true; + break; + } + } + } + }) + }; - *is_open_source_tx.borrow_mut() = is_loaded_file_open_source_thing; - }), + Self { + is_open_source_rx, + _is_open_source_task: task, } }