Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/GitHub.InlineReviews/GitHub.InlineReviews.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
<Compile Include="Glyph\GlyphMargin.cs" />
<Compile Include="Glyph\GlyphMarginVisualManager.cs" />
<Compile Include="Glyph\IGlyphFactory.cs" />
<Compile Include="PullRequestFilterProvider.cs" />
<Compile Include="PullRequestStatusBarPackage.cs" />
<Compile Include="InlineReviewsPackage.cs" />
<Compile Include="Models\InlineCommentThreadModel.cs" />
Expand Down Expand Up @@ -456,6 +457,7 @@
<Content Include="Resources\logo_32x32%402x.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Resources\PullRequestFilterCommand.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(VSToolsPath)\VSSDK\Microsoft.VsSDK.targets" Condition="'$(VSToolsPath)' != '' And '$(NCrunch)' != '1'" />
Expand Down
17 changes: 17 additions & 0 deletions src/GitHub.InlineReviews/InlineReviewsPackage.vsct
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,19 @@
<LocCanonicalName>.GitHub.PreviousComment</LocCanonicalName>
</Strings>
</Button>
<Button guid="guidPullRequestFilterCommandPackageCmdSet" id="PullRequestFilterCommandId" priority="0x0400" type="Button">
<Parent guid="guidSHLMainMenu" id="IDG_VS_TOOLBAR_PROJWIN_FILTERS" />
<Icon guid="guidImages" id="pullrequest" />
<Strings>
<ButtonText>Pull Request Filter</ButtonText>
</Strings>
<CommandFlag>DefaultInvisible</CommandFlag>
<CommandFlag>DynamicVisibility</CommandFlag>
</Button>
</Buttons>
<Bitmaps>
<Bitmap guid="guidImages" href="Resources\PullRequestFilterCommand.png" usedList="bmpPic1, bmpPic2, bmpPicSearch, bmpPicX, bmpPicArrows, bmpPicStrikethrough"/>
</Bitmaps>
</Commands>
<KeyBindings>
<KeyBinding guid="guidGitHubCommandSet" id="NextInlineCommentId" editor="guidVSStd97" key1="VK_OEM_6" mod1="Alt"/>
Expand All @@ -81,6 +93,11 @@
<IDSymbol name="PreviousInlineCommentId" value="0x1002" />
</GuidSymbol>

<GuidSymbol name="guidPullRequestFilterCommandPackageCmdSet" value="{7cde2dfc-43c9-41ff-bf2e-bef41cd99e09}">
<IDSymbol name="MyMenuGroup" value="0x1020" />
<IDSymbol name="PullRequestFilterCommandId" value="0x0100" />
</GuidSymbol>

<GuidSymbol name="guidImages" value="{775aa523-6c52-4c11-9c28-823c99d15613}" >
<IDSymbol name="bmpPic1" value="1" />
<IDSymbol name="bmpPic2" value="2" />
Expand Down
98 changes: 98 additions & 0 deletions src/GitHub.InlineReviews/PullRequestFilterProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
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 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();
vsSolution.GetSolutionInfo(out var 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);
}

private static string BuildAbsolutePath(string solutionDirectory, string fileRelativePath)
{
return Path.Combine(solutionDirectory, fileRelativePath.Replace("/", @"\")).ToLower();
}
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.