Skip to content

Commit 5807f08

Browse files
address robs feedback
1 parent 750f17d commit 5807f08

File tree

3 files changed

+30
-33
lines changed

3 files changed

+30
-33
lines changed

src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs

+9-21
Original file line numberDiff line numberDiff line change
@@ -494,31 +494,19 @@ protected async Task HandleSetBreakpointsRequest(
494494
{
495495
ScriptFile scriptFile = null;
496496

497-
// Fix for issue #195 - user can change name of file outside of VSCode in which case
498-
// VSCode sends breakpoint requests with the original filename that doesn't exist anymore.
499-
try
500-
{
501-
// When you set a breakpoint in the right pane of a Git diff window on a PS1 file,
502-
// the Source.Path comes through as Untitled-X.
503-
if (!ScriptFile.IsUntitledPath(setBreakpointsParams.Source.Path))
504-
{
505-
scriptFile = _editorSession.Workspace.GetFile(setBreakpointsParams.Source.Path);
506-
}
507-
}
508-
catch (Exception e) when (
509-
e is FileNotFoundException ||
510-
e is DirectoryNotFoundException ||
511-
e is IOException ||
512-
e is NotSupportedException ||
513-
e is PathTooLongException ||
514-
e is SecurityException ||
515-
e is UnauthorizedAccessException)
497+
// When you set a breakpoint in the right pane of a Git diff window on a PS1 file,
498+
// the Source.Path comes through as Untitled-X. That's why we check for IsUntitledPath.
499+
if (!ScriptFile.IsUntitledPath(setBreakpointsParams.Source.Path) &&
500+
!_editorSession.Workspace.TryGetFile(
501+
setBreakpointsParams.Source.Path,
502+
out scriptFile,
503+
out Exception exception))
516504
{
517505
Logger.WriteException(
518506
$"Failed to set breakpoint on file: {setBreakpointsParams.Source.Path}",
519-
e);
507+
exception);
520508

521-
string message = _noDebug ? string.Empty : "Source file could not be accessed, breakpoint not set - " + e.Message;
509+
string message = _noDebug ? string.Empty : "Source file could not be accessed, breakpoint not set - " + exception.Message;
522510
var srcBreakpoints = setBreakpointsParams.Breakpoints
523511
.Select(srcBkpt => Protocol.DebugAdapter.Breakpoint.Create(
524512
srcBkpt, setBreakpointsParams.Source.Path, message, verified: _noDebug));

src/PowerShellEditorServices/Language/LanguageService.cs

+1-11
Original file line numberDiff line numberDiff line change
@@ -342,17 +342,7 @@ public async Task<FindReferencesResult> FindReferencesOfSymbol(
342342
{
343343
if (!fileMap.Contains(file))
344344
{
345-
ScriptFile scriptFile;
346-
try
347-
{
348-
scriptFile = workspace.GetFile(file);
349-
}
350-
catch (Exception e) when (e is IOException
351-
|| e is SecurityException
352-
|| e is FileNotFoundException
353-
|| e is DirectoryNotFoundException
354-
|| e is PathTooLongException
355-
|| e is UnauthorizedAccessException)
345+
if (!workspace.TryGetFile(file, out ScriptFile scriptFile))
356346
{
357347
// If we can't access the file for some reason, just ignore it
358348
continue;

src/PowerShellEditorServices/Workspace/Workspace.cs

+20-1
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,34 @@ public ScriptFile GetFile(string filePath)
107107
/// <param name="filePath">The file path at which the script resides.</param>
108108
/// <param name="scriptFile">The out parameter that will contain the ScriptFile object.</param>
109109
public bool TryGetFile(string filePath, out ScriptFile scriptFile)
110+
{
111+
return TryGetFile(filePath, out scriptFile, out Exception e);
112+
}
113+
114+
/// <summary>
115+
/// Tries to get an open file in the workspace. Returns true or false if it succeeds.
116+
/// </summary>
117+
/// <param name="filePath">The file path at which the script resides.</param>
118+
/// <param name="scriptFile">The out parameter that will contain the ScriptFile object.</param>
119+
/// <param name="exception">The out parameter that will contain the underlying exception.</param>
120+
public bool TryGetFile(string filePath, out ScriptFile scriptFile, out Exception exception)
110121
{
111122
try
112123
{
113124
scriptFile = GetFile(filePath);
125+
exception = null;
114126
return true;
115127
}
116-
catch (FileNotFoundException)
128+
catch (Exception e) when (
129+
e is IOException ||
130+
e is SecurityException ||
131+
e is FileNotFoundException ||
132+
e is DirectoryNotFoundException ||
133+
e is PathTooLongException ||
134+
e is UnauthorizedAccessException)
117135
{
118136
scriptFile = null;
137+
exception = e;
119138
return false;
120139
}
121140
}

0 commit comments

Comments
 (0)