private async Task InitializeAsync(CancellationToken cancellationToken) { await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); _lazyRoslynPackage = await RoslynPackage.GetOrLoadAsync(_threadingContext, _serviceProvider, cancellationToken).ConfigureAwait(true); Assumes.Present(_lazyRoslynPackage); _optionService.RefreshOption(new OptionKey(SolutionCrawlerOptions.SolutionBackgroundAnalysisScopeOption), _lazyRoslynPackage.AnalysisScope); _lazyRoslynPackage.AnalysisScopeChanged += OnAnalysisScopeChanged; }
private async Task ShowToolWindowAsync(CancellationToken cancellationToken) { var roslynPackage = await RoslynPackage.GetOrLoadAsync(_threadingContext, _serviceProvider, cancellationToken).ConfigureAwait(false); Contract.ThrowIfNull(roslynPackage); await roslynPackage.ShowToolWindowAsync( typeof(ValueTrackingToolWindow), 0, true, roslynPackage.DisposalToken).ConfigureAwait(false); }
private void OnSetAnalysisScopeStatus(OleMenuCommand command, BackgroundAnalysisScope?scope) { // The command is enabled as long as we have a service provider if (_serviceProvider is null) { // Not yet initialized command.Enabled = false; return; } command.Enabled = true; // The command is checked if RoslynPackage is loaded and the analysis scope for this command matches the // value saved for the solution. var roslynPackage = _threadingContext.JoinableTaskFactory.Run(() => { return(RoslynPackage.GetOrLoadAsync(_threadingContext, (IAsyncServiceProvider)_serviceProvider, _threadingContext.DisposalToken).AsTask()); }); if (roslynPackage is not null) { command.Checked = roslynPackage.AnalysisScope == scope; } // For the specific case of the default analysis scope command, update the command text to show the // current effective default in the context of the language(s) used in the solution. if (scope is null) { command.Text = GetBackgroundAnalysisScope(_workspace.CurrentSolution, _globalOptions) switch { BackgroundAnalysisScope.ActiveFile => ServicesVSResources.Default_Current_Document, BackgroundAnalysisScope.OpenFiles => ServicesVSResources.Default_Open_Documents, BackgroundAnalysisScope.FullSolution => ServicesVSResources.Default_Entire_Solution, BackgroundAnalysisScope.None => ServicesVSResources.Default_None, _ => ServicesVSResources.Default_, }; } return;
private async Task <ValueTrackingToolWindow?> GetOrCreateToolWindowAsync(ITextView textView, CancellationToken cancellationToken) { var roslynPackage = await RoslynPackage.GetOrLoadAsync(_threadingContext, _serviceProvider, cancellationToken).ConfigureAwait(false); if (roslynPackage is null) { return(null); } await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); if (ValueTrackingToolWindow.Instance is null) { var factory = roslynPackage.GetAsyncToolWindowFactory(Guids.ValueTrackingToolWindowId); var viewModel = new ValueTrackingTreeViewModel(_classificationFormatMapService.GetClassificationFormatMap(textView), _typeMap, _formatMapService); factory.CreateToolWindow(Guids.ValueTrackingToolWindowId, 0, viewModel); await factory.InitializeToolWindowAsync(Guids.ValueTrackingToolWindowId, 0); // FindWindowPaneAsync creates an instance if it does not exist ValueTrackingToolWindow.Instance = (ValueTrackingToolWindow)await roslynPackage.FindWindowPaneAsync( typeof(ValueTrackingToolWindow), 0, true, roslynPackage.DisposalToken).ConfigureAwait(false); } // This can happen if the tool window was initialized outside of this command handler. The ViewModel // still needs to be initialized but had no necessary context. Provide that context now in the command handler. if (ValueTrackingToolWindow.Instance.ViewModel is null) { ValueTrackingToolWindow.Instance.ViewModel = new ValueTrackingTreeViewModel(_classificationFormatMapService.GetClassificationFormatMap(textView), _typeMap, _formatMapService); } return(ValueTrackingToolWindow.Instance); }