This repository was archived by the owner on Jun 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[WIP] Add Pull Request filter button to Visual Studio solution explorer #1667
Open
laurentkempe
wants to merge
16
commits into
github:master
Choose a base branch
from
laurentkempe:fixes/1666-filter-pr-solution-explorer
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 11 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
79a8aea
Add Pull Request filter button to Visual Studio solution explorer
laurentkempe 9f15b75
Merge branch 'master' into fixes/1666-filter-pr-solution-explorer
jcansdale 00fef12
Fix build for C# 6.0/Visual Studio 2015
jcansdale c354515
Add IDSymbol for pullrequest Bitmap
jcansdale fa7db93
Keep CA happy by using ToUpperInvariant
jcansdale cc0b7a4
Merge branch 'master' into fixes/1666-filter-pr-solution-explorer
jcansdale 0b1a752
Fix issue introduced in previous commit
laurentkempe e9b547a
Merge branch 'master' into fixes/1666-filter-pr-solution-explorer
jcansdale da6ef3e
Merge branch 'master' into fixes/1666-filter-pr-solution-explorer
jcansdale e95d218
Merge branch 'master' into fixes/1666-filter-pr-solution-explorer
laurentkempe d54e072
Try to use the pull request image from GitHub.VisualStudio
laurentkempe 74390c6
Update src/GitHub.InlineReviews/InlineReviewsPackage.vsct
jcansdale a0c218d
Add and use new xaml pull request filter icon
laurentkempe f1d3741
Merge branch 'master' into fixes/1666-filter-pr-solution-explorer
laurentkempe e5b03bf
Merge branch 'master' into fixes/1666-filter-pr-solution-explorer
jcansdale a9f62a6
Merge branch 'master' into fixes/1666-filter-pr-solution-explorer
laurentkempe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/GitHub.InlineReviews/GitHub.InlineReviews.imagemanifest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- This file was generated by the ManifestFromResources tool.--> | ||
<!-- Version: 14.0.50929.2 --> | ||
<ImageManifest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/VisualStudio/ImageManifestSchema/2014"> | ||
<Symbols> | ||
<String Name="Resources" Value="/GitHub.VisualStudio;Component/Resources/icons" /> | ||
|
||
<Guid Name="guidGitHubInlineReviews" Value="{7b2a62fb-6aaa-4893-82c2-4895716a390c}" /> | ||
<ID Name="pullrequest" Value="1" /> | ||
</Symbols> | ||
<Images> | ||
<Image Guid="$(guidGitHubInlineReviews)" ID="$(pullrequest)"> | ||
<Source Uri="$(Resources)/git_pull_request.xaml" /> | ||
</Image> | ||
</Images> | ||
<ImageLists /> | ||
</ImageManifest> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
using System.Collections.Generic; | ||
using System.ComponentModel.Composition; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using GitHub.Services; | ||
using GitHub.VisualStudio; | ||
using Microsoft.Internal.VisualStudio.PlatformUI; | ||
using Microsoft.VisualStudio.Shell; | ||
|
||
namespace GitHub.InlineReviews | ||
{ | ||
public static class PullRequestFilterPackageGuids | ||
{ | ||
public const string GuidPullRequestFilterPackageCmdSetString = "7cde2dfc-43c9-41ff-bf2e-bef41cd99e09"; | ||
public const int PullRequestFilterId = 0x0100; | ||
} | ||
|
||
[SolutionTreeFilterProvider(PullRequestFilterPackageGuids.GuidPullRequestFilterPackageCmdSetString, PullRequestFilterPackageGuids.PullRequestFilterId)] | ||
[Export] | ||
public class PullRequestFilterProvider : HierarchyTreeFilterProvider | ||
{ | ||
private readonly IVsHierarchyItemCollectionProvider hierarchyCollectionProvider; | ||
private readonly IGitHubServiceProvider githubServiceProvider; | ||
|
||
[ImportingConstructor] | ||
public PullRequestFilterProvider(IVsHierarchyItemCollectionProvider hierarchyCollectionProvider, IGitHubServiceProvider githubServiceProvider) | ||
{ | ||
this.hierarchyCollectionProvider = hierarchyCollectionProvider; | ||
this.githubServiceProvider = githubServiceProvider; | ||
} | ||
|
||
protected override HierarchyTreeFilter CreateFilter() | ||
{ | ||
return new PullRequestFilter(hierarchyCollectionProvider, githubServiceProvider); | ||
} | ||
|
||
private sealed class PullRequestFilter : HierarchyTreeFilter | ||
{ | ||
private readonly IVsHierarchyItemCollectionProvider hierarchyCollectionProvider; | ||
private readonly IGitHubServiceProvider githubServiceProvider; | ||
private IPullRequestSessionManager sessionManager; | ||
private HashSet<string> pullRequestSessionFiles; | ||
|
||
public PullRequestFilter(IVsHierarchyItemCollectionProvider hierarchyCollectionProvider, IGitHubServiceProvider githubServiceProvider) | ||
{ | ||
this.hierarchyCollectionProvider = hierarchyCollectionProvider; | ||
this.githubServiceProvider = githubServiceProvider; | ||
} | ||
|
||
IPullRequestSessionManager SessionManager | ||
{ | ||
get | ||
{ | ||
// Lazily load the pull request session manager to prevent all of our assemblies | ||
// being loaded on VS startup. | ||
if (sessionManager == null) | ||
{ | ||
sessionManager = githubServiceProvider.GetService<IPullRequestSessionManager>(); | ||
} | ||
|
||
return sessionManager; | ||
} | ||
} | ||
|
||
// Gets the items to be included from this filter provider. | ||
// rootItems is a collection that contains the root of your solution | ||
// Returns a collection of items to be included as part of the filter | ||
protected override async Task<IReadOnlyObservableSet> GetIncludedItemsAsync(IEnumerable<IVsHierarchyItem> rootItems) | ||
{ | ||
var root = HierarchyUtilities.FindCommonAncestor(rootItems); | ||
var sourceItems = await hierarchyCollectionProvider.GetDescendantsAsync(root.HierarchyIdentity.NestedHierarchy, CancellationToken); | ||
|
||
var vsSolution = githubServiceProvider.GetSolution(); | ||
string solutionDirectory; | ||
string _; | ||
vsSolution.GetSolutionInfo(out solutionDirectory, out _, out _); | ||
|
||
this.pullRequestSessionFiles = new HashSet<string>(); | ||
if (SessionManager.CurrentSession != null) | ||
{ | ||
var requestSessionFiles = await SessionManager.CurrentSession.GetAllFiles(); | ||
requestSessionFiles.ForEach(file => this.pullRequestSessionFiles.Add(BuildAbsolutePath(solutionDirectory, file.RelativePath))); | ||
} | ||
|
||
return await hierarchyCollectionProvider.GetFilteredHierarchyItemsAsync(sourceItems, ShouldIncludeInFilter, CancellationToken); | ||
} | ||
|
||
// Returns true if filters hierarchy item name for given filter; otherwise, false</returns> | ||
private bool ShouldIncludeInFilter(IVsHierarchyItem hierarchyItem) | ||
{ | ||
return hierarchyItem?.CanonicalName != null && pullRequestSessionFiles.Contains(hierarchyItem.CanonicalName.ToUpperInvariant()); | ||
} | ||
|
||
private static string BuildAbsolutePath(string solutionDirectory, string fileRelativePath) | ||
{ | ||
return Path.Combine(solutionDirectory, fileRelativePath.Replace("/", @"\")).ToUpperInvariant(); | ||
jcansdale marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.