Repository: astral-sh/ruff
File: crates/ty_project/src/db/changes.rs (Rust)

Code before:
                                // of writing, the file root revision
                                // on a project is used to invalidate
                                // the submodule files found within a
                                // directory. If we bumped the revision
                                // on every change within a project,
                                // then this caching technique would be
                                // effectively useless.
                                //
                                // It's plausible we should explore
                                // a more robust cache invalidation
                                // strategy that models more directly
                                // what we care about. For example, by
                                // keeping track of directories and
                                // their direct children explicitly,
                                // and then keying the submodule cache
                                // off of that instead. ---AG
                                FileRootKind::Project => {}
                                FileRootKind::LibrarySearchPath => {
                                    root.set_revision(self).to(FileRevision::now());
                                }
                            }
                        }

                        // Some LSP clients will send a `change` event for a file
                        // without a `created` event. So we try to detect that
                        // case here.
                        if self.system().is_file(&path)
                            && project.is_file_included(self, &path)
                            && let Some(file) = self.files().try_system(self, &path)
                            && !project.files(self).contains(&file)
                        {
                            // Add the parent directory because `walkdir`
                            // always visits explicitly passed files even if
                            // they match an exclude filter.
                            added_paths.insert(path.parent().unwrap().to_path_buf());
                        }
                    }
                }

                ChangeEvent::Created { kind, path } => {
                    match kind {
                        CreatedKind::File => {
                            if synced_files.insert(path.to_path_buf()) {
                                File::sync_path(self, &path);
                            }
                        }
                        CreatedKind::Directory | CreatedKind::Any => {
                            sync_recursively.insert(path.clone());
                        }
                    }


Review comment (suggestion):
For posterity, it might be useful to expand the comment to include the Neovim workflow as an example which I think is that you open a new unsaved file named "<name>.py" which, because of the `.py` extension, is a Python regular file (and not untitled file) so it's not part of the virtual file set but it also won't be picked up by the project files because it doesn't exists yet.

Code after:
                                // of writing, the file root revision
                                // on a project is used to invalidate
                                // the submodule files found within a
                                // directory. If we bumped the revision
                                // on every change within a project,
                                // then this caching technique would be
                                // effectively useless.
                                //
                                // It's plausible we should explore
                                // a more robust cache invalidation
                                // strategy that models more directly
                                // what we care about. For example, by
                                // keeping track of directories and
                                // their direct children explicitly,
                                // and then keying the submodule cache
                                // off of that instead. ---AG
                                FileRootKind::Project => {}
                                FileRootKind::LibrarySearchPath => {
                                    root.set_revision(self).to(FileRevision::now());
                                }
                            }
                        }
                    }
                }

                ChangeEvent::Created { kind, path } => {
                    match kind {
                        CreatedKind::File => {
                            if synced_files.insert(path.to_path_buf()) {
                                File::sync_path(self, &path);
                            }
                        }
                        CreatedKind::Directory | CreatedKind::Any => {
                            sync_recursively.insert(path.clone());
                        }
                    }

                    // Unlike other files, it's not only important to update the status of existing
                    // and known `File`s (`sync_recursively`), it's also important to discover new files
                    // that were added in the project's root (or any of the paths included for checking).
                    //
                    // This is important because `Project::check` iterates over all included files.
                    // The code below walks the `added_paths` and adds all files that
                    // should be included in the project. We can skip this check for
                    // paths that aren't part of the project or shouldn't be included
                    // when checking the project.

                    if self.system().is_file(&path) {
                        if project.is_file_included(self, &path) {
                            // Add the parent directory because `walkdir`
                            // always visits explicitly passed files even if