Skip to content

Commit 090c97d

Browse files
authored
Fix stack trace so it shows external code as "deemphasized". (#537)
1 parent 01b1a14 commit 090c97d

File tree

3 files changed

+60
-29
lines changed

3 files changed

+60
-29
lines changed

src/PowerShellEditorServices.Protocol/DebugAdapter/Source.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,33 @@ public class Source
1212
public string Path { get; set; }
1313

1414
public int? SourceReference { get; set; }
15+
16+
/// <summary>
17+
/// Gets an optional hint for how to present the source in the UI. A value of 'deemphasize'
18+
/// can be used to indicate that the source is not available or that it is skipped on stepping.
19+
/// </summary>
20+
public string PresentationHint { get; set; }
21+
}
22+
23+
/// <summary>
24+
/// An optional hint for how to present source in the UI.
25+
/// </summary>
26+
public enum SourcePresentationHint
27+
{
28+
/// <summary>
29+
/// Dispays the source normally.
30+
/// </summary>
31+
Normal,
32+
33+
/// <summary>
34+
/// Display the source emphasized.
35+
/// </summary>
36+
Emphasize,
37+
38+
/// <summary>
39+
/// Display the source deemphasized.
40+
/// </summary>
41+
Deemphasize
1542
}
1643
}
1744

src/PowerShellEditorServices.Protocol/DebugAdapter/StackFrame.cs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ public static StackFrame Create(
5858
StackFrameDetails stackFrame,
5959
int id)
6060
{
61+
var sourcePresentationHint =
62+
stackFrame.IsExternalCode ? SourcePresentationHint.Deemphasize : SourcePresentationHint.Normal;
63+
6164
return new StackFrame
6265
{
6366
Id = id,
@@ -66,13 +69,35 @@ public static StackFrame Create(
6669
EndLine = stackFrame.EndLineNumber,
6770
Column = stackFrame.StartColumnNumber,
6871
EndColumn = stackFrame.EndColumnNumber,
69-
PresentationHint = stackFrame.PresentationHint.ToString().ToLower(),
7072
Source = new Source
7173
{
72-
Path = stackFrame.ScriptPath
74+
Path = stackFrame.ScriptPath,
75+
PresentationHint = sourcePresentationHint.ToString().ToLower()
7376
}
7477
};
7578
}
7679
}
80+
81+
/// <summary>
82+
/// An optional hint for how to present a stack frame in the UI.
83+
/// </summary>
84+
public enum StackFramePresentationHint
85+
{
86+
/// <summary>
87+
/// Dispays the stack frame as a normal stack frame.
88+
/// </summary>
89+
Normal,
90+
91+
/// <summary>
92+
/// Used to label an entry in the call stack that doesn't actually correspond to a stack frame.
93+
/// This is typically used to label transitions to/from "external" code.
94+
/// </summary>
95+
Label,
96+
97+
/// <summary>
98+
/// Displays the stack frame in a subtle way, typically used from loctaions outside of the current project or workspace.
99+
/// </summary>
100+
Subtle
101+
}
77102
}
78103

src/PowerShellEditorServices/Debugging/StackFrameDetails.cs

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,6 @@
88

99
namespace Microsoft.PowerShell.EditorServices
1010
{
11-
/// <summary>
12-
/// An optional hint for how to present a stack frame in the UI.
13-
/// </summary>
14-
public enum StackFramePresentationHint
15-
{
16-
/// <summary>
17-
/// Dispays the stack frame as a normal stack frame.
18-
/// </summary>
19-
Normal,
20-
21-
/// <summary>
22-
/// Used to label an entry in the call stack that doesn't actually correspond to a stack frame.
23-
/// This is typically used to label transitions to/from "external" code.
24-
/// </summary>
25-
Label,
26-
27-
/// <summary>
28-
/// Displays the stack frame in a subtle way, typically used from loctaions outside of the current project or workspace.
29-
/// </summary>
30-
Subtle
31-
}
32-
3311
/// <summary>
3412
/// Contains details pertaining to a single stack frame in
3513
/// the current debugging session.
@@ -79,9 +57,10 @@ public class StackFrameDetails
7957
public int? EndColumnNumber { get; internal set; }
8058

8159
/// <summary>
82-
/// Gets a hint value that determines how the stack frame should be displayed.
60+
/// Gets a boolean value indicating whether or not the stack frame is executing
61+
/// in script external to the current workspace root.
8362
/// </summary>
84-
public StackFramePresentationHint PresentationHint { get; internal set; }
63+
public bool IsExternalCode { get; internal set; }
8564

8665
/// <summary>
8766
/// Gets or sets the VariableContainerDetails that contains the auto variables.
@@ -122,7 +101,7 @@ static internal StackFrameDetails Create(
122101
string workspaceRootPath = null)
123102
{
124103
string moduleId = string.Empty;
125-
var presentationHint = StackFramePresentationHint.Normal;
104+
var isExternal = false;
126105

127106
var invocationInfo = callStackFrameObject.Properties["InvocationInfo"]?.Value as InvocationInfo;
128107
string scriptPath = (callStackFrameObject.Properties["ScriptName"].Value as string) ?? NoFileScriptPath;
@@ -132,7 +111,7 @@ static internal StackFrameDetails Create(
132111
invocationInfo != null &&
133112
!scriptPath.StartsWith(workspaceRootPath, StringComparison.OrdinalIgnoreCase))
134113
{
135-
presentationHint = StackFramePresentationHint.Subtle;
114+
isExternal = true;
136115
}
137116

138117
return new StackFrameDetails
@@ -145,7 +124,7 @@ static internal StackFrameDetails Create(
145124
EndColumnNumber = 0,
146125
AutoVariables = autoVariables,
147126
LocalVariables = localVariables,
148-
PresentationHint = presentationHint
127+
IsExternalCode = isExternal
149128
};
150129
}
151130

0 commit comments

Comments
 (0)