Skip to content

Make source references for generated builder methods link to original field/parameter location instead of macro callsite #344

@Eisverygoodletter

Description

@Eisverygoodletter

Overview

Make generated builder methods have source links that don't just go to the macro callsite.

Details

This feature request is similar to #57 and follows from #341.

#341 made it so that methods attached to some struct MyStruct, i.e. something along the lines of MyStruct::do_thing(..) -> MyStructDoThingBuilder<...> link to the original definition of MyStruct::do_thing instead of the macro callsite. This has not been implemented for methods on the builder, which is what this feature request covers. For example, consider

use bon::Builder;
#[derive(Builder)]
struct MyStruct {
    property: i32,
}

The generated docs for MyStructBuilder::property(self, value: i32) -> MyStructBuilder<SetProperty<S>> link to the callsite line

#[derive(Builder)]

instead of the line where property came from

    property: i32,

. This issue is also present with params, with

#[bon]
impl MyStruct {
    #[builder]
    pub fn many_params(
        a: i32,
        b: i32,
        c: i32
    ) -> i32 {
        a + b + c
    }
}

Generating a a(self, value: i32) -> ThingManyParamsBuilder<SetA<S>> which links to callsite

#[bon]

instead of the line where param a was defined

         a: i32,

Examples

An example can be seen at https://docs.rs/remoteit-api/latest/remoteit_api/struct.R3ClientBuilder.html#method.credentials where clicking the "Source" links to https://docs.rs/remoteit-api/latest/src/remoteit_api/lib.rs.html#83 instead of https://docs.rs/remoteit-api/latest/src/remoteit_api/lib.rs.html#85.

Additional note

I'm not sure how easy or consistent implementing this will be. Based off implementing #341 it might be as easy as just keeping a span around, but I'm not sure given that we will need to traverse each parameter name and struct field to get the spans.

Metadata

Metadata

Assignees

No one assigned

    Labels

    papercutA non-critical issue that is annoying

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions