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

Link from VS to Github in Browser #106

Closed
avanderhoorn opened this Issue Sep 25, 2015 · 23 comments

Comments

Projects
None yet
8 participants
@avanderhoorn

Request
I would love for a feature to be added where I could right click on a given line and either open the browser up at that line for the given branch on Github and/or copy the link to my clipboard.

Background
In a given day I've lost count of how often I am talking to someone remotely (via twitter/skype/slack/etc) and I'm wanting to reference a line of code and the easiest way to do that is get the file up on Github... from that decision to the point where I find the relevant file/line and get the link is a good 30-60sec of time and like at east 5-10 clicks and a major context switch.

Current Workflow
I have to:

  1. switch to the browser
  2. open a new tab
  3. type in the url for the repo
  4. switch to the right branch
  5. hit t, type in the name of the class
  6. hit enter (if its the first result)
  7. then scroll through a file which could have 200-500 lines of code for the specific line I'm referencing
  8. click the line that I'm interested in
  9. copy the link
  10. finally I get to continue on

Logic
Github for VS already knows if I have a git repo, if that repo origin is github and what branch I'm on. From there, it should be reasonable to think that a URL for that exact spot should be able to be generated.

Edge Cases

  • If the github repo/branch doesn't have the same version of the file that I do or if the file/branch doesn't exist at all
    • To start with I would expect that this feature would just generate the link without doing any verification... For my cases, this is almost never the case and when this does happen I'm usually know whether I've pushed the changes up or not
    • In the future, you could do a diff between what the known state of the origin is locally and see if that is going to cause a conflict or affect the link you would generate... this still isn't perfect but percentage wise deal with most of the edge cases
    • In the future future, you could do a check against what the actual state for the remote repo is... In practice this isn't likely to work all that well due to the latency of the check

I wouldn't let the above stop the feature, because as I mentioned, I usually am aware of the state of changes I've made and even if its not exact, usually getting me within range of the correct line saves me a ton of work.

Other IDEs and Text Editors
This isn't specific to VS, the same feature makes sense in @atom, VS Code, etc, etc

@dalpert-korewireless

This comment has been minimized.

Show comment
Hide comment

I'd love this!

@matthewkimber

This comment has been minimized.

Show comment
Hide comment
@matthewkimber

matthewkimber Sep 25, 2015

That would be awesome!

That would be awesome!

@nosami

This comment has been minimized.

Show comment
Hide comment
@nosami

nosami Sep 25, 2015

Xamarin Studio has this
screen shot 2015-09-25 at 21 59 58

nosami commented Sep 25, 2015

Xamarin Studio has this
screen shot 2015-09-25 at 21 59 58

@wwwlicious

This comment has been minimized.

Show comment
Hide comment
@wwwlicious

wwwlicious Sep 25, 2015

+1 would be great to have this

+1 would be great to have this

@shana

This comment has been minimized.

Show comment
Hide comment
@shana

shana Sep 28, 2015

Collaborator

Thanks for the awesome suggestion! 👍

Collaborator

shana commented Sep 28, 2015

Thanks for the awesome suggestion! 👍

@shana shana added the feature label Sep 28, 2015

@shana shana added the help wanted label Nov 24, 2015

@shana

This comment has been minimized.

Show comment
Hide comment
@shana

shana Nov 24, 2015

Collaborator

BTW, there's already code in place to handle menus and commands. The package adds context menus in the "Connections" area like this - https://github.com/github/VisualStudio/blob/master/src/GitHub.VisualStudio/GitHubPackage.cs#L51

Collaborator

shana commented Nov 24, 2015

BTW, there's already code in place to handle menus and commands. The package adds context menus in the "Connections" area like this - https://github.com/github/VisualStudio/blob/master/src/GitHub.VisualStudio/GitHubPackage.cs#L51

@austin94

This comment has been minimized.

Show comment
Hide comment
@austin94

austin94 Jan 6, 2016

@shana @avanderhoorn Has this feature been implemented yet? I'm willing to make a PR for this if no one else has started.

austin94 commented Jan 6, 2016

@shana @avanderhoorn Has this feature been implemented yet? I'm willing to make a PR for this if no one else has started.

@avanderhoorn

This comment has been minimized.

Show comment
Hide comment
@avanderhoorn

avanderhoorn Jan 6, 2016

As far as I know, no work has started on this.

As far as I know, no work has started on this.

@shana

This comment has been minimized.

Show comment
Hide comment
@shana

shana Jan 7, 2016

Collaborator

Happy new year everyone!

Indeed, work has not been started on this. Not enough hands and omg I needed a rest after last year! I would LOVE a PR on this, these are the little things that really make coding easier.

I've created a new branch for this feature and added some things you will need to get this working, to start with: https://github.com/github/VisualStudio/tree/feature/link-to-vs. The branch adds the "Get Link" context menu and a handler for it, and gets the file name and line from VS, as an example.
You can create a PR targeting this branch and base your work on it 😄

Here's some thoughts on how to do this:


The link can be to a commit hash, so no need for branch information. No need to even check if the local file matches the remote version, I agree, just generate the link with the line and let people sort it out if they don't match exactly.

You can use AddDynamicMenuItem instead of AddTopLevelMenuItem to selectively hide the context menu entry in case the repo is not on github. There's a canEnable callback there. You can get the active repository like so:

var activeRepo = ServiceProvider.GetExportedValue<ITeamExplorerServiceHolder>().ActiveRepo;

If it's not null, ActiveRepo is guaranteed to be a git repository, but not necessarily one that is on a remote server. Check if CloneUrl is not null and if CloneUrl.RepositoryName is not null. If it has a RepositoryName, chances are high that it is a github repo, or a repository with a remote url that matches the github convention of domain.com/owner/reponame url. That's enough to decide whether to show/hide the context menu.

In the command handler of AddDynamicMenuItem, get ActiveRepo (again). If it's not null, then you'll get a ISimpleRepositoryModel. Add an extension method to get the current commit hash in https://github.com/github/VisualStudio/blob/master/src/GitHub.Exports/Extensions/SimpleRepositoryModelExtensions.cs (see HasCommits)

From the CloneUrl property in ISimpleRepositoryModel, build the line url in the same way as

var browseUrl = uri.ToRepositoryUrl().Append(endpoint);
.

Get the IVisualStudioBrowser service from the ServiceProvider to open the url in a browser! I don't have a service to copy to the clipboard I think, so that might need some code.

Collaborator

shana commented Jan 7, 2016

Happy new year everyone!

Indeed, work has not been started on this. Not enough hands and omg I needed a rest after last year! I would LOVE a PR on this, these are the little things that really make coding easier.

I've created a new branch for this feature and added some things you will need to get this working, to start with: https://github.com/github/VisualStudio/tree/feature/link-to-vs. The branch adds the "Get Link" context menu and a handler for it, and gets the file name and line from VS, as an example.
You can create a PR targeting this branch and base your work on it 😄

Here's some thoughts on how to do this:


The link can be to a commit hash, so no need for branch information. No need to even check if the local file matches the remote version, I agree, just generate the link with the line and let people sort it out if they don't match exactly.

You can use AddDynamicMenuItem instead of AddTopLevelMenuItem to selectively hide the context menu entry in case the repo is not on github. There's a canEnable callback there. You can get the active repository like so:

var activeRepo = ServiceProvider.GetExportedValue<ITeamExplorerServiceHolder>().ActiveRepo;

If it's not null, ActiveRepo is guaranteed to be a git repository, but not necessarily one that is on a remote server. Check if CloneUrl is not null and if CloneUrl.RepositoryName is not null. If it has a RepositoryName, chances are high that it is a github repo, or a repository with a remote url that matches the github convention of domain.com/owner/reponame url. That's enough to decide whether to show/hide the context menu.

In the command handler of AddDynamicMenuItem, get ActiveRepo (again). If it's not null, then you'll get a ISimpleRepositoryModel. Add an extension method to get the current commit hash in https://github.com/github/VisualStudio/blob/master/src/GitHub.Exports/Extensions/SimpleRepositoryModelExtensions.cs (see HasCommits)

From the CloneUrl property in ISimpleRepositoryModel, build the line url in the same way as

var browseUrl = uri.ToRepositoryUrl().Append(endpoint);
.

Get the IVisualStudioBrowser service from the ServiceProvider to open the url in a browser! I don't have a service to copy to the clipboard I think, so that might need some code.

@austin94

This comment has been minimized.

Show comment
Hide comment
@austin94

austin94 Jan 7, 2016

@shana Wow, thank you for all the information! I'll go ahead and get started. If we

just generate the link with the line and let people sort it out if they don't match exactly

this doesn't seem too complicated.

austin94 commented Jan 7, 2016

@shana Wow, thank you for all the information! I'll go ahead and get started. If we

just generate the link with the line and let people sort it out if they don't match exactly

this doesn't seem too complicated.

@austin94

This comment has been minimized.

Show comment
Hide comment
@austin94

austin94 Jan 7, 2016

I have completed a basic implementation for the opening of a single line or a group selection.

https://github.com/austin94/VisualStudio/blob/069dc802a65fe21bf1ebcb2616efdebd6a51564c/src/GitHub.VisualStudio/GitHubPackage.cs#LL76-L97

Above is a sample link that it made.

Before I dive into the nested menu controller to include the copy to clipboard feature, are there any current examples in the app so I can match that coding style?

austin94 commented Jan 7, 2016

I have completed a basic implementation for the opening of a single line or a group selection.

https://github.com/austin94/VisualStudio/blob/069dc802a65fe21bf1ebcb2616efdebd6a51564c/src/GitHub.VisualStudio/GitHubPackage.cs#LL76-L97

Above is a sample link that it made.

Before I dive into the nested menu controller to include the copy to clipboard feature, are there any current examples in the app so I can match that coding style?

@shana

This comment has been minimized.

Show comment
Hide comment
@shana

shana Jan 8, 2016

Collaborator

@austin94 For the copy link command, just add another button/idsymbol/pkgcmdid entry for it and then call System.Windows.Clipboard.SetText(text) in the handler instead of opening in the browser.
Don't worry about showing a notification about it right now, I'm working on something for that so we can add it later.

Collaborator

shana commented Jan 8, 2016

@austin94 For the copy link command, just add another button/idsymbol/pkgcmdid entry for it and then call System.Windows.Clipboard.SetText(text) in the handler instead of opening in the browser.
Don't worry about showing a notification about it right now, I'm working on something for that so we can add it later.

@shana

This comment has been minimized.

Show comment
Hide comment
@shana

shana Jan 8, 2016

Collaborator

BTW, I'm on a GMT+1 timezone, so delays in replies may occur :-P

Collaborator

shana commented Jan 8, 2016

BTW, I'm on a GMT+1 timezone, so delays in replies may occur :-P

@austin94

This comment has been minimized.

Show comment
Hide comment
@austin94

austin94 Jan 8, 2016

@shana I probably should have waited to share the link above until I had finished refactoring! I've implemented the comments you made along with the addition of the 'Copy Link to Clipboard' feature. You can view the commit here: austin94@d4d7762

austin94 commented Jan 8, 2016

@shana I probably should have waited to share the link above until I had finished refactoring! I've implemented the comments you made along with the addition of the 'Copy Link to Clipboard' feature. You can view the commit here: austin94@d4d7762

@dmorrison

This comment has been minimized.

Show comment
Hide comment
@dmorrison

dmorrison Oct 5, 2016

I'm confused - when will this make it in to the extension?

I just started using this other extension in the meantime: https://github.com/neuecc/Open-on-GitHub

I'm confused - when will this make it in to the extension?

I just started using this other extension in the meantime: https://github.com/neuecc/Open-on-GitHub

@shana

This comment has been minimized.

Show comment
Hide comment
@shana

shana Oct 5, 2016

Collaborator

@dmorrison This has been out for a few months already

Collaborator

shana commented Oct 5, 2016

@dmorrison This has been out for a few months already

@dmorrison

This comment has been minimized.

Show comment
Hide comment
@dmorrison

dmorrison Oct 5, 2016

@shana, great! Where is this menu?

@shana, great! Where is this menu?

@dmorrison

This comment has been minimized.

Show comment
Hide comment
@dmorrison

dmorrison Oct 5, 2016

Ah - nevermind, kind of... So I see the command here. Is it supposed to be exposed by default in any menu or default shortcut?

Ah - nevermind, kind of... So I see the command here. Is it supposed to be exposed by default in any menu or default shortcut?

@shana

This comment has been minimized.

Show comment
Hide comment
@shana

shana Oct 5, 2016

Collaborator

@dmorrison When you right-click in the editor on a file, there's a GitHub menu with the submenus for links.

Collaborator

shana commented Oct 5, 2016

@dmorrison When you right-click in the editor on a file, there's a GitHub menu with the submenus for links.

@shana

This comment has been minimized.

Show comment
Hide comment
@shana

shana Oct 5, 2016

Collaborator

We didn't actually put it in the context menu of files in the solution explorer, just when right clicking on the contents in the editor. We should probably do that :-P

Collaborator

shana commented Oct 5, 2016

We didn't actually put it in the context menu of files in the solution explorer, just when right clicking on the contents in the editor. We should probably do that :-P

@dmorrison

This comment has been minimized.

Show comment
Hide comment
@dmorrison

dmorrison Oct 5, 2016

Hmm, I don't see it when I right click (that "Open on GitHub" item is for the other extension I mentioned), and I think I'm using the latest extension: http://screencast.com/t/Wbvp04lhp. Also, I'm using GitHub Enterprise, so maybe that's it?

Sorry for the confusion, and thanks!

dmorrison commented Oct 5, 2016

Hmm, I don't see it when I right click (that "Open on GitHub" item is for the other extension I mentioned), and I think I'm using the latest extension: http://screencast.com/t/Wbvp04lhp. Also, I'm using GitHub Enterprise, so maybe that's it?

Sorry for the confusion, and thanks!

@shana

This comment has been minimized.

Show comment
Hide comment
@shana

shana Oct 5, 2016

Collaborator

That's odd. I assume the project is published to github (or enterprise)? Can you post a screenshot of the Team Explorer home page so I can see if it knows it's a github repo? Or send it to windows@github.com if you'd prefer to send that privately.

Collaborator

shana commented Oct 5, 2016

That's odd. I assume the project is published to github (or enterprise)? Can you post a screenshot of the Team Explorer home page so I can see if it knows it's a github repo? Or send it to windows@github.com if you'd prefer to send that privately.

@dmorrison

This comment has been minimized.

Show comment
Hide comment
@dmorrison

dmorrison Oct 5, 2016

Yes, it is published to our internal GitHub Enterprise server. Here's the Team Explorer home page.

Yes, it is published to our internal GitHub Enterprise server. Here's the Team Explorer home page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment