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

Commit 66fbbaa

Browse files
committed
Load VS services asynchronously
Only IVSGitExt needs to be loaded synchronously.
1 parent 1ea222a commit 66fbbaa

File tree

4 files changed

+16
-32
lines changed

4 files changed

+16
-32
lines changed

src/GitHub.InlineReviews/GitHub.InlineReviews.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@
9393
<Compile Include="Models\InlineCommentThreadModel.cs" />
9494
<Compile Include="Models\PullRequestSessionLiveFile.cs" />
9595
<Compile Include="Models\PullRequestSessionFile.cs" />
96-
<Compile Include="Services\IPullRequestStatusBarManager.cs" />
9796
<Compile Include="Services\PullRequestStatusBarManager.cs" />
9897
<Compile Include="Tags\MouseEnterAndLeaveEventRouter.cs" />
9998
<Compile Include="Peek\InlineCommentPeekableItem.cs" />

src/GitHub.InlineReviews/PullRequestStatusBarPackage.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
using System.Runtime.InteropServices;
44
using Microsoft.VisualStudio.Shell;
55
using Microsoft.VisualStudio.ComponentModelHost;
6+
using GitHub.Helpers;
7+
using GitHub.Services;
68
using GitHub.VisualStudio;
79
using GitHub.InlineReviews.Services;
810
using Task = System.Threading.Tasks.Task;
@@ -19,10 +21,15 @@ public class PullRequestStatusBarPackage : AsyncPackage
1921
/// </summary>
2022
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
2123
{
24+
var usageTracker = (IUsageTracker)await GetServiceAsync(typeof(IUsageTracker));
25+
var serviceProvider = (IGitHubServiceProvider)await GetServiceAsync(typeof(IGitHubServiceProvider));
2226
var componentModel = (IComponentModel)await GetServiceAsync(typeof(SComponentModel));
23-
var exportProvider = componentModel.DefaultExportProvider;
24-
var pullRequestStatusManager = exportProvider.GetExportedValue<IPullRequestStatusBarManager>();
25-
await pullRequestStatusManager.InitializeAsync();
27+
var pullRequestSessionManager = componentModel.DefaultExportProvider.GetExport<IPullRequestSessionManager>();
28+
29+
await ThreadingHelper.SwitchToMainThreadAsync();
30+
var gitExt = componentModel.DefaultExportProvider.GetExportedValue<IVSGitExt>();
31+
32+
new PullRequestStatusBarManager(gitExt, pullRequestSessionManager, usageTracker, serviceProvider);
2633
}
2734
}
2835
}

src/GitHub.InlineReviews/Services/IPullRequestStatusBarManager.cs

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

src/GitHub.InlineReviews/Services/PullRequestStatusBarManager.cs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,45 +18,35 @@
1818

1919
namespace GitHub.InlineReviews.Services
2020
{
21-
[Export(typeof(IPullRequestStatusBarManager))]
22-
public class PullRequestStatusBarManager : IPullRequestStatusBarManager
21+
public class PullRequestStatusBarManager
2322
{
2423
static readonly ILogger log = LogManager.ForContext<PullRequestStatusBarManager>();
2524
const string StatusBarPartName = "PART_SccStatusBarHost";
2625

27-
readonly Lazy<IVSGitExt> gitExt;
26+
readonly IVSGitExt gitExt;
2827
readonly Lazy<IPullRequestSessionManager> pullRequestSessionManager;
2928
readonly IUsageTracker usageTracker;
3029
readonly IGitHubServiceProvider serviceProvider;
3130

3231
[ImportingConstructor]
33-
public PullRequestStatusBarManager(Lazy<IVSGitExt> gitExt, Lazy<IPullRequestSessionManager> pullRequestSessionManager,
32+
public PullRequestStatusBarManager(IVSGitExt gitExt, Lazy<IPullRequestSessionManager> pullRequestSessionManager,
3433
IUsageTracker usageTracker, IGitHubServiceProvider serviceProvider)
3534
{
3635
this.gitExt = gitExt;
3736
this.pullRequestSessionManager = pullRequestSessionManager;
3837
this.usageTracker = usageTracker;
3938
this.serviceProvider = serviceProvider;
40-
}
41-
42-
/// <summary>
43-
/// Lazily initialize when user enters the context of a GitHub repository.
44-
/// </summary>
45-
/// <param name="window">Visual Studio's main window.</param>
46-
public async Task InitializeAsync()
47-
{
48-
await ThreadingHelper.SwitchToMainThreadAsync();
4939

5040
OnActiveRepositoriesChanged();
51-
gitExt.Value.ActiveRepositoriesChanged += OnActiveRepositoriesChanged;
41+
gitExt.ActiveRepositoriesChanged += OnActiveRepositoriesChanged;
5242
}
5343

5444
void OnActiveRepositoriesChanged()
5545
{
56-
if (gitExt.Value.ActiveRepositories.Count > 0)
46+
if (gitExt.ActiveRepositories.Count > 0)
5747
{
5848
StartShowingStatus().Forget();
59-
gitExt.Value.ActiveRepositoriesChanged -= OnActiveRepositoriesChanged;
49+
gitExt.ActiveRepositoriesChanged -= OnActiveRepositoriesChanged;
6050
}
6151
}
6252

0 commit comments

Comments
 (0)