Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce Stack Trace Explorer automatic open behavior scope #58819

Merged
merged 1 commit into from
Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ public IgnoredFrame(string originalText)
_originalText = originalText;
}

public override bool IsStackFrame => false;

public override string ToString()
{
return _originalText;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,5 @@ internal abstract class ParsedFrame
public ParsedFrame()
{
}

public abstract bool IsStackFrame { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ public ParsedStackFrame(

public StackFrameCompilationUnit Root => Tree.Root;

public override bool IsStackFrame => true;

public override string ToString()
{
return Tree.Text.CreateString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.ComponentModel.Design;
using System.IO.Packaging;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.StackTraceExplorer;
using Microsoft.VisualStudio.LanguageServices.Setup;
Expand Down Expand Up @@ -63,6 +64,7 @@ public int OnBroadcastMessage(uint msg, IntPtr wParam, IntPtr lParam)
await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync();
var windowFrame = (IVsWindowFrame)window.Frame;
ErrorHandler.ThrowOnFailure(windowFrame.Show());
Logger.Log(FunctionId.StackTraceToolWindow_ShowOnActivated, logLevel: LogLevel.Information);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Windows.Controls;
using System.Windows.Input;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.EmbeddedLanguages.StackFrame;
using Microsoft.CodeAnalysis.StackTraceExplorer;
using Microsoft.VisualStudio.Imaging;
using Microsoft.VisualStudio.LanguageServices.Setup;
Expand Down Expand Up @@ -72,7 +73,7 @@ public async Task<bool> ShouldShowOnActivatedAsync(CancellationToken cancellatio
}

var result = await StackTraceAnalyzer.AnalyzeAsync(text, cancellationToken).ConfigureAwait(false);
if (result.ParsedFrames.Any(static frame => frame.IsStackFrame))
if (result.ParsedFrames.Any(static frame => FrameTriggersActivate(frame)))
{
await Root.ViewModel.AddNewTabAsync(result, text, cancellationToken).ConfigureAwait(false);
return true;
Expand All @@ -81,6 +82,35 @@ public async Task<bool> ShouldShowOnActivatedAsync(CancellationToken cancellatio
return false;
}

private static bool FrameTriggersActivate(ParsedFrame frame)
{
if (frame is not ParsedStackFrame parsedFrame)
{
return false;
}

var methodDeclaration = parsedFrame.Root.MethodDeclaration;

// Find the first token
var firstNodeOrToken = methodDeclaration.ChildAt(0);
while (firstNodeOrToken.IsNode)
{
firstNodeOrToken = firstNodeOrToken.Node.ChildAt(0);
}

if (firstNodeOrToken.Token.LeadingTrivia.IsDefault)
{
return false;
}

// If the stack frame starts with "at" we consider it a well formed stack frame and
// want to automatically open the window. This helps avoids some false positive cases
// where the window shows on code that parses as a stack frame but may not be. The explorer
// should still handle those cases if explicitly pasted in, but can lead to false positives
// when automatically opening.
return firstNodeOrToken.Token.LeadingTrivia.Any(t => t.Kind == StackFrameKind.AtTrivia);
}

public void InitializeIfNeeded(RoslynPackage roslynPackage)
{
if (_initialized)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,5 +537,7 @@ internal enum FunctionId

Inline_Hints_DoubleClick = 530,
NavigateToExternalSources = 531,

StackTraceToolWindow_ShowOnActivated = 540,
}
}