Repository: astral-sh/ruff
File: crates/red_knot_workspace/src/workspace/files.rs (Rust)

Code before:
    fn indexed(indexed_files: IndexedFiles) -> Self {
        Self {
            state: std::sync::Mutex::new(State::Indexed(indexed_files)),
        }
    }

    pub fn get(&self) -> Index {
        let state = self.state.lock().unwrap();

        match &*state {
            State::Lazy => Index::Lazy(LazyFiles { files: state }),
            State::Indexed(files) => Index::Indexed(files.clone()),
        }
    }

    pub fn is_lazy(&self) -> bool {
        matches!(*self.state.lock().unwrap(), State::Lazy)
    }

    /// Returns a mutable view on the index that allows cheap in-place mutations.
    ///
    /// The changes are automatically written back to the database once the view is dropped.
    pub fn indexed_mut(db: &mut dyn Db, package: Package) -> Option<IndexedFilesMut> {
        // Calling `runtime_mut` cancels all pending salsa queries. This ensures that there are no pending
        // reads to the file set.
        let _ = db.as_dyn_database_mut().zalsa_mut();

        let files = package.file_set(db);

        let indexed = match &*files.state.lock().unwrap() {
            State::Lazy => return None,
            State::Indexed(indexed) => indexed.clone(),
        };

        Some(IndexedFilesMut {
            db: Some(db),
            package,
            new_revision: indexed.revision,
            indexed,
        })
    }
}

impl Default for PackageFiles {
    fn default() -> Self {
        Self::lazy()
    }
}

#[derive(Debug)]
enum State {

Review comment (suggestion):
I think you might want to update the comment to reflect the change from `runtime_mut`

Code after:
    fn indexed(indexed_files: IndexedFiles) -> Self {
        Self {
            state: std::sync::Mutex::new(State::Indexed(indexed_files)),
        }
    }

    pub fn get(&self) -> Index {
        let state = self.state.lock().unwrap();

        match &*state {
            State::Lazy => Index::Lazy(LazyFiles { files: state }),
            State::Indexed(files) => Index::Indexed(files.clone()),
        }
    }

    pub fn is_lazy(&self) -> bool {
        matches!(*self.state.lock().unwrap(), State::Lazy)
    }

    /// Returns a mutable view on the index that allows cheap in-place mutations.
    ///
    /// The changes are automatically written back to the database once the view is dropped.
    pub fn indexed_mut(db: &mut dyn Db, package: Package) -> Option<IndexedFilesMut> {
        // Calling `zalsa_mut` cancels all pending salsa queries. This ensures that there are no pending
        // reads to the file set.
        // TODO: Use a non-internal API instead https://salsa.zulipchat.com/#narrow/stream/333573-salsa-3.2E0/topic/Expose.20an.20API.20to.20cancel.20other.20queries
        let _ = db.as_dyn_database_mut().zalsa_mut();

        let files = package.file_set(db);

        let indexed = match &*files.state.lock().unwrap() {
            State::Lazy => return None,
            State::Indexed(indexed) => indexed.clone(),
        };

        Some(IndexedFilesMut {
            db: Some(db),
            package,
            new_revision: indexed.revision,
            indexed,
        })
    }
}

impl Default for PackageFiles {
    fn default() -> Self {
        Self::lazy()
    }
}

#[derive(Debug)]