Repository: astral-sh/ruff
File: crates/ty_server/src/session.rs (Rust)

Code before:
                    return self.projects.range_mut(range).next_back().unwrap().1;
                }

                self.first_project_state_mut()
            }
            AnySystemPath::SystemVirtual(_virtual_path) => self.first_project_state_mut(),
        }
    }

    /// Returns a reference to the project's [`ProjectState`] corresponding to the given path, if
    /// any.
    pub(crate) fn project_state_for_path(
        &self,
        path: impl AsRef<SystemPath>,
    ) -> Option<&ProjectState> {
        self.projects
            .range(..=path.as_ref().to_path_buf())
            .next_back()
            .map(|(_, project)| project)
    }

    // TODO: While ty supports multiple workspace folders, we still
    // need to figure out which project should this virtual path
    // belong to: https://github.com/astral-sh/ty/issues/794 (e.g.
    // look for the first project with an overlapping search path?)
    fn first_project_state(&self) -> &ProjectState {
        self.projects
            .values()
            .next()
            .expect("To always have at least one project")
    }

    fn first_project_state_mut(&mut self) -> &mut ProjectState {
        self.projects.values_mut().next().unwrap()
    }

    pub(crate) fn apply_changes(
        &mut self,
        path: &AnySystemPath,
        changes: Vec<ChangeEvent>,
    ) -> ChangeResult {
        let overrides = path.as_system().and_then(|root| {
            self.workspaces()
                .for_path(root)?
                .settings()
                .project_options_overrides()
                .cloned()
        });

        self.bump_revision();


Review comment (suggestion):
I think I'd prefer that this be called something like `project_state_virtual_fallback` or something similar. And then apply that name to `first_project_state_mut` and also `first_settings`. That way, the name makes its intended use somewhat clearer.

Code after:
                    return self.projects.range_mut(range).next_back().unwrap().1;
                }

                self.project_state_virtual_fallback_mut()
            }
            AnySystemPath::SystemVirtual(_virtual_path) => {
                self.project_state_virtual_fallback_mut()
            }
        }
    }

    /// Returns a reference to the project's [`ProjectState`] corresponding to the given path, if
    /// any.
    pub(crate) fn project_state_for_path(
        &self,
        path: impl AsRef<SystemPath>,
    ) -> Option<&ProjectState> {
        self.projects
            .range(..=path.as_ref().to_path_buf())
            .next_back()
            .map(|(_, project)| project)
    }

    // TODO: While ty supports multiple workspace folders, we still
    // need to figure out which project should this virtual path
    // belong to: https://github.com/astral-sh/ty/issues/794 (e.g.
    // look for the first project with an overlapping search path?)
    fn project_state_virtual_fallback(&self) -> &ProjectState {
        self.projects
            .values()
            .next()
            .expect("To always have at least one project")
    }

    fn project_state_virtual_fallback_mut(&mut self) -> &mut ProjectState {
        self.projects.values_mut().next().unwrap()
    }

    pub(crate) fn apply_changes(
        &mut self,
        path: &AnySystemPath,
        changes: Vec<ChangeEvent>,
    ) -> ChangeResult {
        let overrides = path.as_system().and_then(|root| {
            self.workspaces()
                .for_path(root)?
                .settings()
                .project_options_overrides()
                .cloned()
        });