public async Task <EvaluateResponseBody> Handle(EvaluateRequestArguments request, CancellationToken cancellationToken)
        {
            string valueString = "";
            int    variableId  = 0;

            bool isFromRepl =
                string.Equals(
                    request.Context,
                    "repl",
                    StringComparison.CurrentCultureIgnoreCase);

            if (isFromRepl)
            {
                var notAwaited =
                    _powerShellContextService
                    .ExecuteScriptStringAsync(request.Expression, false, true)
                    .ConfigureAwait(false);
            }
            else
            {
                VariableDetailsBase result = null;

                // VS Code might send this request after the debugger
                // has been resumed, return an empty result in this case.
                if (_powerShellContextService.IsDebuggerStopped)
                {
                    // First check to see if the watch expression refers to a naked variable reference.
                    result =
                        _debugService.GetVariableFromExpression(request.Expression, request.FrameId);

                    // If the expression is not a naked variable reference, then evaluate the expression.
                    if (result == null)
                    {
                        result =
                            await _debugService.EvaluateExpressionAsync(
                                request.Expression,
                                request.FrameId,
                                isFromRepl);
                    }
                }

                if (result != null)
                {
                    valueString = result.ValueString;
                    variableId  =
                        result.IsExpandable ?
                        result.Id : 0;
                }
            }

            return(new EvaluateResponseBody
            {
                Result = valueString,
                VariablesReference = variableId
            });
        }
        public async Task <EvaluateResponseBody> Handle(EvaluateRequestArguments request, CancellationToken cancellationToken)
        {
            string valueString = "";
            int    variableId  = 0;

            bool isFromRepl =
                string.Equals(
                    request.Context,
                    "repl",
                    StringComparison.CurrentCultureIgnoreCase);

            if (isFromRepl)
            {
                await _executionService.ExecutePSCommandAsync(
                    new PSCommand().AddScript(request.Expression),
                    CancellationToken.None,
                    new PowerShellExecutionOptions { WriteOutputToHost = true, ThrowOnError = false, AddToHistory = true }).HandleErrorsAsync(_logger).ConfigureAwait(false);
            }
            else
            {
                VariableDetailsBase result = null;

                // VS Code might send this request after the debugger
                // has been resumed, return an empty result in this case.
                if (_debugContext.IsStopped)
                {
                    // First check to see if the watch expression refers to a naked variable reference.
                    result = _debugService.GetVariableFromExpression(request.Expression);

                    // If the expression is not a naked variable reference, then evaluate the expression.
                    if (result == null)
                    {
                        result =
                            await _debugService.EvaluateExpressionAsync(
                                request.Expression,
                                isFromRepl).ConfigureAwait(false);
                    }
                }

                if (result != null)
                {
                    valueString = result.ValueString;
                    variableId  =
                        result.IsExpandable ?
                        result.Id : 0;
                }
            }

            return(new EvaluateResponseBody
            {
                Result = valueString,
                VariablesReference = variableId
            });
        }
Ejemplo n.º 3
0
        public Task <EvaluateResponseBody> Handle(EvaluateRequestArguments request, CancellationToken cancellationToken)
        {
            _powerShellContextService.ExecuteScriptStringAsync(
                request.Expression,
                writeInputToHost: true,
                writeOutputToHost: true,
                addToHistory: true);

            return(Task.FromResult(new EvaluateResponseBody
            {
                Result = "",
                VariablesReference = 0
            }));
        }
        public async Task <EvaluateResponseBody> Handle(EvaluateRequestArguments request, CancellationToken cancellationToken)
        {
            // This API is mostly used for F8 execution, so it needs to interrupt the command prompt
            // (or other foreground task).
            await _executionService.ExecutePSCommandAsync(
                new PSCommand().AddScript(request.Expression),
                CancellationToken.None,
                new PowerShellExecutionOptions
            {
                WriteInputToHost           = true,
                WriteOutputToHost          = true,
                AddToHistory               = true,
                ThrowOnError               = false,
                InterruptCurrentForeground = true
            }).ConfigureAwait(false);

            // TODO: Should we return a more informative result?
            return(new EvaluateResponseBody
            {
                Result = "",
                VariablesReference = 0
            });
        }