From 8abf93f5fbce74232432421c59b1ba5d24dd17d4 Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Wed, 23 Apr 2025 15:32:41 +0200 Subject: [PATCH] [red-knot] Early return from `project.is_file_open` for vendored files (#17580) --- crates/red_knot_project/src/lib.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/crates/red_knot_project/src/lib.rs b/crates/red_knot_project/src/lib.rs index fd6545972a..8393aec663 100644 --- a/crates/red_knot_project/src/lib.rs +++ b/crates/red_knot_project/src/lib.rs @@ -314,20 +314,23 @@ impl Project { /// * It has a [`SystemPath`] and belongs to a package's `src` files /// * It has a [`SystemVirtualPath`](ruff_db::system::SystemVirtualPath) pub fn is_file_open(self, db: &dyn Db, file: File) -> bool { + let path = file.path(db); + + // Try to return early to avoid adding a dependency on `open_files` or `file_set` which + // both have a durability of `LOW`. + if path.is_vendored_path() { + return false; + } + if let Some(open_files) = self.open_files(db) { open_files.contains(&file) } else if file.path(db).is_system_path() { - self.contains_file(db, file) + self.files(db).contains(&file) } else { file.path(db).is_system_virtual_path() } } - /// Returns `true` if `file` is a first-party file part of this package. - pub fn contains_file(self, db: &dyn Db, file: File) -> bool { - self.files(db).contains(&file) - } - #[tracing::instrument(level = "debug", skip(self, db))] pub fn remove_file(self, db: &mut dyn Db, file: File) { tracing::debug!(