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

Link from VS to Github in Browser #106

Closed
avanderhoorn opened this issue Sep 25, 2015 · 25 comments
Closed

Link from VS to Github in Browser #106

avanderhoorn opened this issue Sep 25, 2015 · 25 comments

Comments

@avanderhoorn
Copy link

@avanderhoorn avanderhoorn commented Sep 25, 2015

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
Copy link

@dalpert-korewireless dalpert-korewireless commented Sep 25, 2015

I'd love this!

@matthewkimber
Copy link

@matthewkimber matthewkimber commented Sep 25, 2015

That would be awesome!

@nosami
Copy link
Member

@nosami nosami commented Sep 25, 2015

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

@wwwlicious
Copy link

@wwwlicious wwwlicious commented Sep 25, 2015

+1 would be great to have this

@shana
Copy link
Collaborator

@shana shana commented Sep 28, 2015

Thanks for the awesome suggestion! 👍

@shana
Copy link
Collaborator

@shana 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

@austingreendev
Copy link

@austingreendev austingreendev 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
Copy link
Author

@avanderhoorn avanderhoorn commented Jan 6, 2016

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

@shana
Copy link
Collaborator

@shana 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.

@austingreendev
Copy link

@austingreendev austingreendev 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.

@austingreendev
Copy link

@austingreendev austingreendev 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
Copy link
Collaborator

@shana 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
Copy link
Collaborator

@shana shana commented Jan 8, 2016

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

@austingreendev
Copy link

@austingreendev austingreendev 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: https://github.com/austin94/VisualStudio/commit/d4d77627b33a5bad4c3d27696594f58d97e04d36

@dmorrison
Copy link

@dmorrison dmorrison commented 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

@shana
Copy link
Collaborator

@shana shana commented Oct 5, 2016

@dmorrison This has been out for a few months already

@dmorrison
Copy link

@dmorrison dmorrison commented Oct 5, 2016

@shana, great! Where is this menu?

@dmorrison
Copy link

@dmorrison dmorrison commented 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?

@shana
Copy link
Collaborator

@shana 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
Copy link
Collaborator

@shana 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
Copy link

@dmorrison 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
Copy link
Collaborator

@shana 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
Copy link

@dmorrison dmorrison commented Oct 5, 2016

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

@bsivanov
Copy link

@bsivanov bsivanov commented Sep 30, 2019

So just to confirm, this is not working with Git Enterprise? We have some private repos and I would love to use this.

@dmorrison
Copy link

@dmorrison dmorrison commented Sep 30, 2019

@bsivanov, correct - it didn't work for me in GitHub Enterprise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

9 participants
You can’t perform that action at this time.