Skip to content

Fix stack trace so it shows external code as "deemphasized". #537

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

Merged
merged 1 commit into from
Jul 6, 2017
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
27 changes: 27 additions & 0 deletions src/PowerShellEditorServices.Protocol/DebugAdapter/Source.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,33 @@ public class Source
public string Path { get; set; }

public int? SourceReference { get; set; }

/// <summary>
/// Gets an optional hint for how to present the source in the UI. A value of 'deemphasize'
/// can be used to indicate that the source is not available or that it is skipped on stepping.
/// </summary>
public string PresentationHint { get; set; }
}

/// <summary>
/// An optional hint for how to present source in the UI.
/// </summary>
public enum SourcePresentationHint
{
/// <summary>
/// Dispays the source normally.
/// </summary>
Normal,

/// <summary>
/// Display the source emphasized.
/// </summary>
Emphasize,

/// <summary>
/// Display the source deemphasized.
/// </summary>
Deemphasize
}
}

29 changes: 27 additions & 2 deletions src/PowerShellEditorServices.Protocol/DebugAdapter/StackFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ public static StackFrame Create(
StackFrameDetails stackFrame,
int id)
{
var sourcePresentationHint =
stackFrame.IsExternalCode ? SourcePresentationHint.Deemphasize : SourcePresentationHint.Normal;

return new StackFrame
{
Id = id,
Expand All @@ -66,13 +69,35 @@ public static StackFrame Create(
EndLine = stackFrame.EndLineNumber,
Column = stackFrame.StartColumnNumber,
EndColumn = stackFrame.EndColumnNumber,
PresentationHint = stackFrame.PresentationHint.ToString().ToLower(),
Source = new Source
{
Path = stackFrame.ScriptPath
Path = stackFrame.ScriptPath,
PresentationHint = sourcePresentationHint.ToString().ToLower()
}
};
}
}

/// <summary>
/// An optional hint for how to present a stack frame in the UI.
/// </summary>
public enum StackFramePresentationHint
{
/// <summary>
/// Dispays the stack frame as a normal stack frame.
/// </summary>
Normal,

/// <summary>
/// Used to label an entry in the call stack that doesn't actually correspond to a stack frame.
/// This is typically used to label transitions to/from "external" code.
/// </summary>
Label,

/// <summary>
/// Displays the stack frame in a subtle way, typically used from loctaions outside of the current project or workspace.
/// </summary>
Subtle
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be Deemphasize too or are they inconsistent?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird as it seems, the PresentationHint on StackFrame has different values than the PresentationHint on Source. https://github.com/Microsoft/vscode-debugadapter-node/blob/master/protocol/src/debugProtocol.ts#L1131

That accounts for part of the confusion I was running into. And then there was also the typo in the VSCode impl. But this works with 1.13.1 so yay!

}
}

33 changes: 6 additions & 27 deletions src/PowerShellEditorServices/Debugging/StackFrameDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,6 @@

namespace Microsoft.PowerShell.EditorServices
{
/// <summary>
/// An optional hint for how to present a stack frame in the UI.
/// </summary>
public enum StackFramePresentationHint
{
/// <summary>
/// Dispays the stack frame as a normal stack frame.
/// </summary>
Normal,

/// <summary>
/// Used to label an entry in the call stack that doesn't actually correspond to a stack frame.
/// This is typically used to label transitions to/from "external" code.
/// </summary>
Label,

/// <summary>
/// Displays the stack frame in a subtle way, typically used from loctaions outside of the current project or workspace.
/// </summary>
Subtle
}

/// <summary>
/// Contains details pertaining to a single stack frame in
/// the current debugging session.
Expand Down Expand Up @@ -79,9 +57,10 @@ public class StackFrameDetails
public int? EndColumnNumber { get; internal set; }

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

/// <summary>
/// Gets or sets the VariableContainerDetails that contains the auto variables.
Expand Down Expand Up @@ -122,7 +101,7 @@ static internal StackFrameDetails Create(
string workspaceRootPath = null)
{
string moduleId = string.Empty;
var presentationHint = StackFramePresentationHint.Normal;
var isExternal = false;

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

return new StackFrameDetails
Expand All @@ -145,7 +124,7 @@ static internal StackFrameDetails Create(
EndColumnNumber = 0,
AutoVariables = autoVariables,
LocalVariables = localVariables,
PresentationHint = presentationHint
IsExternalCode = isExternal
};
}

Expand Down