vscode-go icon indicating copy to clipboard operation
vscode-go copied to clipboard

Add an action to copy a link to a file in the online repository for a module dependency

Open YesYouKenSpace opened this issue 11 months ago • 9 comments

Is your feature request related to a problem? Please describe. I would like to share reference to lines of code in public repository of imported packages when discussing issues with my teammates.

Describe the solution you'd like It would be nice to have an action item in the context menu under Copy As > Copy link to remote repository image

Describe alternatives you've considered

Additional context

YesYouKenSpace avatar Jan 09 '25 06:01 YesYouKenSpace

Hi YesYouKenSpace,

I find a tool offered from GitLens. I'm not sure if this is something you are looking for. If you configured correctly, you will find options below.

image

But this is limited to understanding your repo allow you to customize the repo url with file, line and range parameter. It does not understand the library you imported in your repo unless you vendor them (make those as part of your repo). But standard lib is always out of reach because it can not be vendored.

h9jiang avatar Jan 09 '25 17:01 h9jiang

I think what they mean is: If I open a file from the module cache (for example by using "Go to definition" on an imported type), I want a "Copy link to file" menu option that links to the online repository for that package. I don't think GitLens can solve this because the module cache files aren't git repositories.

@YesYouKenSpace If I'm correct this would be tricky to handle in the general case. Obviously if the module starts with github.com it's not that hard to determine a browsable URL for that file. However supporting other providers would require a go-get query for each module and that only works if the provider includes a go-source meta tag.

firelizzard18 avatar Jan 09 '25 19:01 firelizzard18

Timed out in state WaitingForInfo. Closing.

(I am just a bot, though. Please speak up if this is a mistake or you have the requested information.)

gopherbot avatar Feb 09 '25 17:02 gopherbot

@firelizzard18 yeap you are right that is what i meant. I think even if supporting just the common code hosting sites is good enough for most open source projects. Already makes it easier to reference open source libraries.

YesYouKenSpace avatar Feb 11 '25 03:02 YesYouKenSpace

@h9jiang thank you for pointing out gitlens. I do have gitlens too and i was unable to refer to the lib that are imported.

YesYouKenSpace avatar Feb 11 '25 03:02 YesYouKenSpace

@YesYouKenSpace Can you clarify when you want this option to appear? I can think of multiple scenarios. I had been thinking when you right click the file tab after opening a file from the module cache as in [right click method/etc] -> [go to definition] -> [right click file tab] -> [copy link] but from your screenshot it looks like you want this option to appear when right clicking a definition, as in [right click method/etc] -> [copy link] as an alternative to [go to definition].

firelizzard18 avatar Feb 11 '25 05:02 firelizzard18

@firelizzard18 i expect it to be available at a right click on any line within a file of the module cache. I believe that to be the most intuitive.

I imagine myself navigating in the team codebase and then travelling to the public library definition and finding a piece of code in the module cache that explains a behaviour and wanting to link my teammates to that line.

YesYouKenSpace avatar Feb 11 '25 05:02 YesYouKenSpace

That's sufficiently clear. The request is:

  • As a user, when I open a file within the module cache, I want a context menu option to copy a link to the online repository for that file.
  • For example, if I open ~/go/pkg/mod/github.com/spf13/[email protected]/command.go (e.g. by Go to Definition) and I right click, I want a context menu option that will place https://github.com/spf13/cobra/blob/v1.8.1/command.go on the clipboard, ideally with #LXX for the line number I right clicked on.

As far as implementation, it should be relatively straightforward for github, gitlab, and other well-known providers. Supporting arbitrary providers (e.g. custom GitLab deployments such as https://gitlab.freedesktop.org/) will require checking for a go-source meta tag with a go-get query as I mentioned before https://github.com/golang/vscode-go/issues/3656#issuecomment-2581077483.

firelizzard18 avatar Feb 11 '25 20:02 firelizzard18

Thank you good sir @firelizzard18, ah yes i probably should have just started with a user story.

YesYouKenSpace avatar Feb 12 '25 04:02 YesYouKenSpace