-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Closed
Labels
FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.The path to resolution is known, but the work has not been done.Proposal-Accepted
Milestone
Description
The doc package currently provides:
func Examples(files ...*ast.File) []*ExampleGiven a set of source files, this only parses out the examples as a flat list.
However, the testing package documents a syntax of how to associate examples with:
- A package (e.g.,
ExampleorExample_suffix) - A function (e.g.,
ExampleForExampleF_suffix) - A type (e.g.,
ExampleTorExampleT_suffix) - A method (e.g.,
ExampleT_MorExampleT_M_suffix)
As the number of tools that provide godoc-like functionality increases, the manual logic to parse these example names and associate it with the appropriate top-level declaration is somewhat tedious and easy to get wrong.
Given that this syntax is documented, I propose that the doc package provide first-class support for doing this association. The additional functionality is as follows:
Newuses theast.Package.Filesinput to produce an internal[]Example.- An
Examples []Examplefield is added to thePackage,Type, andFunctypes. They are populated as appropriate according to what the relevant examples are associated with. - Examples that do not follow the example syntax or reference an non-existent declaration could be either ignored or just associated with the entire package.
\cc @griesemer
jimmyfrasche, ericlagergren and dmitshur
Metadata
Metadata
Assignees
Labels
FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.The path to resolution is known, but the work has not been done.Proposal-Accepted