Skip to content

Commit a13539d

Browse files
committed
Fix occasional crash when requesting IntelliSense while debugging
This change fixes an issue where calling TabExpansion2 while debugging will sometimes cause a crash due to it returning an ErrorRecord instead of a CommandCompletion. The fix is to expect the possibility of the ErrorRecord and log it when it occurs. Resolves PowerShell#427.
1 parent 885dcab commit a13539d

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/PowerShellEditorServices/Language/AstOperations.cs

+14-2
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,21 @@ static public async Task<CommandCompletion> GetCompletions(
9090
command.AddParameter("PositionOfCursor", cursorPosition);
9191
command.AddParameter("Options", null);
9292

93-
commandCompletion =
94-
(await powerShellContext.ExecuteCommand<CommandCompletion>(command, false, false))
93+
PSObject outputObject =
94+
(await powerShellContext.ExecuteCommand<PSObject>(command, false, false))
9595
.FirstOrDefault();
96+
97+
ErrorRecord errorRecord = outputObject.BaseObject as ErrorRecord;
98+
if (errorRecord != null)
99+
{
100+
Logger.WriteException(
101+
"Encountered an error while invoking TabExpansion2 in the debugger",
102+
errorRecord.Exception);
103+
}
104+
else
105+
{
106+
commandCompletion = outputObject.BaseObject as CommandCompletion;
107+
}
96108
}
97109
else if (powerShellContext.CurrentRunspace.Runspace.RunspaceAvailability ==
98110
RunspaceAvailability.Available)

0 commit comments

Comments
 (0)