Ejemplo n.º 1
0
        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;
        }
Ejemplo n.º 2
0
        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);
        }
        public void InitializeIfNeeded(RoslynPackage roslynPackage)
        {
            if (_initialized)
            {
                return;
            }

            var workspace                    = roslynPackage.ComponentModel.GetService <VisualStudioWorkspace>();
            var formatMapService             = roslynPackage.ComponentModel.GetService <IClassificationFormatMapService>();
            var formatMap                    = formatMapService.GetClassificationFormatMap(StandardContentTypeNames.Text);
            var typeMap                      = roslynPackage.ComponentModel.GetService <ClassificationTypeMap>();
            var threadingContext             = roslynPackage.ComponentModel.GetService <IThreadingContext>();
            var streamingFindUsagesPresenter = roslynPackage.ComponentModel.GetService <IStreamingFindUsagesPresenter>();

            Root = new StackTraceExplorerRoot(new StackTraceExplorerRootViewModel(threadingContext, workspace, formatMap, typeMap, streamingFindUsagesPresenter))
            {
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment   = VerticalAlignment.Stretch
            };

            var contentRoot = (DockPanel)Content;

            contentRoot.Children.Add(Root);

            var contextMenu = new ThemedContextMenu();

            contextMenu.Items.Add(new MenuItem()
            {
                Header  = ServicesVSResources.Paste,
                Command = new DelegateCommand(_ => Root.OnPaste()),
                Icon    = new CrispImage()
                {
                    Moniker = KnownMonikers.Paste
                }
            });

            contextMenu.Items.Add(new MenuItem()
            {
                Header  = ServicesVSResources.Clear,
                Command = new DelegateCommand(_ => Root.OnClear()),
                Icon    = new CrispImage()
                {
                    Moniker = KnownMonikers.ClearCollection
                }
            });

            contentRoot.ContextMenu = contextMenu;

            _initialized = true;
        }
Ejemplo n.º 4
0
        private StackTraceExplorerCommandHandler(RoslynPackage package)
        {
            _package          = package;
            _threadingContext = package.ComponentModel.GetService <IThreadingContext>();
            _globalOptions    = package.ComponentModel.GetService <IGlobalOptionService>();

            _globalOptions.OptionChanged += GlobalOptionChanged;

            var enabled = _globalOptions.GetOption(StackTraceExplorerOptionsMetadata.OpenOnFocus);

            if (enabled)
            {
                AdviseBroadcastMessages();
            }
        }
        private StackTraceExplorerCommandHandler(RoslynPackage package)
        {
            _package          = package;
            _threadingContext = package.ComponentModel.GetService <IThreadingContext>();

            var workspace     = package.ComponentModel.GetService <VisualStudioWorkspace>();
            var optionService = workspace.Services.GetRequiredService <IOptionService>();

            optionService.OptionChanged += OptionService_OptionChanged;

            var enabled = workspace.CurrentSolution.Options.GetOption(StackTraceExplorerOptions.OpenOnFocus);

            if (enabled)
            {
                AdviseBroadcastMessages();
            }
        }
        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;
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
 private StackTraceExplorerCommandHandler(RoslynPackage package)
 {
     _package = package;
 }