diff --git a/src/PowerShellEditorServices/Language/AstOperations.cs b/src/PowerShellEditorServices/Language/AstOperations.cs index aa27bead4..67533903a 100644 --- a/src/PowerShellEditorServices/Language/AstOperations.cs +++ b/src/PowerShellEditorServices/Language/AstOperations.cs @@ -90,9 +90,24 @@ static public async Task GetCompletions( command.AddParameter("PositionOfCursor", cursorPosition); command.AddParameter("Options", null); - commandCompletion = - (await powerShellContext.ExecuteCommand(command, false, false)) + PSObject outputObject = + (await powerShellContext.ExecuteCommand(command, false, false)) .FirstOrDefault(); + + if (outputObject != null) + { + ErrorRecord errorRecord = outputObject.BaseObject as ErrorRecord; + if (errorRecord != null) + { + Logger.WriteException( + "Encountered an error while invoking TabExpansion2 in the debugger", + errorRecord.Exception); + } + else + { + commandCompletion = outputObject.BaseObject as CommandCompletion; + } + } } else if (powerShellContext.CurrentRunspace.Runspace.RunspaceAvailability == RunspaceAvailability.Available)