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

GitSccProvider is overly active #1511

@jcansdale

Description

@jcansdale
  • 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.

Possible solutions

  1. 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. 😄

  1. 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions