diff --git a/src/VisualStudio/Core/Def/StackTraceExplorer/StackFrameViewModel.cs b/src/VisualStudio/Core/Def/StackTraceExplorer/StackFrameViewModel.cs index 69d61d24a7d68..13e1dfced0c15 100644 --- a/src/VisualStudio/Core/Def/StackTraceExplorer/StackFrameViewModel.cs +++ b/src/VisualStudio/Core/Def/StackTraceExplorer/StackFrameViewModel.cs @@ -14,6 +14,9 @@ using System.Windows.Documents; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Classification; +using Microsoft.CodeAnalysis.Editor; +using Microsoft.CodeAnalysis.Editor.GoToDefinition; +using Microsoft.CodeAnalysis.Editor.Host; using Microsoft.CodeAnalysis.Editor.Shared.Extensions; using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.CodeAnalysis.Editor.StackTraceExplorer; @@ -32,6 +35,7 @@ internal class StackFrameViewModel : FrameViewModel private readonly ParsedStackFrame _frame; private readonly IThreadingContext _threadingContext; private readonly Workspace _workspace; + private readonly IStreamingFindUsagesPresenter _streamingPresenter; private ISymbol? _cachedSymbol; private Document? _cachedDocument; @@ -42,12 +46,14 @@ public StackFrameViewModel( IThreadingContext threadingContext, Workspace workspace, IClassificationFormatMap formatMap, - ClassificationTypeMap typeMap) + ClassificationTypeMap typeMap, + IStreamingFindUsagesPresenter streamingPresenter) : base(formatMap, typeMap) { _frame = frame; _threadingContext = threadingContext; _workspace = workspace; + _streamingPresenter = streamingPresenter; } public override bool ShowMouseOver => true; @@ -119,28 +125,19 @@ public async Task NavigateToMethodAsync(CancellationToken cancellationToken) return; } - var sourceLocation = symbol.Locations.FirstOrDefault(l => l.IsInSource); - if (sourceLocation is null || sourceLocation.SourceTree is null) - { - // Show some dialog? - return; - } + var success = GoToDefinitionHelpers.TryGoToDefinition( + symbol, + _workspace.CurrentSolution, + _threadingContext, + _streamingPresenter, + thirdPartyNavigationAllowed: true, + cancellationToken: cancellationToken); - var navigationService = _workspace.Services.GetService(); - if (navigationService is null) + if (!success) { + // Show some dialog? return; } - - // While navigating do not activate the tab, which will change focus from the tool window - var options = _workspace.Options - .WithChangedOption(new OptionKey(NavigationOptions.PreferProvisionalTab), true) - .WithChangedOption(new OptionKey(NavigationOptions.ActivateTab), false); - - var document = _workspace.CurrentSolution.GetRequiredDocument(sourceLocation.SourceTree); - - await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); - navigationService.TryNavigateToSpan(_workspace, document.Id, sourceLocation.SourceSpan, options, cancellationToken); } catch (Exception ex) when (FatalError.ReportAndCatchUnlessCanceled(ex, cancellationToken)) { diff --git a/src/VisualStudio/Core/Def/StackTraceExplorer/StackTraceExplorerRootViewModel.cs b/src/VisualStudio/Core/Def/StackTraceExplorer/StackTraceExplorerRootViewModel.cs index 1118dccb28d80..8811f42992a85 100644 --- a/src/VisualStudio/Core/Def/StackTraceExplorer/StackTraceExplorerRootViewModel.cs +++ b/src/VisualStudio/Core/Def/StackTraceExplorer/StackTraceExplorerRootViewModel.cs @@ -5,6 +5,7 @@ using System.Collections.ObjectModel; using System.Linq; using System.Windows.Input; +using Microsoft.CodeAnalysis.Editor.Host; using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.VisualStudio.LanguageServices.Utilities; using Microsoft.VisualStudio.Text.Classification; @@ -17,13 +18,15 @@ internal class StackTraceExplorerRootViewModel : ViewModelBase private readonly IClassificationFormatMap _formatMap; private readonly ClassificationTypeMap _typeMap; private readonly IThreadingContext _threadingContext; + private readonly IStreamingFindUsagesPresenter _streamingFindUsagesPresenter; - public StackTraceExplorerRootViewModel(IThreadingContext threadingContext, VisualStudioWorkspace workspace, IClassificationFormatMap formatMap, ClassificationTypeMap typeMap) + public StackTraceExplorerRootViewModel(IThreadingContext threadingContext, VisualStudioWorkspace workspace, IClassificationFormatMap formatMap, ClassificationTypeMap typeMap, IStreamingFindUsagesPresenter streamingFindUsagesPresenter) { _threadingContext = threadingContext; _workspace = workspace; _formatMap = formatMap; _typeMap = typeMap; + _streamingFindUsagesPresenter = streamingFindUsagesPresenter; } public ObservableCollection Tabs { get; } = new(); @@ -42,7 +45,7 @@ public void AddNewTab(bool triggerPaste) ? 0 : Tabs.Max(t => t.NameIndex); - var newTab = new StackTraceExplorerTab(_threadingContext, _workspace, _formatMap, _typeMap, highestIndex + 1); + var newTab = new StackTraceExplorerTab(_threadingContext, _workspace, _formatMap, _typeMap, _streamingFindUsagesPresenter, highestIndex + 1); Tabs.Add(newTab); SelectedTab = newTab; diff --git a/src/VisualStudio/Core/Def/StackTraceExplorer/StackTraceExplorerTab.cs b/src/VisualStudio/Core/Def/StackTraceExplorer/StackTraceExplorerTab.cs index 88a3828aeb4cc..4d39bd5ba3c09 100644 --- a/src/VisualStudio/Core/Def/StackTraceExplorer/StackTraceExplorerTab.cs +++ b/src/VisualStudio/Core/Def/StackTraceExplorer/StackTraceExplorerTab.cs @@ -5,6 +5,7 @@ using System; using System.Windows; using System.Windows.Input; +using Microsoft.CodeAnalysis.Editor.Host; using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.VisualStudio.LanguageServices.Utilities; using Microsoft.VisualStudio.Text.Classification; @@ -22,11 +23,11 @@ internal class StackTraceExplorerTab public event EventHandler? OnClosed; public bool IsEmpty => _stackExplorerVM.Frames.Count == 0; - public StackTraceExplorerTab(IThreadingContext threadingContext, VisualStudioWorkspace workspace, IClassificationFormatMap formatMap, ClassificationTypeMap typeMap, int nameIndex) + public StackTraceExplorerTab(IThreadingContext threadingContext, VisualStudioWorkspace workspace, IClassificationFormatMap formatMap, ClassificationTypeMap typeMap, IStreamingFindUsagesPresenter streamingFindUsagesPresenter, int nameIndex) { NameIndex = nameIndex; - _stackExplorerVM = new StackTraceExplorerViewModel(threadingContext, workspace, typeMap, formatMap); + _stackExplorerVM = new StackTraceExplorerViewModel(threadingContext, workspace, typeMap, formatMap, streamingFindUsagesPresenter); Content = new StackTraceExplorer(_stackExplorerVM); CloseClick = new DelegateCommand(_ => diff --git a/src/VisualStudio/Core/Def/StackTraceExplorer/StackTraceExplorerToolWindow.cs b/src/VisualStudio/Core/Def/StackTraceExplorer/StackTraceExplorerToolWindow.cs index 3b257899e42a3..84b2881819a90 100644 --- a/src/VisualStudio/Core/Def/StackTraceExplorer/StackTraceExplorerToolWindow.cs +++ b/src/VisualStudio/Core/Def/StackTraceExplorer/StackTraceExplorerToolWindow.cs @@ -6,6 +6,7 @@ using System.Runtime.InteropServices; using System.Windows; using System.Windows.Controls; +using Microsoft.CodeAnalysis.Editor.Host; using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.VisualStudio.Imaging; using Microsoft.VisualStudio.LanguageServices.Setup; @@ -46,8 +47,9 @@ public void InitializeIfNeeded(RoslynPackage roslynPackage) var formatMap = formatMapService.GetClassificationFormatMap(StandardContentTypeNames.Text); var typeMap = roslynPackage.ComponentModel.GetService(); var threadingContext = roslynPackage.ComponentModel.GetService(); + var streamingFindUsagesPresenter = roslynPackage.ComponentModel.GetService(); - Root = new StackTraceExplorerRoot(new StackTraceExplorerRootViewModel(threadingContext, workspace, formatMap, typeMap)) + Root = new StackTraceExplorerRoot(new StackTraceExplorerRootViewModel(threadingContext, workspace, formatMap, typeMap, streamingFindUsagesPresenter)) { HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch diff --git a/src/VisualStudio/Core/Def/StackTraceExplorer/StackTraceExplorerViewModel.cs b/src/VisualStudio/Core/Def/StackTraceExplorer/StackTraceExplorerViewModel.cs index b2ddb88d1ca15..67c67053cf8d0 100644 --- a/src/VisualStudio/Core/Def/StackTraceExplorer/StackTraceExplorerViewModel.cs +++ b/src/VisualStudio/Core/Def/StackTraceExplorer/StackTraceExplorerViewModel.cs @@ -12,6 +12,7 @@ using Microsoft.VisualStudio.LanguageServices.Utilities; using Microsoft.VisualStudio.Text.Classification; using Roslyn.Utilities; +using Microsoft.CodeAnalysis.Editor.Host; namespace Microsoft.VisualStudio.LanguageServices.StackTraceExplorer { @@ -19,7 +20,7 @@ internal class StackTraceExplorerViewModel : ViewModelBase { private readonly IThreadingContext _threadingContext; private readonly Workspace _workspace; - + private readonly IStreamingFindUsagesPresenter _streamingFindUsagesPresenter; public ObservableCollection Frames { get; } = new(); private bool _isLoading; @@ -49,7 +50,7 @@ internal void OnClear() public string InstructionText => ServicesVSResources.Paste_valid_stack_trace; - public StackTraceExplorerViewModel(IThreadingContext threadingContext, Workspace workspace, ClassificationTypeMap classificationTypeMap, IClassificationFormatMap formatMap) + public StackTraceExplorerViewModel(IThreadingContext threadingContext, Workspace workspace, ClassificationTypeMap classificationTypeMap, IClassificationFormatMap formatMap, IStreamingFindUsagesPresenter streamingFindUsagesPresenter) { _threadingContext = threadingContext; _workspace = workspace; @@ -57,6 +58,7 @@ public StackTraceExplorerViewModel(IThreadingContext threadingContext, Workspace workspace.WorkspaceChanged += Workspace_WorkspaceChanged; _classificationTypeMap = classificationTypeMap; _formatMap = formatMap; + _streamingFindUsagesPresenter = streamingFindUsagesPresenter; Frames.CollectionChanged += CallstackLines_CollectionChanged; } @@ -118,7 +120,7 @@ private FrameViewModel GetViewModel(ParsedFrame frame) => frame switch { IgnoredFrame ignoredFrame => new IgnoredFrameViewModel(ignoredFrame, _formatMap, _classificationTypeMap), - ParsedStackFrame stackFrame => new StackFrameViewModel(stackFrame, _threadingContext, _workspace, _formatMap, _classificationTypeMap), + ParsedStackFrame stackFrame => new StackFrameViewModel(stackFrame, _threadingContext, _workspace, _formatMap, _classificationTypeMap, _streamingFindUsagesPresenter), _ => throw ExceptionUtilities.UnexpectedValue(frame) }; }