public static async Task <RemoteHostClient> CreateAsync(
            HostWorkspaceServices services,
            IGlobalOptionService globalOptions,
            AsynchronousOperationListenerProvider listenerProvider,
            IServiceBroker serviceBroker,
            RemoteServiceCallbackDispatcherRegistry callbackDispatchers,
            CancellationToken cancellationToken)
        {
            using (Logger.LogBlock(FunctionId.ServiceHubRemoteHostClient_CreateAsync, KeyValueLogMessage.NoProperty, cancellationToken))
            {
#pragma warning disable ISB001    // Dispose of proxies
#pragma warning disable VSTHRD012 // Provide JoinableTaskFactory where allowed
                var serviceBrokerClient = new ServiceBrokerClient(serviceBroker);
#pragma warning restore

                var hubClient = new HubClient("ManagedLanguage.IDE.RemoteHostClient");

                var client = new ServiceHubRemoteHostClient(services, globalOptions, serviceBrokerClient, hubClient, callbackDispatchers);

                await client.TryInvokeAsync <IRemoteAsynchronousOperationListenerService>(
                    (service, cancellationToken) => service.EnableAsync(AsynchronousOperationListenerProvider.IsEnabled, listenerProvider.DiagnosticTokensEnabled, cancellationToken),
                    cancellationToken).ConfigureAwait(false);

                client.Started();
                return(client);
            }
        }
Exemple #2
0
        public static async Task <RemoteHostClient> CreateAsync(
            HostWorkspaceServices services,
            RemoteProcessConfiguration configuration,
            AsynchronousOperationListenerProvider listenerProvider,
            IServiceBroker serviceBroker,
            RemoteServiceCallbackDispatcherRegistry callbackDispatchers,
            CancellationToken cancellationToken)
        {
            using (Logger.LogBlock(FunctionId.ServiceHubRemoteHostClient_CreateAsync, KeyValueLogMessage.NoProperty, cancellationToken))
            {
#pragma warning disable ISB001    // Dispose of proxies
#pragma warning disable VSTHRD012 // Provide JoinableTaskFactory where allowed
                var serviceBrokerClient = new ServiceBrokerClient(serviceBroker);
#pragma warning restore

                var hubClient = new HubClient("ManagedLanguage.IDE.RemoteHostClient");

                var client = new ServiceHubRemoteHostClient(services, configuration, serviceBrokerClient, hubClient, callbackDispatchers);

                var syntaxTreeConfigurationService = services.GetService <ISyntaxTreeConfigurationService>();
                if (syntaxTreeConfigurationService != null)
                {
                    await client.TryInvokeAsync <IRemoteProcessTelemetryService>(
                        (service, cancellationToken) => service.SetSyntaxTreeConfigurationOptionsAsync(syntaxTreeConfigurationService.DisableRecoverableTrees, syntaxTreeConfigurationService.DisableProjectCacheService, syntaxTreeConfigurationService.EnableOpeningSourceGeneratedFilesInWorkspace, cancellationToken),
                        cancellationToken).ConfigureAwait(false);
                }

                await client.TryInvokeAsync <IRemoteAsynchronousOperationListenerService>(
                    (service, cancellationToken) => service.EnableAsync(AsynchronousOperationListenerProvider.IsEnabled, listenerProvider.DiagnosticTokensEnabled, cancellationToken),
                    cancellationToken).ConfigureAwait(false);

                client.Started();
                return(client);
            }
        }
 private VisualStudioRemoteHostClientProvider(HostWorkspaceServices services, IAsyncServiceProvider vsServiceProvider, AsynchronousOperationListenerProvider listenerProvider)
 {
     _services          = services;
     _vsServiceProvider = vsServiceProvider;
     _listenerProvider  = listenerProvider;
     _lazyClient        = new AsyncLazy <RemoteHostClient?>(CreateHostClientAsync, cacheResult: true);
 }
Exemple #4
0
        public async Task TestFindReferencesAsynchronousCall()
        {
            using (var workspace = TestWorkspace.CreateCSharp("class C { C() { new C(); } }"))
            {
                var context   = new MockFindUsagesContext();
                var presenter = new MockStreamingFindUsagesPresenter(context);

                var listenerProvider = new AsynchronousOperationListenerProvider();

                var handler = new FindReferencesCommandHandler(
                    SpecializedCollections.SingletonEnumerable(new Lazy <IStreamingFindUsagesPresenter>(() => presenter)),
                    listenerProvider);

                var textView = workspace.Documents[0].GetTextView();
                textView.Caret.MoveTo(new SnapshotPoint(textView.TextSnapshot, 7));
                handler.ExecuteCommand(new FindReferencesCommandArgs(
                                           textView,
                                           textView.TextBuffer), TestCommandExecutionContext.Create());

                var waiter = listenerProvider.GetWaiter(FeatureAttribute.FindReferences);
                await waiter.CreateWaitTask();

                AssertResult(context.Result, "C.C()", "class C");
            }
        }
 public ApexAsynchronousOperationListenerProviderAccessor(
     AsynchronousOperationListenerProvider implementation,
     [Import(AllowDefault = true)] VisualStudioWorkspace?workspace)
 {
     _implementation = implementation;
     _workspace      = workspace;
 }
        public override void Before(MethodInfo methodUnderTest)
        {
            MefHostServices.TestAccessor.HookServiceCreation(CreateMefHostServices);

            // make sure we enable this for all unit tests
            AsynchronousOperationListenerProvider.Enable(enable: true, diagnostics: true);
            ExportProviderCache.SetEnabled_OnlyUseExportProviderAttributeCanCall(true);
        }
 public Factory(
     SVsServiceProvider vsServiceProvider,
     AsynchronousOperationListenerProvider listenerProvider,
     [ImportMany] IEnumerable <Lazy <IRemoteServiceCallbackDispatcher, RemoteServiceCallbackDispatcherRegistry.ExportMetadata> > callbackDispatchers)
 {
     _vsServiceProvider   = (IAsyncServiceProvider)vsServiceProvider;
     _listenerProvider    = listenerProvider;
     _callbackDispatchers = new RemoteServiceCallbackDispatcherRegistry(callbackDispatchers);
 }
Exemple #8
0
        public override void Before(MethodInfo methodUnderTest)
        {
            MefHostServices.HookServiceCreation(CreateMefHostServices);
            RoslynServices.HookHostServices(() => _remoteHostServices.Value);
            DesktopMefHostServices.ResetHostServicesTestOnly();

            // make sure we enable this for all unit tests
            AsynchronousOperationListenerProvider.Enable(enable: true, diagnostics: true);
            ExportProviderCache.SetEnabled_OnlyUseExportProviderAttributeCanCall(true);
        }
        public static ExportProvider CreateExportProvider(ComposableCatalog catalog)
        {
            // make sure we enable this for all unit tests
            AsynchronousOperationListenerProvider.Enable(true);

            var configuration      = CompositionConfiguration.Create(catalog.WithDesktopSupport().WithCompositionService());
            var runtimeComposition = RuntimeComposition.CreateRuntimeComposition(configuration);

            return(runtimeComposition.CreateExportProviderFactory().CreateExportProvider());
        }
 public Factory(
     SVsServiceProvider vsServiceProvider,
     AsynchronousOperationListenerProvider listenerProvider,
     IGlobalOptionService globalOptions,
     IThreadingContext threadingContext,
     [ImportMany] IEnumerable <Lazy <IRemoteServiceCallbackDispatcher, RemoteServiceCallbackDispatcherRegistry.ExportMetadata> > callbackDispatchers)
 {
     _vsServiceProvider   = (IAsyncServiceProvider)vsServiceProvider;
     _globalOptions       = globalOptions;
     _listenerProvider    = listenerProvider;
     _threadingContext    = threadingContext;
     _callbackDispatchers = new RemoteServiceCallbackDispatcherRegistry(callbackDispatchers);
 }
        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);
        }
Exemple #12
0
        public static async Task <RemoteHostClient> CreateAsync(
            HostWorkspaceServices services,
            AsynchronousOperationListenerProvider listenerProvider,
            IServiceBroker serviceBroker,
            RemoteServiceCallbackDispatcherRegistry callbackDispatchers,
            CancellationToken cancellationToken)
        {
            using (Logger.LogBlock(FunctionId.ServiceHubRemoteHostClient_CreateAsync, KeyValueLogMessage.NoProperty, cancellationToken))
            {
                Logger.Log(FunctionId.RemoteHost_Bitness, KeyValueLogMessage.Create(
                               LogType.Trace,
                               m =>
                {
                    m["64bit"]    = RemoteHostOptions.IsServiceHubProcess64Bit(services);
                    m["ServerGC"] = RemoteHostOptions.IsServiceHubProcessServerGC(services);
                }));

#pragma warning disable ISB001    // Dispose of proxies
#pragma warning disable VSTHRD012 // Provide JoinableTaskFactory where allowed
                var serviceBrokerClient = new ServiceBrokerClient(serviceBroker);
#pragma warning restore

                var hubClient = new HubClient("ManagedLanguage.IDE.RemoteHostClient");

                var remoteHostStream = await RequestServiceAsync(services, hubClient, WellKnownServiceHubService.RemoteHost, cancellationToken).ConfigureAwait(false);

                var client = new ServiceHubRemoteHostClient(services, serviceBroker, serviceBrokerClient, hubClient, remoteHostStream, callbackDispatchers);

                var uiCultureLCID = CultureInfo.CurrentUICulture.LCID;
                var cultureLCID   = CultureInfo.CurrentCulture.LCID;

                // initialize the remote service
                await client._endPoint.InvokeAsync <string>(
                    nameof(IRemoteHostService.InitializeGlobalState),
                    new object?[] { uiCultureLCID, cultureLCID },
                    cancellationToken).ConfigureAwait(false);

                if (AsynchronousOperationListenerProvider.IsEnabled && !IsRpsMachine())
                {
                    await client.TryInvokeAsync <IRemoteAsynchronousOperationListenerService>(
                        (service, cancellationToken) => service.EnableAsync(AsynchronousOperationListenerProvider.IsEnabled, listenerProvider.DiagnosticTokensEnabled, cancellationToken),
                        cancellationToken).ConfigureAwait(false);
                }

                client.Started();
                return(client);
            }
        public async Task TestWithMockDiagnosticService_TaggerProviderCreatedBeforeInitialDiagnosticsReported()
        {
            // This test produces diagnostics from a mock service so that we are disconnected from
            // all teh asynchrony of hte actual async analyzer engine.  If this fails, then the
            // issue is almost certainly in the DiagnosticsSquiggleTaggerProvider code.  If this
            // succeed, but other squiggle tests fail, then it is likely an issue with the
            // diagnostics engine not actually reporting all diagnostics properly.

            using (var workspace = TestWorkspace.CreateCSharp(new string[] { "class A { }" }, CSharpParseOptions.Default))
                using (var wrapper = new DiagnosticTaggerWrapper <DiagnosticsSquiggleTaggerProvider>(workspace))
                {
                    var listenerProvider = new AsynchronousOperationListenerProvider();

                    var diagnosticService = new MockDiagnosticService(workspace);
                    var provider          = new DiagnosticsSquiggleTaggerProvider(
                        diagnosticService, workspace.GetService <IForegroundNotificationService>(), listenerProvider);

                    // Create the tagger before the first diagnostic event has been fired.
                    var tagger = provider.CreateTagger <IErrorTag>(workspace.Documents.First().GetTextBuffer());

                    // Now product hte first diagnostic and fire the events.
                    var tree = await workspace.CurrentSolution.Projects.Single().Documents.Single().GetSyntaxTreeAsync();

                    var span = TextSpan.FromBounds(0, 5);
                    diagnosticService.CreateDiagnosticAndFireEvents(Location.Create(tree, span));

                    using (var disposable = tagger as IDisposable)
                    {
                        await listenerProvider.GetWaiter(FeatureAttribute.DiagnosticService).CreateWaitTask();

                        await listenerProvider.GetWaiter(FeatureAttribute.ErrorSquiggles).CreateWaitTask();

                        var snapshot = workspace.Documents.First().GetTextBuffer().CurrentSnapshot;
                        var spans    = tagger.GetTags(snapshot.GetSnapshotSpanCollection()).ToList();
                        Assert.Equal(1, spans.Count);
                        Assert.Equal(span.ToSpan(), spans[0].Span.Span);
                    }
                }
        }
        private DiagnosticTaggerWrapper(
            TestWorkspace workspace,
            Dictionary <string, DiagnosticAnalyzer[]> analyzerMap,
            IDiagnosticUpdateSource updateSource,
            bool createTaggerProvider)
        {
            _listenerProvider = new AsynchronousOperationListenerProvider();

            if (analyzerMap != null || updateSource == null)
            {
                AnalyzerService = CreateDiagnosticAnalyzerService(analyzerMap, _listenerProvider.GetListener(FeatureAttribute.DiagnosticService));
            }

            if (updateSource == null)
            {
                updateSource = AnalyzerService;
            }

            _workspace = workspace;

            _registrationService = workspace.Services.GetService <ISolutionCrawlerRegistrationService>();
            _registrationService.Register(workspace);

            DiagnosticService = new DiagnosticService(_listenerProvider);
            DiagnosticService.Register(updateSource);

            if (createTaggerProvider)
            {
                var taggerProvider = this.TaggerProvider;
            }

            if (AnalyzerService != null)
            {
                _incrementalAnalyzers   = ImmutableArray.Create(AnalyzerService.CreateIncrementalAnalyzer(workspace));
                _solutionCrawlerService = workspace.Services.GetService <ISolutionCrawlerRegistrationService>() as SolutionCrawlerRegistrationService;
            }
        }
Exemple #15
0
        public async Task TestPreviewDiagnosticTaggerInPreviewPane()
        {
            using (var workspace = TestWorkspace.CreateCSharp("class { }", exportProvider: EditorServicesUtil.ExportProvider))
            {
                // set up listener to wait until diagnostic finish running
                var diagnosticService = workspace.ExportProvider.GetExportedValue <IDiagnosticService>() as DiagnosticService;

                // no easy way to setup waiter. kind of hacky way to setup waiter
                var source     = new CancellationTokenSource();
                var taskSource = new TaskCompletionSource <DiagnosticsUpdatedArgs>();
                diagnosticService.DiagnosticsUpdated += (s, a) =>
                {
                    source.Cancel();

                    source = new CancellationTokenSource();
                    var cancellationToken = source.Token;
                    Task.Delay(2000, cancellationToken).ContinueWith(t => taskSource.TrySetResult(a), CancellationToken.None, TaskContinuationOptions.OnlyOnRanToCompletion, TaskScheduler.Current);
                };

                var hostDocument = workspace.Projects.First().Documents.First();

                // make a change to remove squiggle
                var oldDocument = workspace.CurrentSolution.GetDocument(hostDocument.Id);
                var oldText     = oldDocument.GetTextAsync().Result;

                var newDocument = oldDocument.WithText(oldText.WithChanges(new TextChange(new TextSpan(0, oldText.Length), "class C { }")));

                // create a diff view
                WpfTestCase.RequireWpfFact($"{nameof(TestPreviewDiagnosticTaggerInPreviewPane)} creates a {nameof(DifferenceViewerPreview)}");

                var previewFactoryService = workspace.ExportProvider.GetExportedValue <IPreviewFactoryService>();
                using (var diffView = (DifferenceViewerPreview)(await previewFactoryService.CreateChangedDocumentPreviewViewAsync(oldDocument, newDocument, CancellationToken.None)))
                {
                    var foregroundService = workspace.GetService <IForegroundNotificationService>();

                    var listenerProvider = new AsynchronousOperationListenerProvider();

                    // set up tagger for both buffers
                    var leftBuffer   = diffView.Viewer.LeftView.BufferGraph.GetTextBuffers(t => t.ContentType.IsOfType(ContentTypeNames.CSharpContentType)).First();
                    var leftProvider = new DiagnosticsSquiggleTaggerProvider(diagnosticService, foregroundService, listenerProvider);
                    var leftTagger   = leftProvider.CreateTagger <IErrorTag>(leftBuffer);
                    using (var leftDisposable = leftTagger as IDisposable)
                    {
                        var rightBuffer   = diffView.Viewer.RightView.BufferGraph.GetTextBuffers(t => t.ContentType.IsOfType(ContentTypeNames.CSharpContentType)).First();
                        var rightProvider = new DiagnosticsSquiggleTaggerProvider(diagnosticService, foregroundService, listenerProvider);
                        var rightTagger   = rightProvider.CreateTagger <IErrorTag>(rightBuffer);
                        using (var rightDisposable = rightTagger as IDisposable)
                        {
                            // wait up to 20 seconds for diagnostics
                            taskSource.Task.Wait(20000);
                            if (!taskSource.Task.IsCompleted)
                            {
                                // something is wrong
                                FatalError.Report(new System.Exception("not finished after 20 seconds"));
                            }

                            // wait taggers
                            await listenerProvider.GetWaiter(FeatureAttribute.ErrorSquiggles).CreateWaitTask();

                            // check left buffer
                            var leftSnapshot = leftBuffer.CurrentSnapshot;
                            var leftSpans    = leftTagger.GetTags(leftSnapshot.GetSnapshotSpanCollection()).ToList();
                            Assert.Equal(1, leftSpans.Count);

                            // check right buffer
                            var rightSnapshot = rightBuffer.CurrentSnapshot;
                            var rightSpans    = rightTagger.GetTags(rightSnapshot.GetSnapshotSpanCollection()).ToList();
                            Assert.Equal(0, rightSpans.Count);
                        }
                    }
                }
            }
        }
Exemple #16
0
 internal static void EnableAsynchronousOperationTracking()
 {
     AsynchronousOperationListenerProvider.Enable(true);
 }
Exemple #17
0
 public void Enable(bool enable)
 {
     AsynchronousOperationListenerProvider.Enable(enable);
 }
Exemple #18
0
 public TestWaitingService(AsynchronousOperationListenerProvider provider)
 {
     _provider = provider;
 }
 public TestingOnly_WaitingService(IAsynchronousOperationListenerProvider provider)
 {
     _provider = (AsynchronousOperationListenerProvider)provider;
 }
Exemple #20
0
 public ApexAsynchronousOperationListenerProviderAccessor(AsynchronousOperationListenerProvider implementation)
 {
     _implementation = implementation;
 }
 public Factory(SVsServiceProvider vsServiceProvider, AsynchronousOperationListenerProvider listenerProvider)
 {
     _vsServiceProvider = (IAsyncServiceProvider)vsServiceProvider;
     _listenerProvider  = listenerProvider;
 }