Skip to content

Commit 009dba4

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 009dba4

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/PowerShellEditorServices/Language/AstOperations.cs

+17-2
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,24 @@ 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+
if (outputObject != null)
98+
{
99+
ErrorRecord errorRecord = outputObject.BaseObject as ErrorRecord;
100+
if (errorRecord != null)
101+
{
102+
Logger.WriteException(
103+
"Encountered an error while invoking TabExpansion2 in the debugger",
104+
errorRecord.Exception);
105+
}
106+
else
107+
{
108+
commandCompletion = outputObject.BaseObject as CommandCompletion;
109+
}
110+
}
96111
}
97112
else if (powerShellContext.CurrentRunspace.Runspace.RunspaceAvailability ==
98113
RunspaceAvailability.Available)

0 commit comments

Comments
 (0)