-
Notifications
You must be signed in to change notification settings - Fork 1.2k
GitSccProvider is overly active #1511
Description
- GitHub Extension for Visual Studio version: 2.4.3
- Visual Studio version: 2015 and 2017
Problem
The [ProvideAutoLoad(Guids.GitSccProviderId)] attribute is causing our GitHubPackage package to virtually always get initialized as Visual Studio starts. This includes when starting with no solution or starting with a non-Git solution. The only exception is when Visual Studio used a non-Git SCC provider that last time it was opened (e.g. if it was using the native TFS SCC provider).
This behavior appears to be the same with Visual Studio 2015 and 2017. The only difference when using Visual Studio 2017 is that the previously active repository doesn't appear in Team Explorer when opening with no solution. Under the covers the Git SCC provider remains active.
- This potentially has performance consequences for Consolidate VS Command Architecture #1502. It means commands are being initialized using MEF even when there is no active repository.
- We're also initializing
IUsageTrackerwhen where is no active repository.
https://github.com/github/VisualStudio/blob/master/src/GitHub.VisualStudio/GitHubPackage.cs#L58 - Adds a complication for [Feature] Show current PR on status bar #1396 which should only be initialized when there is an active repository
- Other places?
Possible solutions
- We might want to create a Custom Context GUID:
https://msdn.microsoft.com/en-us/library/bb165339.aspx
If an appropriate command context GUID is not already defined, you can define one in your VSPackage and then program it to be active or inactive as required to control the visibility of your commands.
Is seems UIContext is the key. 😄
- Alternatively we could lazily initialize when a repository becomes active.
For example:
async Task InitializeMenusWhenActive()
{
var sp = (IGitHubServiceProvider)await GetServiceAsync(typeof(IGitHubServiceProvider));
var gitExt = sp.GetService<IVSGitExt>();
if (gitExt.ActiveRepositories.Count > 0)
{
log.Information("Eagerly initializing menus for {LocalPath}", gitExt.ActiveRepositories.First().LocalPath);
await InitializeMenus();
}
else
{
log.Information("Postpone initializing menus when there's no active repository");
Action subscription = null;
gitExt.ActiveRepositoriesChanged += subscription = () =>
{
if (gitExt.ActiveRepositories.Count > 0)
{
log.Information("Lazily initializing menus for {LocalPath}", gitExt.ActiveRepositories.First().LocalPath);
gitExt.ActiveRepositoriesChanged -= subscription;
InitializeMenus().Forget();
}
};
}
}Related
-
VSIX UIContext
https://gist.github.com/madskristensen/7981e3e746088b51f98c9efd13e68963 -
Expose IVSGitExt as async VS service: Expose IVSGitExt as async VS service #1510
-
Consolidate VS Command Architecture: Consolidate VS Command Architecture #1502
-
[Feature] Show current PR on status bar [Feature] Show current PR on status bar #1396