Skip to content

Commit c12dc8d

Browse files
Перенос замены пути в DebugeeProcess, обработка приема
1 parent 46d1f63 commit c12dc8d

2 files changed

Lines changed: 47 additions & 34 deletions

File tree

src/VSCode.DebugAdapter/DebugeeProcess.cs

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,41 @@ private void RaiseOutputReceivedEvent(string category, string data)
198198
OutputReceived?.Invoke(this, new DebugeeOutputEventArgs(category, data));
199199
}
200200

201+
private string ApplyRemoteWorkspaceString(string path)
202+
{
203+
var clientPath = path;
204+
205+
if (!string.IsNullOrWhiteSpace(HostWorkspace) && !string.IsNullOrWhiteSpace(RemoteWorkspace))
206+
{
207+
208+
var hostWorkspace = HostWorkspace;
209+
var remoteWorkspace = RemoteWorkspace;
210+
211+
string normalizedClientPath = clientPath.Replace('/', '\\').Trim();
212+
string normalizedHostWorkspace = hostWorkspace.Replace('/', '\\').Trim();
213+
214+
if (!normalizedHostWorkspace.EndsWith("\\"))
215+
normalizedHostWorkspace += "\\";
216+
217+
if (normalizedClientPath.StartsWith(normalizedHostWorkspace, StringComparison.OrdinalIgnoreCase))
218+
{
219+
220+
string relativePath = normalizedClientPath.Substring(normalizedHostWorkspace.Length);
221+
222+
string normalizedRemote = remoteWorkspace.Trim().Replace('\\', '/');
223+
normalizedRemote = normalizedRemote.TrimEnd('/');
224+
225+
clientPath = string.IsNullOrEmpty(relativePath)
226+
? normalizedRemote
227+
: normalizedRemote + "/" + relativePath.Replace('\\', '/');
228+
229+
}
230+
}
231+
232+
return clientPath;
233+
234+
}
235+
201236
private void Terminate()
202237
{
203238
if (!_terminated)
@@ -273,7 +308,14 @@ public void SetExceptionsBreakpoints((string Id, string Condition)[] filters)
273308

274309
public Breakpoint[] SetBreakpoints(IEnumerable<Breakpoint> breakpoints)
275310
{
276-
var confirmedBreaks = _debugger.SetMachineBreakpoints(breakpoints.ToArray());
311+
var breakpointsArray = breakpoints.ToArray();
312+
313+
for (int i = 0; i < breakpointsArray.Length; i++)
314+
{
315+
breakpointsArray[i].Source = ApplyRemoteWorkspaceString(breakpointsArray[i].Source);
316+
}
317+
318+
var confirmedBreaks = _debugger.SetMachineBreakpoints(breakpointsArray);
277319

278320
return confirmedBreaks;
279321
}
@@ -297,6 +339,7 @@ public StackFrame[] GetStackTrace(int threadId, int firstFrameIdx, int limit)
297339
for (int i = firstFrameIdx; i < limit && i < allFrames.Length; i++)
298340
{
299341
allFrames[i].ThreadId = threadId;
342+
allFrames[i].Source = ApplyRemoteWorkspaceString(allFrames[i].Source);
300343
result.Add(allFrames[i]);
301344
}
302345

src/VSCode.DebugAdapter/OscriptDebugSession.cs

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -268,40 +268,10 @@ public override void SetBreakpoints(Response response, dynamic arguments)
268268

269269
private string NormalizeDriveLetter(string path)
270270
{
271-
var clientPath = path;
272-
273271
if (Path.IsPathRooted(path))
274-
clientPath = path[0].ToString().ToUpperInvariant() + path.Substring(1);
275-
276-
if (!string.IsNullOrWhiteSpace(_debuggee.HostWorkspace) && !string.IsNullOrWhiteSpace(_debuggee.RemoteWorkspace))
277-
{
278-
279-
var hostWorkspace = _debuggee.HostWorkspace;
280-
var remoteWorkspace = _debuggee.RemoteWorkspace;
281-
282-
string normalizedClientPath = clientPath.Replace('/', '\\').Trim();
283-
string normalizedHostWorkspace = hostWorkspace.Replace('/', '\\').Trim();
284-
285-
if (!normalizedHostWorkspace.EndsWith("\\"))
286-
normalizedHostWorkspace += "\\";
287-
288-
if (normalizedClientPath.StartsWith(normalizedHostWorkspace, StringComparison.OrdinalIgnoreCase))
289-
{
290-
291-
string relativePath = normalizedClientPath.Substring(normalizedHostWorkspace.Length);
292-
293-
string normalizedRemote = remoteWorkspace.Trim().Replace('\\', '/');
294-
normalizedRemote = normalizedRemote.TrimEnd('/');
295-
296-
string result = string.IsNullOrEmpty(relativePath)
297-
? normalizedRemote
298-
: normalizedRemote + "/" + relativePath.Replace('\\', '/');
299-
300-
return result;
301-
}
302-
}
303-
304-
return clientPath;
272+
return path[0].ToString().ToUpperInvariant() + path.Substring(1);
273+
else
274+
return path;
305275

306276
}
307277

0 commit comments

Comments
 (0)