Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make v3 examples runnable on pkg.go.dev #1811

Closed
3 tasks done
matthewdale opened this issue Sep 2, 2023 · 2 comments · Fixed by #1812
Closed
3 tasks done

Make v3 examples runnable on pkg.go.dev #1811

matthewdale opened this issue Sep 2, 2023 · 2 comments · Fixed by #1812
Labels
area/v3 relates to / is being considered for v3 status/triage maintainers still need to look into this

Comments

@matthewdale
Copy link
Contributor

Checklist

  • Are you running the latest v3 release? The list of releases is here.
  • Did you check the manual for your release? The v3 manual is here.
  • Did you perform a search about this feature? Here's the GitHub guide about searching.

What problem does this solve?

The v3 examples are not runnable in the pkg.go.dev documentation. For example, see the Command.Run example.

This is probably caused by a bug in the go/doc example parser, which doesn't handle major version suffixes when resolving package import symbols right now. See golang/go#62059 for more details.

Solution description

Use an import alias in files with testable examples so that the go/doc example parser (used to extract and render examples on pkg.go.dev) can resolve the package import symbols.

E.g.

import cli "github.com/urfave/cli/v3"

Describe alternatives you've considered

The examples not being runnable is probably caused by a bug in the go/doc example AST parser, which doesn't handle major version suffixes when resolving import symbols right now. An alternative is to fix that bug. See golang/go#62059 for that bug report.

@matthewdale matthewdale added area/v3 relates to / is being considered for v3 status/triage maintainers still need to look into this labels Sep 2, 2023
@matthewdale matthewdale changed the title Make v3 examples runnable Make v3 examples runnable on pkg.go.dev Sep 2, 2023
@abitrolly
Copy link
Contributor

The examples not being runnable is probably caused by a bug in the go/doc example AST parser, which doesn't handle major version suffixes when resolving import symbols right now.

Is it possible to construct Go playground snippet to validate this bug?

@matthewdale
Copy link
Contributor Author

@abitrolly Here's an example of trying to extract runnable doc examples from two sample Go test files: https://go.dev/play/p/V8RY15XlJZy

I believe that demonstrates the bug. While it makes sense that doc.Examples can't find a symbol for the cli package when it ends in v3, ending in v3 is a requirement of the Go modules system. Seems like the go/doc package should know how to handle major version suffixes since they're required, hence my suggestion that it's a bug (or at least missing feature) in go/doc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/v3 relates to / is being considered for v3 status/triage maintainers still need to look into this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants