Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 47d3753

Browse files
committed
Revert "Factor b/g loading menu code into AsyncMenuPackage"
This reverts commit 5730008.
1 parent f66afaf commit 47d3753

File tree

4 files changed

+36
-56
lines changed

4 files changed

+36
-56
lines changed

src/GitHub.InlineReviews/InlineReviewsPackage.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
using System;
2+
using System.ComponentModel.Design;
23
using System.Runtime.InteropServices;
4+
using System.Threading;
35
using GitHub.Commands;
46
using GitHub.InlineReviews.Views;
5-
using GitHub.Services.Vssdk;
67
using GitHub.Services.Vssdk.Commands;
78
using GitHub.VisualStudio;
89
using Microsoft.VisualStudio.ComponentModelHost;
@@ -16,16 +17,25 @@ namespace GitHub.InlineReviews
1617
[ProvideAutoLoad(Guids.UIContext_Git, PackageAutoLoadFlags.BackgroundLoad)]
1718
[ProvideMenuResource("Menus.ctmenu", 1)]
1819
[ProvideToolWindow(typeof(PullRequestCommentsPane), DocumentLikeTool = true)]
19-
public class InlineReviewsPackage : AsyncMenuPackage
20+
public class InlineReviewsPackage : AsyncPackage
2021
{
21-
protected override async Task InitializeMenusAsync(OleMenuCommandService menuService)
22+
protected override async Task InitializeAsync(
23+
CancellationToken cancellationToken,
24+
IProgress<ServiceProgressData> progress)
2225
{
26+
var menuService = (IMenuCommandService)(await GetServiceAsync(typeof(IMenuCommandService)));
2327
var componentModel = (IComponentModel)(await GetServiceAsync(typeof(SComponentModel)));
2428
var exports = componentModel.DefaultExportProvider;
2529

2630
menuService.AddCommands(
2731
exports.GetExportedValue<INextInlineCommentCommand>(),
2832
exports.GetExportedValue<IPreviousInlineCommentCommand>());
2933
}
34+
35+
// The IDesignerHost and ISelectionService services are requested by MenuCommandService.EnsureVerbs().
36+
// When called from a non-Main thread this would throw despite the fact these services don't exist.
37+
// This override allows IMenuCommandService.AddCommands to be called form a background thread.
38+
protected override object GetService(Type serviceType)
39+
=> (serviceType == typeof(ISelectionService) || serviceType == typeof(IDesignerHost)) ? null : base.GetService(serviceType);
3040
}
3141
}

src/GitHub.Services.Vssdk/AsyncMenuPackage.cs

Lines changed: 0 additions & 41 deletions
This file was deleted.

src/GitHub.Services.Vssdk/GitHub.Services.Vssdk.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@
139139
<Compile Include="..\common\SolutionInfo.cs">
140140
<Link>Properties\SolutionInfo.cs</Link>
141141
</Compile>
142-
<Compile Include="AsyncMenuPackage.cs" />
143142
<Compile Include="Commands\MenuCommandServiceExtensions.cs" />
144143
<Compile Include="Commands\VsCommand.cs" />
145144
<Compile Include="Commands\VsCommandBase.cs" />

src/GitHub.VisualStudio/GitHubPackage.cs

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Windows;
33
using System.Threading;
44
using System.Threading.Tasks;
5+
using System.ComponentModel.Design;
56
using System.ComponentModel.Composition;
67
using System.Runtime.InteropServices;
78
using GitHub.Api;
@@ -13,7 +14,6 @@
1314
using GitHub.Services.Vssdk.Commands;
1415
using GitHub.ViewModels.GitHubPane;
1516
using GitHub.VisualStudio.UI;
16-
using GitHub.Services.Vssdk;
1717
using Microsoft.VisualStudio;
1818
using Microsoft.VisualStudio.ComponentModelHost;
1919
using Microsoft.VisualStudio.Shell;
@@ -29,15 +29,35 @@ namespace GitHub.VisualStudio
2929
[ProvideMenuResource("Menus.ctmenu", 1)]
3030
[ProvideAutoLoad(Guids.UIContext_Git, PackageAutoLoadFlags.BackgroundLoad)]
3131
[ProvideOptionPage(typeof(OptionsPage), "GitHub for Visual Studio", "General", 0, 0, supportsAutomation: true)]
32-
public class GitHubPackage : AsyncMenuPackage
32+
public class GitHubPackage : AsyncPackage
3333
{
3434
static readonly ILogger log = LogManager.ForContext<GitHubPackage>();
3535

36-
protected async override Task InitializeMenusAsync(OleMenuCommandService menuService)
36+
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
3737
{
3838
LogVersionInformation();
39+
await base.InitializeAsync(cancellationToken, progress);
3940
await GetServiceAsync(typeof(IUsageTracker));
41+
await InitializeMenus();
42+
}
43+
44+
// The IDesignerHost and ISelectionService services are requested by MenuCommandService.EnsureVerbs().
45+
// When called from a non-Main thread this would throw despite the fact these services don't exist.
46+
// This override allows IMenuCommandService.AddCommands to be called form a background thread.
47+
protected override object GetService(Type serviceType)
48+
=> (serviceType == typeof(ISelectionService) || serviceType == typeof(IDesignerHost)) ? null : base.GetService(serviceType);
49+
50+
void LogVersionInformation()
51+
{
52+
var packageVersion = ApplicationInfo.GetPackageVersion(this);
53+
var hostVersionInfo = ApplicationInfo.GetHostVersionInfo();
54+
log.Information("Initializing GitHub Extension v{PackageVersion} in {$FileDescription} ({$ProductVersion})",
55+
packageVersion, hostVersionInfo.FileDescription, hostVersionInfo.ProductVersion);
56+
}
4057

58+
async Task InitializeMenus()
59+
{
60+
var menuService = (IMenuCommandService)(await GetServiceAsync(typeof(IMenuCommandService)));
4161
var componentModel = (IComponentModel)(await GetServiceAsync(typeof(SComponentModel)));
4262
var exports = componentModel.DefaultExportProvider;
4363

@@ -52,14 +72,6 @@ protected async override Task InitializeMenusAsync(OleMenuCommandService menuSer
5272
exports.GetExportedValue<IShowGitHubPaneCommand>());
5373
}
5474

55-
void LogVersionInformation()
56-
{
57-
var packageVersion = ApplicationInfo.GetPackageVersion(this);
58-
var hostVersionInfo = ApplicationInfo.GetHostVersionInfo();
59-
log.Information("Initializing GitHub Extension v{PackageVersion} in {$FileDescription} ({$ProductVersion})",
60-
packageVersion, hostVersionInfo.FileDescription, hostVersionInfo.ProductVersion);
61-
}
62-
6375
async Task EnsurePackageLoaded(Guid packageGuid)
6476
{
6577
var shell = await GetServiceAsync(typeof(SVsShell)) as IVsShell;

0 commit comments

Comments
 (0)