-
Notifications
You must be signed in to change notification settings - Fork 266
Add "Refs" (find usages) links to definitions #259
Conversation
In general, I agree that being able to easily find usages of an identifier is useful. Especially when docs are unclear or lacking, or usage requires some helpers whose availability is not immediately obvious. Some thoughts:
|
+1 |
I think "Uses" might be a better word. I'm quite happy with the presentation though. WDYT @sqs ? |
Should Godoc start linking to sourcegraph.com? I use godoc offline a lot (in which sourcegraph won't work) and I don't think it should be added to Godoc, but that's just my opinion. |
@adg "Uses" sounds better to me, too. Thanks! @Thomasdezeeuw: Good point. Just to be make sure, you mean
Unless there is a clear preference either way (or other ideas), I will explore the first option and implement that if it is workable. If not, I'll implement the second option. |
This seems okay to me. Sorry for taking so long to get to this. We're using Gerrit now. Care to send a Gerrit review? This change needs to be rebased regardless. If not, then I can re-send this change through Gerrit myself. |
Timed out. |
Actually, we are working on adding this now for all of the repositories we can crawl and making it much faster. Will post an update this week. Sorry for the delay.
|
@sqs will you send a Gerrit change? If so, this can remain closed. |
Will do. 👍
|
Much appreciated. Make sure you send it to adg@golang.org.
|
These links point to Sourcegraph definition info pages that list global uses (from the packages that are indexed). Store value of go/doc.Func.Orig (the original receiver name, see https://godoc.org/go/doc#Func.Orig) when building documentation. Previously, only go/doc.Func.Recv (actual receiver name) was stored. The original receiver name can differ from actual due to struct embedding. This change was originally submitted and OK'd by adg at golang#259.
Each definition's "Uses" link points to the definition's page on Sourcegraph that shows where the definition is used (across all indexed open-source repositories). This lets library users see "usage examples" and gives library authors information about how their library is being used at an API level. It is necessary to store the value of go/doc.Func.Orig (the original receiver name, see https://godoc.org/go/doc#Func.Orig) when building documentation. Previously, only go/doc.Func.Recv (actual receiver name) was stored. The original receiver name can differ from actual due to struct embedding. This change was originally submitted and OK'd by adg at golang#259. A gddo server with this change applied is temporarily available at http://godoc.sgdev.org/.
Each definition's "Uses" link points to the definition's page on Sourcegraph, which shows where the definition is used (across all indexed open-source repositories). This lets library users see "usage examples" and gives library authors information about how their library's API is being used. It is necessary to store the value of go/doc.Func.Orig (the original receiver name, see https://godoc.org/go/doc#Func.Orig) when building documentation. Previously, only go/doc.Func.Recv (actual receiver name) was stored. The original receiver name can differ from actual due to struct embedding. This change was originally submitted and OK'd by adg at golang#259. A gddo server with this change applied is temporarily available at http://godoc.sgdev.org/. Change-Id: Ifa7773b56ccc08c8f063730bdf1fa441d9728d5c
Each definition's "Uses" link points to the definition's page on Sourcegraph, which shows where the definition is used (across all indexed open-source repositories). This lets library users see "usage examples" and gives library authors information about how their library's API is being used. It is necessary to store the value of go/doc.Func.Orig (the original receiver name, see https://godoc.org/go/doc#Func.Orig) when building documentation. Previously, only go/doc.Func.Recv (actual receiver name) was stored. The original receiver name can differ from actual due to struct embedding. This change was originally submitted and OK'd by adg at golang#259. A gddo server with this change applied is temporarily available at http://godoc.sgdev.org/. Change-Id: Ifa7773b56ccc08c8f063730bdf1fa441d9728d5c
Each definition's "Uses" link points to the definition's page on Sourcegraph, which shows where the definition is used (across all indexed open-source repositories). This lets library users see "usage examples" and gives library authors information about how their library's API is being used. It is necessary to store the value of go/doc.Func.Orig (the original receiver name, see https://godoc.org/go/doc#Func.Orig) when building documentation. Previously, only go/doc.Func.Recv (actual receiver name) was stored. The original receiver name can differ from actual due to struct embedding. This change was originally submitted and OK'd by adg at #259. A gddo server with this change applied is temporarily available at http://godoc.sgdev.org/. Change-Id: Ifa7773b56ccc08c8f063730bdf1fa441d9728d5c Reviewed-on: https://go-review.googlesource.com/23380 Reviewed-by: Andrew Gerrand <adg@golang.org>
… methods The godoc.org has a Uses link that redirects to Sourcegraph website for showing the usage/callers of types, functions, and methods. This PR implements the same funcitonality for pkg.go.dev. Much inspired by Quinn's (sqs) PR on gddo (github.com/golang/gddo/pull/259). A short demo can be seen at https://youtu.be/OathLmQVM5g. Fixes #39703
This PR adds unobtrusive "Uses" links for each type, func, and method that show all references to the item (on Sourcegraph). Like the permalink, the Refs link is only displayed on hover.
Viewing usages of a definition is a good way to determine how (best) to use something, especially when the documentation is poor or nonexistent.
Possible improvements/changes:
Disclaimer: I'm one of the creators of Sourcegraph. I think lots of people would find it useful to view usages (and several people asked me to submit this), but I know it'd be a slippery slope to start adding external links to gddo. I'd obviously totally understand if this PR is rejected.
(As an aside, gowalker.org already offers links to examples on Sourcegraph; see bytes.Buffer on gowalker.org, for example. They are quite popular, judging from our site analytics.)
Demo