Repository: astral-sh/ruff
File: crates/ty_ide/src/completion.rs (Rust)

Code before:
    pub builtin: bool,
    /// Whether this item only exists for type checking purposes and
    /// will be missing at runtime
    pub is_type_check_only: bool,
    /// Whether this item can definitively be used in the current context.
    ///
    /// Some completions are computed based on contextual information.
    /// If that's the case, we know this is a very precise completion
    /// that should always be valid and can be preferred when
    /// ordering completions.
    pub is_context_specific: bool,
    /// The documentation associated with this item, if
    /// available.
    pub documentation: Option<Docstring>,
    /// Information used to sort this completion relative to others
    /// in the same collection.
    relevance: Relevance,
}

impl<'db> Completion<'db> {
    fn builder(name: impl Into<Name>) -> CompletionBuilder<'db> {
        CompletionBuilder::new(name)
    }
}

#[expect(clippy::struct_excessive_bools)]
/// A builder for construction a `Completion`.
#[derive(Debug)]
struct CompletionBuilder<'db> {
    // See comments on `Completion` for the meaning of fields.
    name: Name,
    qualified: Option<Name>,
    insert: Option<Name>,
    ty: Option<Type<'db>>,
    kind: Option<CompletionKind>,
    module_name: Option<&'db ModuleName>,
    import: Option<Edit>,
    builtin: bool,
    is_context_specific: bool,
    is_type_check_only: bool,
    documentation: Option<Docstring>,
    module_dependency_kind: Option<ModuleDependencyKind>,
    deprecated: bool,
}

impl<'db> CompletionBuilder<'db> {
    /// Start building a new completion with the given name.
    ///
    /// All other values given to the completion by default are
    /// valid, but callers will generally want to fill in as much
    /// as is appropriate.

Review comment (refactor):
Can you move this down below the `#[derive(...)]`? It's IMO weird to put it above the comment (even though it's valid to do so).

Code after:
    pub builtin: bool,
    /// Whether this item only exists for type checking purposes and
    /// will be missing at runtime
    pub is_type_check_only: bool,
    /// Whether this item can definitively be used in the current context.
    ///
    /// Some completions are computed based on contextual information.
    /// If that's the case, we know this is a very precise completion
    /// that should always be valid and can be preferred when
    /// ordering completions.
    pub is_context_specific: bool,
    /// The documentation associated with this item, if
    /// available.
    pub documentation: Option<Docstring>,
    /// Information used to sort this completion relative to others
    /// in the same collection.
    relevance: Relevance,
}

impl<'db> Completion<'db> {
    fn builder(name: impl Into<Name>) -> CompletionBuilder<'db> {
        CompletionBuilder::new(name)
    }
}

/// A builder for construction a `Completion`.
#[derive(Debug)]
#[expect(clippy::struct_excessive_bools)]
struct CompletionBuilder<'db> {
    // See comments on `Completion` for the meaning of fields.
    name: Name,
    qualified: Option<Name>,
    insert: Option<Name>,
    ty: Option<Type<'db>>,
    kind: Option<CompletionKind>,
    module_name: Option<&'db ModuleName>,
    import: Option<Edit>,
    builtin: bool,
    is_context_specific: bool,
    is_type_check_only: bool,
    documentation: Option<Docstring>,
    module_dependency_kind: Option<ModuleDependencyKind>,
    deprecated: bool,
}

impl<'db> CompletionBuilder<'db> {
    /// Start building a new completion with the given name.
    ///
    /// All other values given to the completion by default are
    /// valid, but callers will generally want to fill in as much
    /// as is appropriate.