public void StartListening(Workspace workspace, object serviceOpt) { if (workspace is not VisualStudioWorkspace || IVsShellExtensions.IsInCommandLineMode(_threadingContext.JoinableTaskFactory)) { return; } // only push solution snapshot from primary (VS) workspace: _checksumUpdater = new SolutionChecksumUpdater(workspace, _globalOptions, _listenerProvider, _disposalCancellationSource.Token); _globalNotificationDelivery = new GlobalNotificationRemoteDeliveryService(workspace.Services, _disposalCancellationSource.Token); // start launching remote process, so that the first service that needs it doesn't need to wait for it: var service = workspace.Services.GetRequiredService <IRemoteHostClientProvider>(); _remoteClientInitializationTask = service.TryGetRemoteHostClientAsync(_disposalCancellationSource.Token); }
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress) { await base.InitializeAsync(cancellationToken, progress).ConfigureAwait(true); await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); var shell = (IVsShell7) await GetServiceAsync(typeof(SVsShell)).ConfigureAwait(true); var solution = (IVsSolution) await GetServiceAsync(typeof(SVsSolution)).ConfigureAwait(true); cancellationToken.ThrowIfCancellationRequested(); Assumes.Present(shell); Assumes.Present(solution); foreach (var editorFactory in CreateEditorFactories()) { RegisterEditorFactory(editorFactory); } RegisterLanguageService(typeof(TLanguageService), async ct => { await JoinableTaskFactory.SwitchToMainThreadAsync(ct); // Create the language service, tell it to set itself up, then store it in a field // so we can notify it that it's time to clean up. _languageService = CreateLanguageService(); _languageService.Setup(); return(_languageService.ComAggregate); }); await shell.LoadPackageAsync(Guids.RoslynPackageId); var miscellaneousFilesWorkspace = this.ComponentModel.GetService <MiscellaneousFilesWorkspace>(); RegisterMiscellaneousFilesWorkspaceInformation(miscellaneousFilesWorkspace); if (!IVsShellExtensions.IsInCommandLineMode(JoinableTaskFactory)) { // not every derived package support object browser and for those languages // this is a no op await RegisterObjectBrowserLibraryManagerAsync(cancellationToken).ConfigureAwait(true); } LoadComponentsInUIContextOnceSolutionFullyLoadedAsync(cancellationToken).Forget(); }
protected override void Dispose(bool disposing) { if (disposing) { if (!IVsShellExtensions.IsInCommandLineMode(JoinableTaskFactory)) { JoinableTaskFactory.Run(async() => await UnregisterObjectBrowserLibraryManagerAsync(CancellationToken.None).ConfigureAwait(true)); } // If we've created the language service then tell it it's time to clean itself up now. if (_languageService != null) { _languageService.TearDown(); _languageService = null; } } base.Dispose(disposing); }
public void StopListening(Workspace workspace) { if (!(workspace is VisualStudioWorkspace) || IVsShellExtensions.IsInCommandLineMode(_threadingContext.JoinableTaskFactory)) { return; } _disposalCancellationSource.Cancel(); _disposalCancellationSource.Dispose(); _checksumUpdater?.Shutdown(); _globalNotificationDelivery?.Dispose(); // dispose remote client if its initialization has completed: _remoteClientInitializationTask?.ContinueWith( previousTask => previousTask.Result?.Dispose(), CancellationToken.None, TaskContinuationOptions.OnlyOnRanToCompletion, TaskScheduler.Default); }