public VsPathContextProvider(
     IAsyncServiceProvider asyncServiceProvider,
     Lazy <ISettings> settings,
     Lazy <IVsSolutionManager> solutionManager,
     Lazy <NuGet.Common.ILogger> logger,
     Lazy <IVsProjectAdapterProvider> vsProjectAdapterProvider)
 {
     _asyncServiceprovider = asyncServiceProvider ?? throw new ArgumentNullException(nameof(asyncServiceProvider));
     _settings             = settings ?? throw new ArgumentNullException(nameof(settings));
     _solutionManager      = solutionManager ?? throw new ArgumentNullException(nameof(solutionManager));
     _logger = logger ?? throw new ArgumentNullException(nameof(logger));
     _vsProjectAdapterProvider = vsProjectAdapterProvider ?? throw new ArgumentNullException(nameof(vsProjectAdapterProvider));
     _getLockFileOrNull        = BuildIntegratedProjectUtility.GetLockFileOrNull;
 }
Esempio n. 2
0
 public VisualStudioDiagnosticListTableWorkspaceEventListener(
     [Import("Microsoft.VisualStudio.Shell.Interop.SAsyncServiceProvider")] object asyncServiceProvider,
     IGlobalOptionService globalOptions,
     IThreadingContext threadingContext,
     ITableManagerProvider tableManagerProvider)
 {
     // MEFv2 doesn't support type based contract for Import above and for this particular contract (SAsyncServiceProvider)
     // actual type cast doesn't work. (https://github.com/microsoft/vs-mef/issues/138)
     // workaround by getting the service as object and cast to actual interface
     _asyncServiceProvider = (IAsyncServiceProvider)asyncServiceProvider;
     _globalOptions        = globalOptions;
     _threadingContext     = threadingContext;
     _tableManagerProvider = tableManagerProvider;
 }
Esempio n. 3
0
        protected static async System.Threading.Tasks.Task ShowStatusBarMessageAsync(IAsyncServiceProvider serviceProvider, string message)
        {
            try
            {
                var dte = await serviceProvider.GetServiceAsync(typeof(EnvDTE.DTE)) as EnvDTE.DTE;

                dte.StatusBar.Text = message;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Esempio n. 4
0
        public VSGitExt(IAsyncServiceProvider asyncServiceProvider, IVSUIContextFactory factory, ILocalRepositoryModelFactory repositoryFactory)
        {
            this.asyncServiceProvider = asyncServiceProvider;
            this.repositoryFactory    = repositoryFactory;

            // Start with empty array until we have a chance to initialize.
            ActiveRepositories = Array.Empty <ILocalRepositoryModel>();

            // The IGitExt service isn't available when a TFS based solution is opened directly.
            // It will become available when moving to a Git based solution (and cause a UIContext event to fire).
            var context = factory.GetUIContext(new Guid(Guids.GitSccProviderId));

            context.WhenActivated(() => Initialize());
        }
Esempio n. 5
0
        public static IVSGitExt Create(int vsVersion, IAsyncServiceProvider sp)
        {
            switch (vsVersion)
            {
            case 14:
                return(Create(() => new VSGitExt14(sp)));

            case 15:
                return(Create(() => new VSGitExt15(sp)));

            default:
                log.Error("There is no IVSGitExt implementation for DTE version {Version}", vsVersion);
                return(null);
            }
        }
        public VsSourceControlManagerProvider(
            [Import(typeof(SVsServiceProvider))]
            IAsyncServiceProvider asyncServiceProvider,
            Configuration.ISettings vsSettings)
        {
            Assumes.NotNull(asyncServiceProvider);
            _asyncServiceProvider = asyncServiceProvider;
            Assumes.Present(vsSettings);

            _settings = vsSettings;
            _dte      = new AsyncLazy <EnvDTE.DTE>(async() =>
            {
                return(await asyncServiceProvider.GetDTEAsync());
            }, NuGetUIThreadHelper.JoinableTaskFactory);
        }
Esempio n. 7
0
        public static async Task InitializeAsync(IAsyncServiceProvider provider, JoinableTask optionsLoadTask, CancellationToken cancellationToken)
        {
            var dte = await provider.GetDteAsync(cancellationToken);

            var compositionService = await provider.GetServiceAsync <SComponentModel, IComponentModel>(cancellationToken);

            Instance = new DialControllerHost(provider, dte, compositionService);
            var mainWindow = dte.DTE.MainWindow;
            await Task.WhenAll(
                ThreadHelper.JoinableTaskFactory.StartOnIdle(Instance.CreateStatusBarItem).JoinAsync(),
                ThreadHelper.JoinableTaskFactory.StartOnIdle(new Action(() => controllersMapping.Add(mainWindow, Instance.CreateController(mainWindow)))).JoinAsync());

            await optionsLoadTask;
            await Instance.ImportProvidersAsync(cancellationToken);
        }
Esempio n. 8
0
        /// <summary>
        /// Gets Settings Instance
        /// </summary>
        /// <param name="serviceProvider">Extension service provider</param>
        /// <param name="projectGuid">Guid of project to read settings of</param>
        public Settings(IAsyncServiceProvider serviceProvider, Guid projectGuid)
        {
            _projectGuid   = projectGuid;
            _settingsStore = GetWritableSettingsStore(serviceProvider);


            if (_settingsStore.CollectionExists(CollectionPath))
            {
                UpdateSettings();
                Load();
            }
            else
            {
                _settingsStore.CreateCollection(CollectionPath);
            }
        }
Esempio n. 9
0
        public static async Task StartAsync(IAsyncServiceProvider services, Task uiReady)
        {
            if (services is null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            Task  playspacesSetup = RunPlayspacesSetupAsync(services);
            await uiReady;

            await RunCampaignSetupAsync(services);

            await playspacesSetup;

            await RunServiceDiscoveryAsync(services);
        }
        /// <summary>
        /// Performs the asynchronous initialization for the package in cases where IDE supports AsyncPackage.
        ///
        /// This method is always called from background thread initially.
        /// </summary>
        /// <param name="asyncServiceProvider">Async service provider instance to query services asynchronously</param>
        /// <param name="pProfferService">Async service proffer instance</param>
        /// <param name="IAsyncProgressCallback">Progress callback instance</param>
        /// <returns></returns>
        public IVsTask Initialize(IAsyncServiceProvider asyncServiceProvider, 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() =>
            {
                this.BackgroundThreadInitialization();
                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
                IVsUIShell shellService = await asyncServiceProvider.GetServiceAsync <IVsUIShell>(typeof(SVsUIShell));
                this.MainThreadInitialization(shellService, isAsyncPath: true);
                return null;
            }).AsVsTask());
        }
Esempio n. 11
0
        public static async Task InitializeAsync(IAsyncServiceProvider provider)
        {
            var commandService = await provider.GetServiceAsync(typeof(IMenuCommandService)) as IMenuCommandService;

            Assumes.Present(commandService);

            _dte = await provider.GetServiceAsync(typeof(DTE)) as DTE2;

            Assumes.Present(_dte);

            var cmdId   = new CommandID(PackageGuids.guidImageOptimizerCmdSet, PackageIds.cmdCopyDataUri);
            var menuCmd = new OleMenuCommand(Execute, cmdId);

            menuCmd.BeforeQueryStatus += CopyBeforeQueryStatus;
            commandService.AddCommand(menuCmd);
        }
        /// <summary>
        /// Performs the asynchronous initialization for the package in cases where IDE supports AsyncPackage.
        ///
        /// This method is always called from background thread initially.
        /// </summary>
        /// <param name="asyncServiceProvider">Async service provider instance to query services asynchronously</param>
        /// <param name="pProfferService">Async service proffer instance</param>
        /// <param name="IAsyncProgressCallback">Progress callback instance</param>
        /// <returns></returns>
        public IVsTask Initialize(IAsyncServiceProvider asyncServiceProvider, 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() =>
            {
                BackgroundThreadInitialization();
                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
                var menuCommandService = (OleMenuCommandService)GetService(typeof(IMenuCommandService));
                MainThreadInitialization(menuCommandService, isAsyncPath: true);
                return null;
            }).AsVsTask());
        }
Esempio n. 13
0
        public async Task InitializeAsync(IAsyncServiceProvider serviceProvider, CancellationToken cancellationToken)
        {
            Contract.ThrowIfNull(serviceProvider);

            _serviceProvider = (IServiceProvider)serviceProvider;

            // Hook up the "Remove Unused References" 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, ID.RoslynCommands.RemoveUnusedReferences, Guids.RoslynGroupId, OnRemoveUnusedReferencesForSelectedProject, OnRemoveUnusedReferencesForSelectedProjectStatus);
            }
        }
        private VisualStudioRemoteHostClientProvider(
            HostWorkspaceServices services,
            IAsyncServiceProvider vsServiceProvider,
            IThreadingContext threadingContext,
            AsynchronousOperationListenerProvider listenerProvider,
            RemoteServiceCallbackDispatcherRegistry callbackDispatchers)
        {
            _services            = services;
            _vsServiceProvider   = vsServiceProvider;
            _listenerProvider    = listenerProvider;
            _callbackDispatchers = callbackDispatchers;

            // using VS AsyncLazy here since Roslyn's is not compatible with JTF.
            // Our ServiceBroker services may be invoked by other VS components under JTF.
            _lazyClient = new VSThreading.AsyncLazy <RemoteHostClient?>(CreateHostClientAsync, threadingContext.JoinableTaskFactory);
        }
Esempio n. 15
0
        public async Task <AnalyzerOutput> GetXamlAsync(IAsyncServiceProvider serviceProvider)
        {
            AnalyzerOutput result = null;

            if (AnalyzerBase.GetSettings().Profiles.Any())
            {
                var dte = await serviceProvider.GetServiceAsync(typeof(EnvDTE.DTE)) as EnvDTE.DTE;

                var activeDocument = dte.ActiveDocument;

                var textView = await GetTextViewAsync(serviceProvider);

                var selection = textView.Selection;

                bool isSelection = selection.Start.Position != selection.End.Position;

                var caretPosition = textView.Caret.Position.BufferPosition;

                var document = caretPosition.Snapshot.GetOpenDocumentInCurrentContextWithChanges();

                var semanticModel = await document.GetSemanticModelAsync();

                var vs         = new VisualStudioAbstraction(this.Logger, this.ServiceProvider, dte);
                var xamlIndent = await vs.GetXamlIndentAsync();

                IDocumentAnalyzer analyzer = null;

                if (activeDocument.Language == "CSharp")
                {
                    analyzer = new CSharpAnalyzer(this.Logger);
                }
                else if (activeDocument.Language == "Basic")
                {
                    analyzer = new VisualBasicAnalyzer(this.Logger);
                }

                result = isSelection
                    ? analyzer?.GetSelectionOutput(await document.GetSyntaxRootAsync(), semanticModel, selection.Start.Position, selection.End.Position, xamlIndent)
                    : analyzer?.GetSingleItemOutput(await document.GetSyntaxRootAsync(), semanticModel, caretPosition.Position, xamlIndent);
            }
            else
            {
                await ShowStatusBarMessageAsync(serviceProvider, StringRes.UI_NoXamlCopiedNoProfilesConfigured);
            }

            return(result);
        }
Esempio n. 16
0
        public async Task RegisterAsync(IAsyncServiceProvider serviceProvider, CancellationToken cancellationToken)
        {
            if (!_eventsHookedUp)
            {
                var trackProjectDocuments = await serviceProvider.GetServiceAsync <SVsTrackProjectDocuments, IVsTrackProjectDocuments2>(_threadingContext.JoinableTaskFactory).ConfigureAwait(false);

                await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

                if (!_eventsHookedUp)
                {
                    if (ErrorHandler.Succeeded(trackProjectDocuments.AdviseTrackProjectDocumentsEvents(this, out _cookie)))
                    {
                        _eventsHookedUp = true;
                    }
                }
            }
        }
Esempio n. 17
0
        internal static async ValueTask ProfferServicesAsync(IAsyncServiceProvider serviceProvider)
        {
            Assumes.NotNull(serviceProvider);

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

            var factory = new NuGetBrokeredServiceFactory();

            // 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);
        }
Esempio n. 18
0
        public async Task <ParserOutput> GetXamlAsync(IAsyncServiceProvider serviceProvider)
        {
            ParserOutput result = null;

            if (CodeParserBase.GetSettings().Profiles.Any())
            {
                if (!(await serviceProvider.GetServiceAsync(typeof(EnvDTE.DTE)) is DTE dte))
                {
                    RapidXamlPackage.Logger?.RecordError("Failed to get DTE in GetXamlFromCodeWindowBaseCommand.GetXamlAsync");
                }
                else
                {
                    var activeDocument = dte.ActiveDocument;

                    var textView = await GetTextViewAsync(serviceProvider);

                    var selection = textView.Selection;

                    bool isSelection = selection.Start.Position != selection.End.Position;

                    var caretPosition = textView.Caret.Position.BufferPosition;

                    var document = caretPosition.Snapshot.GetOpenDocumentInCurrentContextWithChanges();

                    var semanticModel = await document.GetSemanticModelAsync();

                    var vs         = new VisualStudioAbstraction(this.Logger, this.ServiceProvider, dte);
                    var xamlIndent = await vs.GetXamlIndentAsync();

                    IDocumentParser parser = null;

                    if (activeDocument.Language == "CSharp")
                    {
                        parser = new CSharpParser(this.Logger, xamlIndent);
                    }
                    else if (activeDocument.Language == "Basic")
                    {
                        parser = new VisualBasicParser(this.Logger, xamlIndent);
                    }

                    result = isSelection
                        ? parser?.GetSelectionOutput(await document.GetSyntaxRootAsync(), semanticModel, selection.Start.Position, selection.End.Position)
                        : parser?.GetSingleItemOutput(await document.GetSyntaxRootAsync(), semanticModel, caretPosition.Position);
                }
            }
Esempio n. 19
0
        /// <summary>
        /// Custom: returns an instance of service type or throws an exception if one is not available.
        /// </summary>
        /// <typeparam name="T">Service type.</typeparam>
        /// <param name="serviceProvider">Service provider.</param>
        /// <param name="throwOnError">Throw exception if service is not available or return null otherwise.</param>
        /// <returns>Service instance.</returns>
        public static async Task <T> GetServiceAsync <T>(this IAsyncServiceProvider serviceProvider, bool throwOnError = true)
        {
            var service = await serviceProvider.GetServiceAsync(typeof(T));

            if (!(service is T))
            {
                if (throwOnError)
                {
                    throw new ApplicationException($"Service of {typeof(T)} type is not available.");
                }
                else
                {
                    return(default(T));
                }
            }

            return((T)service);
        }
Esempio n. 20
0
        public VSGitExt(IAsyncServiceProvider asyncServiceProvider, IVSUIContextFactory factory, ILocalRepositoryModelFactory repositoryFactory,
                        JoinableTaskContext joinableTaskContext)
        {
            JoinableTaskCollection             = joinableTaskContext.CreateCollection();
            JoinableTaskCollection.DisplayName = nameof(VSGitExt);
            JoinableTaskFactory = joinableTaskContext.CreateFactory(JoinableTaskCollection);

            this.asyncServiceProvider = asyncServiceProvider;
            this.repositoryFactory    = repositoryFactory;

            // Start with empty array until we have a chance to initialize.
            ActiveRepositories = Array.Empty <ILocalRepositoryModel>();

            // Initialize when we enter the context of a Git repository
            var context = factory.GetUIContext(UICONTEXT.RepositoryOpen_guid);

            context.WhenActivated(() => JoinableTaskFactory.RunAsync(InitializeAsync).Task.Forget(log));
        }
Esempio n. 21
0
        public static void FindPattern(string regexPattern, IAsyncServiceProvider serviceProvider)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            DTE dteObject = ThreadHelper.JoinableTaskFactory.Run(() =>
                                                                 serviceProvider.GetServiceAsync(typeof(DTE))
                                                                 ) as DTE;

            dteObject.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxRegExpr;
            dteObject.Find.Action        = vsFindAction.vsFindActionFindAll;
            dteObject.Find.Backwards     = false;
            dteObject.Find.Target        = vsFindTarget.vsFindTargetSolution;
            //dteObject.Find.ResultsLocation = vsFindResultsLocation.vsFindResultsNone;
            dteObject.Find.ResultsLocation   = vsFindResultsLocation.vsFindResults1;
            dteObject.Find.MatchWholeWord    = false;
            dteObject.Find.MatchInHiddenText = true;
            dteObject.Find.FindWhat          = regexPattern;
            dteObject.Find.Execute();
        }
Esempio n. 22
0
        public VSGitExt(IAsyncServiceProvider asyncServiceProvider, IVSUIContextFactory factory, ILocalRepositoryModelFactory repositoryFactory,
                        JoinableTaskContext joinableTaskContext)
        {
            JoinableTaskCollection             = joinableTaskContext.CreateCollection();
            JoinableTaskCollection.DisplayName = nameof(VSGitExt);
            JoinableTaskFactory = joinableTaskContext.CreateFactory(JoinableTaskCollection);

            this.asyncServiceProvider = asyncServiceProvider;
            this.repositoryFactory    = repositoryFactory;

            // Start with empty array until we have a chance to initialize.
            ActiveRepositories = Array.Empty <ILocalRepositoryModel>();

            // The IGitExt service isn't available when a TFS based solution is opened directly.
            // It will become available when moving to a Git based solution (and cause a UIContext event to fire).
            var context = factory.GetUIContext(new Guid(Guids.GitSccProviderId));

            context.WhenActivated(() => JoinableTaskFactory.RunAsync(InitializeAsync).Task.Forget(log));
        }
Esempio n. 23
0
        public AnalyzerOutput GetXaml(IAsyncServiceProvider serviceProvider)
        {
            AnalyzerOutput result = null;

            if (AnalyzerBase.GetSettings().Profiles.Any())
            {
                var dte            = (EnvDTE.DTE)serviceProvider.GetServiceAsync(typeof(EnvDTE.DTE)).Result;
                var activeDocument = dte.ActiveDocument;

                var textView = GetTextView(serviceProvider);

                var selection = textView.Selection;

                bool isSelection = selection.Start.Position != selection.End.Position;

                var caretPosition = textView.Caret.Position.BufferPosition;

                var document = caretPosition.Snapshot.GetOpenDocumentInCurrentContextWithChanges();

                var semanticModel = document.GetSemanticModelAsync().Result;

                IDocumentAnalyzer analyzer = null;

                if (activeDocument.Language == "CSharp")
                {
                    analyzer = new CSharpAnalyzer(this.Logger);
                }
                else if (activeDocument.Language == "Basic")
                {
                    analyzer = new VisualBasicAnalyzer(this.Logger);
                }

                result = isSelection
                    ? analyzer?.GetSelectionOutput(document.GetSyntaxRootAsync().Result, semanticModel, selection.Start.Position, selection.End.Position)
                    : analyzer?.GetSingleItemOutput(document.GetSyntaxRootAsync().Result, semanticModel, caretPosition.Position);
            }
            else
            {
                ShowStatusBarMessage(serviceProvider, "No XAML copied. No profiles configured.");
            }

            return(result);
        }
Esempio n. 24
0
        /// <summary>
        /// Helper method to use async/await with IAsyncServiceProvider implementation
        /// </summary>
        /// <param name="asyncServiceProvider">IAsyncServciceProvider instance</param>
        /// <param name="serviceType">Type of the Visual Studio service requested</param>
        /// <returns>Service object as type of T</returns>
        public static async Task <T> GetServiceAsync <T>(this IAsyncServiceProvider asyncServiceProvider, Type serviceType) where T : class
        {
            T returnValue = null;

            await ThreadHelper.JoinableTaskFactory.RunAsync(async() =>
            {
                object serviceInstance = null;
                Guid serviceTypeGuid   = serviceType.GUID;
                serviceInstance        = await asyncServiceProvider.QueryServiceAsync(ref serviceTypeGuid);

                // We have to make sure we are on main UI thread before trying to cast as underlying implementation
                // can be an STA COM object and doing a cast would require calling QueryInterface/AddRef marshaling
                // to main thread via COM.
                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
                returnValue = serviceInstance as T;
            });

            return(returnValue);
        }
 public Factory(
     SVsServiceProvider vsServiceProvider,
     AsynchronousOperationListenerProvider listenerProvider,
     IThreadingContext threadingContext,
     [ImportMany]
     IEnumerable <
         Lazy <
             IRemoteServiceCallbackDispatcher,
             RemoteServiceCallbackDispatcherRegistry.ExportMetadata
             >
         > callbackDispatchers
     )
 {
     _vsServiceProvider   = (IAsyncServiceProvider)vsServiceProvider;
     _listenerProvider    = listenerProvider;
     _threadingContext    = threadingContext;
     _callbackDispatchers = new RemoteServiceCallbackDispatcherRegistry(
         callbackDispatchers
         );
 }
Esempio n. 26
0
        public static async Task <VSVersion> GetVersionAsync(IAsyncServiceProvider serviceProvider)
        {
            serviceProvider.ThrowOnNull(nameof(serviceProvider));

            if (!ThreadHelper.CheckAccess())
            {
                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
            }

            Version?shellVersion = await VS.Shell.GetVsVersionAsync();

            if (shellVersion != null)
            {
                return(new VSVersion(shellVersion));
            }

            var unknownVersion = new Version(VSVersion.UnknownVersion, VSVersion.UnknownVersion);

            return(new VSVersion(unknownVersion));
        }
        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);
            }
        }
Esempio n. 28
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 <IGlobalRunSettingsInternal2>();

                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                DoInitialize();

                return null;
            }).AsVsTask());
        }
Esempio n. 29
0
        public Task InitializeAsync(IAsyncServiceProvider asyncServiceProvider)
        {
            // There's no public API registering a trace listener for a
            // non-public trace source, so we need to use reflection
            string assemblyName = typeof(AppliesToAttribute).Assembly.FullName;

            var type = Type.GetType($"Microsoft.VisualStudio.ProjectSystem.TraceUtilities, {assemblyName}");

            Assumes.NotNull(type);

            FieldInfo field = type.GetField("Source", BindingFlags.NonPublic | BindingFlags.Static);

            Assumes.NotNull(field);

            var source = (TraceSource)field.GetValue(null);

            source.Switch.Level = SourceLevels.Warning;
            source.Listeners.Add(this);

            return(Task.CompletedTask);
        }
Esempio n. 30
0
        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());
        }