Skip to content

Commit 966b854

Browse files
committed
Fix up return source for a mapped breakpoint
1 parent 27b16d9 commit 966b854

File tree

6 files changed

+54
-28
lines changed

6 files changed

+54
-28
lines changed

src/PowerShellEditorServices/Services/DebugAdapter/BreakpointService.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ public async Task<IReadOnlyList<Breakpoint>> GetBreakpointsAsync()
5757
.ConfigureAwait(false);
5858
}
5959

60-
public async Task<IReadOnlyList<BreakpointDetails>> SetBreakpointsAsync(string scriptPath, string escapedScriptPath, IReadOnlyList<BreakpointDetails> breakpoints)
60+
public async Task<IReadOnlyList<BreakpointDetails>> SetBreakpointsAsync(string escapedScriptPath, IReadOnlyList<BreakpointDetails> breakpoints)
6161
{
6262
if (BreakpointApiUtils.SupportsBreakpointApis(_editorServicesHost.CurrentRunspace))
6363
{
6464
foreach (BreakpointDetails breakpointDetails in breakpoints)
6565
{
6666
try
6767
{
68-
BreakpointApiUtils.SetBreakpoint(_editorServicesHost.Runspace.Debugger, breakpointDetails, _debugStateService.RunspaceId, scriptPathOverride: scriptPath);
68+
BreakpointApiUtils.SetBreakpoint(_editorServicesHost.Runspace.Debugger, breakpointDetails, _debugStateService.RunspaceId);
6969
}
7070
catch (InvalidOperationException e)
7171
{
@@ -140,7 +140,16 @@ public async Task<IReadOnlyList<BreakpointDetails>> SetBreakpointsAsync(string s
140140
IEnumerable<Breakpoint> setBreakpoints = await _executionService
141141
.ExecutePSCommandAsync<Breakpoint>(psCommand, CancellationToken.None)
142142
.ConfigureAwait(false);
143-
configuredBreakpoints.AddRange(setBreakpoints.Select((breakpoint) => BreakpointDetails.Create(breakpoint)));
143+
144+
int bpIdx = 0;
145+
foreach (Breakpoint setBp in setBreakpoints)
146+
{
147+
BreakpointDetails setBreakpoint = BreakpointDetails.Create(
148+
setBp,
149+
sourceBreakpoint: breakpoints[bpIdx]);
150+
configuredBreakpoints.Add(setBreakpoint);
151+
bpIdx++;
152+
}
144153
}
145154
return configuredBreakpoints;
146155
}

src/PowerShellEditorServices/Services/DebugAdapter/DebugService.cs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Execution;
1616
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Host;
1717
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Utility;
18-
using Microsoft.PowerShell.EditorServices.Services.TextDocument;
1918
using Microsoft.PowerShell.EditorServices.Utility;
2019

2120
namespace Microsoft.PowerShell.EditorServices.Services
@@ -123,26 +122,22 @@ public DebugService(
123122
/// <summary>
124123
/// Sets the list of line breakpoints for the current debugging session.
125124
/// </summary>
126-
/// <param name="scriptFile">The ScriptFile in which breakpoints will be set.</param>
125+
/// <param name="scriptPath">The path in which breakpoints will be set.</param>
127126
/// <param name="breakpoints">BreakpointDetails for each breakpoint that will be set.</param>
128127
/// <param name="clearExisting">If true, causes all existing breakpoints to be cleared before setting new ones.</param>
128+
/// <param name="skipRemoteMapping">If true, skips the remote file manager mapping of the script path.</param>
129129
/// <returns>An awaitable Task that will provide details about the breakpoints that were set.</returns>
130130
public async Task<IReadOnlyList<BreakpointDetails>> SetLineBreakpointsAsync(
131-
ScriptFile scriptFile,
131+
string scriptPath,
132132
IReadOnlyList<BreakpointDetails> breakpoints,
133-
bool clearExisting = true)
133+
bool clearExisting = true,
134+
bool skipRemoteMapping = false)
134135
{
135136
DscBreakpointCapability dscBreakpoints = await _debugContext.GetDscBreakpointCapabilityAsync().ConfigureAwait(false);
136137

137-
string scriptPath = scriptFile.FilePath;
138-
139138
_psesHost.Runspace.ThrowCancelledIfUnusable();
140139
// Make sure we're using the remote script path
141-
if (TryGetMappedRemotePath(scriptPath, out string remoteMappedPath))
142-
{
143-
scriptPath = remoteMappedPath;
144-
}
145-
else if (_psesHost.CurrentRunspace.IsOnRemoteMachine && _remoteFileManager is not null)
140+
if (!skipRemoteMapping && _psesHost.CurrentRunspace.IsOnRemoteMachine && _remoteFileManager is not null)
146141
{
147142
if (!_remoteFileManager.IsUnderRemoteTempPath(scriptPath))
148143
{
@@ -166,10 +161,10 @@ public async Task<IReadOnlyList<BreakpointDetails>> SetLineBreakpointsAsync(
166161
{
167162
if (clearExisting)
168163
{
169-
await _breakpointService.RemoveAllBreakpointsAsync(scriptFile.FilePath).ConfigureAwait(false);
164+
await _breakpointService.RemoveAllBreakpointsAsync(scriptPath).ConfigureAwait(false);
170165
}
171166

172-
return await _breakpointService.SetBreakpointsAsync(scriptPath, escapedScriptPath, breakpoints).ConfigureAwait(false);
167+
return await _breakpointService.SetBreakpointsAsync(escapedScriptPath, breakpoints).ConfigureAwait(false);
173168
}
174169

175170
return await dscBreakpoints

src/PowerShellEditorServices/Services/DebugAdapter/Debugging/BreakpointApiUtils.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ static BreakpointApiUtils()
110110

111111
#region Public Static Methods
112112

113-
public static Breakpoint SetBreakpoint(Debugger debugger, BreakpointDetailsBase breakpoint, int? runspaceId = null, string scriptPathOverride = null)
113+
public static Breakpoint SetBreakpoint(Debugger debugger, BreakpointDetailsBase breakpoint, int? runspaceId = null)
114114
{
115115
ScriptBlock actionScriptBlock = null;
116116
string logMessage = breakpoint is BreakpointDetails bd ? bd.LogMessage : null;
@@ -136,7 +136,7 @@ public static Breakpoint SetBreakpoint(Debugger debugger, BreakpointDetailsBase
136136
{
137137
BreakpointDetails lineBreakpoint => SetLineBreakpointDelegate(
138138
debugger,
139-
scriptPathOverride ?? lineBreakpoint.Source,
139+
lineBreakpoint.MappedSource ?? lineBreakpoint.Source,
140140
lineBreakpoint.LineNumber,
141141
lineBreakpoint.ColumnNumber ?? 0,
142142
actionScriptBlock,

src/PowerShellEditorServices/Services/DebugAdapter/Debugging/BreakpointDetails.cs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ internal sealed class BreakpointDetails : BreakpointDetailsBase
2424
/// </summary>
2525
public string Source { get; private set; }
2626

27+
/// <summary>
28+
/// Gets the source where the breakpoint is mapped to, will be null if no mapping exists. Used only for debug purposes.
29+
/// </summary>
30+
public string MappedSource { get; private set; }
31+
2732
/// <summary>
2833
/// Gets the line number at which the breakpoint is set.
2934
/// </summary>
@@ -50,14 +55,16 @@ private BreakpointDetails()
5055
/// <param name="condition"></param>
5156
/// <param name="hitCondition"></param>
5257
/// <param name="logMessage"></param>
58+
/// <param name="mappedSource"></param>
5359
/// <returns></returns>
5460
internal static BreakpointDetails Create(
5561
string source,
5662
int line,
5763
int? column = null,
5864
string condition = null,
5965
string hitCondition = null,
60-
string logMessage = null)
66+
string logMessage = null,
67+
string mappedSource = null)
6168
{
6269
Validate.IsNotNullOrEmptyString(nameof(source), source);
6370

@@ -69,7 +76,8 @@ internal static BreakpointDetails Create(
6976
ColumnNumber = column,
7077
Condition = condition,
7178
HitCondition = hitCondition,
72-
LogMessage = logMessage
79+
LogMessage = logMessage,
80+
MappedSource = mappedSource
7381
};
7482
}
7583

@@ -79,10 +87,12 @@ internal static BreakpointDetails Create(
7987
/// </summary>
8088
/// <param name="breakpoint">The Breakpoint instance from which details will be taken.</param>
8189
/// <param name="updateType">The BreakpointUpdateType to determine if the breakpoint is verified.</param>
90+
/// /// <param name="sourceBreakpoint">The breakpoint source from the debug client, if any.</param>
8291
/// <returns>A new instance of the BreakpointDetails class.</returns>
8392
internal static BreakpointDetails Create(
8493
Breakpoint breakpoint,
85-
BreakpointUpdateType updateType = BreakpointUpdateType.Set)
94+
BreakpointUpdateType updateType = BreakpointUpdateType.Set,
95+
BreakpointDetails sourceBreakpoint = null)
8696
{
8797
Validate.IsNotNull(nameof(breakpoint), breakpoint);
8898

@@ -96,10 +106,11 @@ internal static BreakpointDetails Create(
96106
{
97107
Id = breakpoint.Id,
98108
Verified = updateType != BreakpointUpdateType.Disabled,
99-
Source = lineBreakpoint.Script,
109+
Source = sourceBreakpoint?.MappedSource is not null ? sourceBreakpoint.Source : lineBreakpoint.Script,
100110
LineNumber = lineBreakpoint.Line,
101111
ColumnNumber = lineBreakpoint.Column,
102-
Condition = lineBreakpoint.Action?.ToString()
112+
Condition = lineBreakpoint.Action?.ToString(),
113+
MappedSource = sourceBreakpoint?.MappedSource,
103114
};
104115

105116
if (lineBreakpoint.Column > 0)

src/PowerShellEditorServices/Services/DebugAdapter/Handlers/BreakpointHandlers.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,20 @@ public async Task<SetBreakpointsResponse> Handle(SetBreakpointsArguments request
8383
}
8484

8585
// At this point, the source file has been verified as a PowerShell script.
86+
string mappedSource = null;
87+
if (_debugService.TryGetMappedRemotePath(scriptFile.FilePath, out string remoteMappedPath))
88+
{
89+
mappedSource = remoteMappedPath;
90+
}
8691
IReadOnlyList<BreakpointDetails> breakpointDetails = request.Breakpoints
8792
.Select((srcBreakpoint) => BreakpointDetails.Create(
8893
scriptFile.FilePath,
8994
srcBreakpoint.Line,
9095
srcBreakpoint.Column,
9196
srcBreakpoint.Condition,
9297
srcBreakpoint.HitCondition,
93-
srcBreakpoint.LogMessage)).ToList();
98+
srcBreakpoint.LogMessage,
99+
mappedSource: mappedSource)).ToList();
94100

95101
// If this is a "run without debugging (Ctrl+F5)" session ignore requests to set breakpoints.
96102
IReadOnlyList<BreakpointDetails> updatedBreakpointDetails = breakpointDetails;
@@ -102,8 +108,9 @@ public async Task<SetBreakpointsResponse> Handle(SetBreakpointsArguments request
102108
{
103109
updatedBreakpointDetails =
104110
await _debugService.SetLineBreakpointsAsync(
105-
scriptFile,
106-
breakpointDetails).ConfigureAwait(false);
111+
mappedSource ?? scriptFile.FilePath,
112+
breakpointDetails,
113+
skipRemoteMapping: mappedSource is not null).ConfigureAwait(false);
107114
}
108115
catch (Exception e)
109116
{

src/PowerShellEditorServices/Services/DebugAdapter/PathMapping.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4+
#nullable enable
5+
46
namespace Microsoft.PowerShell.EditorServices.Services;
57

68
/// <summary>
@@ -11,10 +13,12 @@ internal record PathMapping
1113
/// <summary>
1214
/// Gets or sets the local root of this mapping entry.
1315
/// </summary>
14-
public string LocalRoot { get; set; }
16+
public string? LocalRoot { get; set; }
1517

1618
/// <summary>
1719
/// Gets or sets the remote root of this mapping entry.
1820
/// </summary>
19-
public string RemoteRoot { get; set; }
21+
public string? RemoteRoot { get; set; }
2022
}
23+
24+
#nullable disable

0 commit comments

Comments
 (0)