gddo icon indicating copy to clipboard operation
gddo copied to clipboard

show imported packages in example snippets

Open rakyll opened this issue 9 years ago • 9 comments

Examples currently don't include the import paths of the referred packages, thus often requiring the user to refer to the actual example go file to copy paste the correct imports. Including the import path in the snippet can easily improve the case.

rakyll avatar Aug 08 '16 18:08 rakyll

godoc.org so far has generally followed the behavior of cmd/godoc pretty closely. If I understand https://github.com/golang/go/issues/8223 correctly, the cmd/godoc command doesn't do this either, right? If so, are you suggesting that godoc.org deviate in behavior here?

dmitshur avatar Aug 09 '16 02:08 dmitshur

To be clear, both should implement this feature.

rakyll avatar Aug 09 '16 22:08 rakyll

Ah, that makes sense, thanks for clarifying. I'm in agreement with that.

dmitshur avatar Aug 10 '16 05:08 dmitshur

The upstream godoc issue has been addressed by including imports and a surrounding func main() for each example. It would be nice if gddo could mirror this behavior.

zombiezen avatar Mar 22 '19 19:03 zombiezen

The upstream godoc issue has been addressed by including imports and a surrounding func main() for each example. It would be nice if gddo could mirror this behavior.

Can you provide a sample as the docs do not illustrate how to reproduce this?

urandom2 avatar Mar 22 '19 21:03 urandom2

https://golang.org/pkg/crypto/sha256/#example_New_file

zombiezen avatar Mar 22 '19 21:03 zombiezen

The upstream godoc issue has been addressed by including imports and a surrounding func main() for each example.

When/where'd this happen? I can't find the relevant CL.

edit: Is it CL 83615?

broady avatar Mar 22 '19 21:03 broady

I'm having trouble find the CL that introduced this. The reference to "Playable" in the godoc source goes back to 2014: https://golang.org/cl/64910043.

But I can't tell where the func main() business is happening in godoc.

zombiezen avatar Mar 22 '19 22:03 zombiezen

example.html is the template, which extracts the .Output or .Play fields from go/doc.Example. iirc, gddo also uses go/doc, so this change could be ingested.

urandom2 avatar Mar 22 '19 22:03 urandom2