Example #1
0
        IVsTask IAsyncLoadablePackageInitialize.Initialize(IAsyncServiceProvider serviceProvider, IProfferAsyncService profferService,
                                                           IAsyncProgressCallback progressCallback)
        {
            if (!_isAsyncLoadSupported)
            {
                throw new InvalidOperationException("Async Initialize method should not be called when async load is not supported.");
            }

            return(ThreadHelper.JoinableTaskFactory.RunAsync <object>(async() =>
            {
                var componentModel = await serviceProvider.GetServiceAsync <IComponentModel>(typeof(SComponentModel));
                _globalRunSettings = componentModel.GetService <IGlobalRunSettingsInternal>();

                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                DoInitialize();

                return null;
            }).AsVsTask());
        }
Example #2
0
        public async ValueTask <IOptionPersister> GetOrCreatePersisterAsync(CancellationToken cancellationToken)
        {
            if (_lazyPersister != null)
            {
                return(_lazyPersister);
            }

            IVsFeatureFlags?service;

            try
            {
                service = (IVsFeatureFlags?)await _serviceProvider.GetServiceAsync(typeof(SVsFeatureFlags)).ConfigureAwait(false);
            }
            catch (Exception e) when(FatalError.ReportAndCatch(e))
            {
                service = null;
            }

            return(_lazyPersister = new FeatureFlagPersister(service));
        }
Example #3
0
        private async Task <RemoteHostClient?> CreateHostClientAsync(CancellationToken cancellationToken)
        {
            try
            {
                var brokeredServiceContainer = await _vsServiceProvider.GetServiceAsync <SVsBrokeredServiceContainer, IBrokeredServiceContainer>().ConfigureAwait(false);

                var serviceBroker = brokeredServiceContainer.GetFullAccessServiceBroker();

                var client = await ServiceHubRemoteHostClient.CreateAsync(_services, serviceBroker, cancellationToken).ConfigureAwait(false);

                // proffer in-proc brokered services:
                _ = brokeredServiceContainer.Proffer(SolutionAssetProvider.ServiceDescriptor, (_, _, _, _) => new ValueTask <object?>(new SolutionAssetProvider(_services)));

                return(client);
            }
            catch (Exception e) when(FatalError.ReportWithoutCrashUnlessCanceled(e))
            {
                return(null);
            }
        }
        protected static async Task <Microsoft.VisualStudio.Text.Editor.IWpfTextView> GetTextViewAsync(IAsyncServiceProvider serviceProvider)
        {
            if (!(await serviceProvider.GetServiceAsync(typeof(SVsTextManager)) is IVsTextManager textManager))
            {
                return(null);
            }

            textManager.GetActiveView(1, null, out IVsTextView textView);

            if (textView == null)
            {
                return(null);
            }
            else
            {
                var provider = await GetEditorAdaptersFactoryServiceAsync(serviceProvider);

                return(provider.GetWpfTextView(textView));
            }
        }
        public async Task InitializeAsync(IAsyncServiceProvider serviceProvider, CancellationToken cancellationToken)
        {
            _serviceProvider = (IServiceProvider)serviceProvider;

            // Hook up the "Run Code Analysis" menu command for CPS based managed projects.
            var menuCommandService = await serviceProvider.GetServiceAsync <IMenuCommandService, IMenuCommandService>(_threadingContext.JoinableTaskFactory, throwOnFailure : false).ConfigureAwait(false);

            if (menuCommandService != null)
            {
                await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

                VisualStudioCommandHandlerHelpers.AddCommand(menuCommandService, RunCodeAnalysisForSelectedProjectCommandId, VSConstants.VSStd2K, OnRunCodeAnalysisForSelectedProject, OnRunCodeAnalysisForSelectedProjectStatus);
                VisualStudioCommandHandlerHelpers.AddCommand(menuCommandService, ID.RoslynCommands.RunCodeAnalysisForProject, Guids.RoslynGroupId, OnRunCodeAnalysisForSelectedProject, OnRunCodeAnalysisForSelectedProjectStatus);
                VisualStudioCommandHandlerHelpers.AddCommand(menuCommandService, ID.RoslynCommands.AnalysisScopeDefault, Guids.RoslynGroupId, OnSetAnalysisScopeDefault, OnSetAnalysisScopeDefaultStatus);
                VisualStudioCommandHandlerHelpers.AddCommand(menuCommandService, ID.RoslynCommands.AnalysisScopeCurrentDocument, Guids.RoslynGroupId, OnSetAnalysisScopeCurrentDocument, OnSetAnalysisScopeCurrentDocumentStatus);
                VisualStudioCommandHandlerHelpers.AddCommand(menuCommandService, ID.RoslynCommands.AnalysisScopeOpenDocuments, Guids.RoslynGroupId, OnSetAnalysisScopeOpenDocuments, OnSetAnalysisScopeOpenDocumentsStatus);
                VisualStudioCommandHandlerHelpers.AddCommand(menuCommandService, ID.RoslynCommands.AnalysisScopeEntireSolution, Guids.RoslynGroupId, OnSetAnalysisScopeEntireSolution, OnSetAnalysisScopeEntireSolutionStatus);
                VisualStudioCommandHandlerHelpers.AddCommand(menuCommandService, ID.RoslynCommands.AnalysisScopeNone, Guids.RoslynGroupId, OnSetAnalysisScopeNone, OnSetAnalysisScopeNoneStatus);
            }
        }
Example #6
0
        void Initialize()
        {
            PendingTasks = asyncServiceProvider.GetServiceAsync(typeof(IGitExt)).ContinueWith(t =>
            {
                gitService = (IGitExt)t.Result;
                if (gitService == null)
                {
                    log.Error("Couldn't find IGitExt service");
                    return;
                }

                RefreshActiveRepositories();
                gitService.PropertyChanged += (s, e) =>
                {
                    if (e.PropertyName == nameof(gitService.ActiveRepositories))
                    {
                        RefreshActiveRepositories();
                    }
                };
            }, TaskScheduler.Default);
        }
        public IVsTask Initialize(IAsyncServiceProvider pServiceProvider, IProfferAsyncService pProfferService, IAsyncProgressCallback pProgressCallback)
        {
            if (!isAsyncLoadSupported)
            {
                throw new InvalidOperationException("Async Initialize method should not be called when async load is not supported.");
            }

            return(ThreadHelper.JoinableTaskFactory.RunAsync <object>(async() =>
            {
                var dte = await pServiceProvider.GetServiceAsync <DTE>(typeof(DTE));

                var runningDocumentTable = new RunningDocumentTable(this);
                var defaultConfig = (VisualStudioConfiguration)GetDialogPage(typeof(VisualStudioConfiguration));

                var documentFormatService = new DocumentFormatService(dte, (doc) => new FormatDocumentConfiguration(doc, defaultConfig));
                plugin = new FormatDocumentOnBeforeSave(dte, runningDocumentTable, documentFormatService);
                runningDocumentTable.Advise(plugin);

                return null;
            }).AsVsTask());
        }
        private async Task <RemoteHostClient?> CreateHostClientAsync()
        {
            try
            {
                var brokeredServiceContainer = await _vsServiceProvider.GetServiceAsync <SVsBrokeredServiceContainer, IBrokeredServiceContainer>().ConfigureAwait(false);

                var serviceBroker = brokeredServiceContainer.GetFullAccessServiceBroker();

                // VS AsyncLazy does not currently support cancellation:
                var client = await ServiceHubRemoteHostClient.CreateAsync(_services, _listenerProvider, serviceBroker, _callbackDispatchers, CancellationToken.None).ConfigureAwait(false);

                // proffer in-proc brokered services:
                _ = brokeredServiceContainer.Proffer(SolutionAssetProvider.ServiceDescriptor, (_, _, _, _) => ValueTaskFactory.FromResult <object?>(new SolutionAssetProvider(_services)));

                return(client);
            }
            catch (Exception e) when(FatalError.ReportAndCatchUnlessCanceled(e))
            {
                return(null);
            }
        }
        // This returns a disposable for test purposes only.
        internal static async ValueTask <IDisposable> ProfferServicesAsync(IAsyncServiceProvider serviceProvider)
        {
            Assumes.NotNull(serviceProvider);

            IBrokeredServiceContainer brokeredServiceContainer = await serviceProvider.GetServiceAsync <SVsBrokeredServiceContainer, IBrokeredServiceContainer>();

#pragma warning disable CA2000 // Dispose objects before losing scope
            var factory = new NuGetBrokeredServiceFactory();
#pragma warning restore CA2000 // Dispose objects before losing scope

            // This service descriptor reference will cause NuGet.VisualStudio.Contracts.dll to load.
            brokeredServiceContainer.Proffer(ContractsNuGetServices.NuGetProjectServiceV1, factory.CreateNuGetProjectServiceV1);

            // These service descriptor references will cause NuGet.VisualStudio.Internal.Contracts.dll to load.
            brokeredServiceContainer.Proffer(NuGetServices.SourceProviderService, factory.CreateSourceProviderServiceAsync);
            brokeredServiceContainer.Proffer(NuGetServices.SolutionManagerService, factory.CreateSolutionManagerServiceAsync);
            brokeredServiceContainer.Proffer(NuGetServices.ProjectManagerService, factory.CreateProjectManagerServiceAsync);
            brokeredServiceContainer.Proffer(NuGetServices.ProjectUpgraderService, factory.CreateProjectUpgraderServiceAsync);
            brokeredServiceContainer.Proffer(NuGetServices.SearchService, factory.CreatePackageSearchServiceAsync);

            return(factory);
        }
Example #10
0
        public async Task InitializeAsync(CancellationToken cancellationToken)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            loggerService = await serviceProvider.GetServiceAsync(typeof(SLoggerService)) as ILoggerService;

            var package = (AsyncPackage)serviceProvider;
            var page    = (OptionsPageGrid)package.GetDialogPage(typeof(OptionsPageGrid));

            if (!string.IsNullOrWhiteSpace(page.ExecutablePath))
            {
                if (Path.HasExtension(page.ExecutablePath))
                {
                    this.ExecutablePath = Path.GetDirectoryName(page.ExecutablePath);
                }
                else
                {
                    this.ExecutablePath = page.ExecutablePath;
                }
            }

            this.StartHidden = false;
        }
Example #11
0
        protected async Task <int> GetXamlIndentAsync(IAsyncServiceProvider serviceProvider)
        {
            try
            {
                var xamlLanguageGuid    = new Guid("CD53C9A1-6BC2-412B-BE36-CC715ED8DD41");
                var languagePreferences = new LANGPREFERENCES3[1];

                languagePreferences[0].guidLang = xamlLanguageGuid;

                var textManager = await serviceProvider.GetServiceAsync(typeof(SVsTextManager)) as IVsTextManager4;

                textManager.GetUserPreferences4(pViewPrefs: null, pLangPrefs: languagePreferences, pColorPrefs: null);

                return((int)languagePreferences[0].uIndentSize);
            }
            catch (Exception exc)
            {
                this.Logger.RecordException(exc);

                var indent = new Microsoft.VisualStudio.Text.Editor.IndentSize();

                return(indent.Default);
            }
        }
Example #12
0
        protected static async Task <IVsEditorAdaptersFactoryService> GetEditorAdaptersFactoryServiceAsync(IAsyncServiceProvider serviceProvider)
        {
            var componentModel = await serviceProvider.GetServiceAsync(typeof(SComponentModel)) as IComponentModel;

            return(componentModel.GetService <IVsEditorAdaptersFactoryService>());
        }
Example #13
0
        async Task <T> GetServiceAsync <T>()
        {
            await JoinableTaskFactory.SwitchToMainThreadAsync();

            return((T)await asyncServiceProvider.GetServiceAsync(typeof(T)));
        }
Example #14
0
        public static async Task <T> GetServiceAsync <T>(this IAsyncServiceProvider serviceProvider)
        {
            var instance = await serviceProvider.GetServiceAsync(typeof(T));

            return((T)instance);
        }
 public static async Task <TReturn> GetServiceAsync <TService, TReturn>(this IAsyncServiceProvider provider)
 {
     return((TReturn)(await provider.GetServiceAsync(typeof(TService))));
 }
 public static Task <IComponentModel> GetComponentModelAsync(
     this IAsyncServiceProvider site)
 {
     return(site.GetServiceAsync <SComponentModel, IComponentModel>());
 }
Example #17
0
 internal static async Task <TReturnType> GetServiceAsync <TServiceType, TReturnType>(this IAsyncServiceProvider provider, CancellationToken cancellationToken)
 => (TReturnType)await provider.GetServiceAsync(typeof(TServiceType));
 public static async Task <T> GetAsync <T>(this IAsyncServiceProvider serviceProvider)
     where T : class
 {
     return(await serviceProvider.GetServiceAsync(typeof(T)) as T);
 }
Example #19
0
 private static async Task <TReturn> GetServiceAsync <TGet, TReturn>(this IAsyncServiceProvider asyncServiceProvider)
     where TGet : class
     where TReturn : class
 {
     return(await asyncServiceProvider.GetServiceAsync(typeof(TGet)) as TReturn);
 }
 public static async Task <TInterface> GetServiceAsync <TService, TInterface>(this IAsyncServiceProvider sp)
 {
     return((TInterface)await sp.GetServiceAsync(typeof(TService)));
 }
        public static async Task <T> GetMefServiceAsync <T>(this IAsyncServiceProvider serviceProvider) where T : class
        {
            var componentModel = await serviceProvider.GetServiceAsync(typeof(SComponentModel)) as IComponentModel;

            return(componentModel.GetService <T>());
        }
Example #22
0
    public static async Task InitializeAsync(IAsyncServiceProvider provider, string name)
    {
        _output = await provider.GetServiceAsync(typeof(Interop.SVsOutputWindow)) as Interop.IVsOutputWindow;

        _name = name;
    }
Example #23
0
        public async Task InitializeAsync(IAsyncServiceProvider serviceProvider)
        {
            var errorList = await serviceProvider.GetServiceAsync <SVsErrorList, IErrorList>(_threadingContext.JoinableTaskFactory, throwOnFailure : false).ConfigureAwait(false);

            _tableControl = errorList?.TableControl;
        }
Example #24
0
        protected static IVsEditorAdaptersFactoryService GetEditorAdaptersFactoryService(IAsyncServiceProvider serviceProvider)
        {
            var componentModel = (IComponentModel)serviceProvider.GetServiceAsync(typeof(SComponentModel)).Result;

            return(componentModel.GetService <IVsEditorAdaptersFactoryService>());
        }
 public static async Task <T> GetServiceAsync <T>(this IAsyncServiceProvider provider)
 {
     return((T)(await provider.GetServiceAsync(typeof(T))));
 }
 public async Task InitializeAsync(IAsyncServiceProvider provider, CancellationToken cancellationToken)
 {
     _dte = await provider.GetServiceAsync(typeof(EnvDTE.DTE)) as EnvDTE.DTE;
 }
Example #27
0
 internal static Task <DTE2> GetDteAsync(this IAsyncServiceProvider provider, CancellationToken cancellationToken)
 => provider.GetServiceAsync <DTE, DTE2>(cancellationToken);
 public static Task <EnvDTE.DTE> GetDTEAsync(
     this IAsyncServiceProvider site)
 {
     return(site.GetServiceAsync <SDTE, EnvDTE.DTE>());
 }