protected async Task HandleEvaluateRequestAsync(
            EvaluateRequestArguments evaluateParams,
            RequestContext <EvaluateResponseBody> requestContext)
        {
            string valueString = null;
            int    variableId  = 0;

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

            if (isFromRepl)
            {
                var notAwaited =
                    _editorSession
                    .PowerShellContext
                    .ExecuteScriptStringAsync(evaluateParams.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 (_editorSession.PowerShellContext.IsDebuggerStopped)
                {
                    // First check to see if the watch expression refers to a naked variable reference.
                    result =
                        _editorSession.DebugService.GetVariableFromExpression(evaluateParams.Expression, evaluateParams.FrameId);

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

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

            await requestContext.SendResultAsync(
                new EvaluateResponseBody
            {
                Result             = valueString,
                VariablesReference = variableId
            });
        }
Exemplo n.º 2
0
        protected async Task HandleEvaluateRequest(
            EvaluateRequestArguments evaluateParams,
            RequestContext <EvaluateResponseBody> requestContext)
        {
            // TODO: This needs to respect debug mode!

            var evaluateResponse =
                new EvaluateResponseBody
            {
                Result             = "",
                VariablesReference = 0
            };

            if (this.commandLineInputTask != null)
            {
                this.commandLineInputTask.SetResult(evaluateParams.Expression);
                await requestContext.SendResult(evaluateResponse);
            }
            else
            {
                // Check for special commands
                if (string.Equals("!ctrlc", evaluateParams.Expression, StringComparison.CurrentCultureIgnoreCase))
                {
                    this.powerShellContext.AbortExecution();
                    await requestContext.SendResult(evaluateResponse);
                }
                else if (string.Equals("!break", evaluateParams.Expression, StringComparison.CurrentCultureIgnoreCase))
                {
                    // TODO: Need debugger commands interface
                    //editorSession.DebugService.Break();
                    await requestContext.SendResult(evaluateResponse);
                }
                else
                {
                    // We don't await the result of the execution here because we want
                    // to be able to receive further messages while the current script
                    // is executing.  This important in cases where the pipeline thread
                    // gets blocked by something in the script like a prompt to the user.
                    var executeTask =
                        this.powerShellContext.ExecuteScriptString(
                            evaluateParams.Expression,
                            writeInputToHost: true,
                            writeOutputToHost: true,
                            addToHistory: true);

                    // Return the execution result after the task completes so that the
                    // caller knows when command execution completed.
                    Task unusedTask =
                        executeTask.ContinueWith(
                            (task) =>
                    {
                        // Return an empty result since the result value is irrelevant
                        // for this request in the LanguageServer
                        return
                        (requestContext.SendResult(
                             evaluateResponse));
                    });
                }
            }
        }
        protected async Task HandleEvaluateRequest(
            EvaluateRequestArguments evaluateParams,
            EditorSession editorSession,
            RequestContext <EvaluateResponseBody, object> requestContext)
        {
            VariableDetails result =
                await editorSession.DebugService.EvaluateExpression(
                    evaluateParams.Expression,
                    evaluateParams.FrameId);

            string valueString = null;
            int    variableId  = 0;

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

            await requestContext.SendResult(
                new EvaluateResponseBody
            {
                Result             = valueString,
                VariablesReference = variableId
            });
        }
Exemplo n.º 4
0
        protected async Task HandleEvaluateRequest(
            EvaluateRequestArguments evaluateParams,
            RequestContext <EvaluateResponseBody> requestContext)
        {
            string valueString = null;
            int    variableId  = 0;

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

            if (isFromRepl)
            {
                // Check for special commands
                if (string.Equals("!ctrlc", evaluateParams.Expression, StringComparison.CurrentCultureIgnoreCase))
                {
                    editorSession.PowerShellContext.AbortExecution();
                }
                else if (string.Equals("!break", evaluateParams.Expression, StringComparison.CurrentCultureIgnoreCase))
                {
                    editorSession.DebugService.Break();
                }
                else
                {
                    // Send the input through the console service
                    editorSession.ConsoleService.ExecuteCommand(
                        evaluateParams.Expression,
                        false);
                }
            }
            else
            {
                VariableDetails result =
                    await editorSession.DebugService.EvaluateExpression(
                        evaluateParams.Expression,
                        evaluateParams.FrameId,
                        isFromRepl);

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

            await requestContext.SendResult(
                new EvaluateResponseBody
            {
                Result             = valueString,
                VariablesReference = variableId
            });
        }
        protected async Task HandleEvaluateRequest(
            EvaluateRequestArguments evaluateParams,
            RequestContext <EvaluateResponseBody> requestContext)
        {
            string valueString = null;
            int    variableId  = 0;

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

            if (isFromRepl)
            {
                // TODO: Do we send the input through the command handler?
                // Send the input through the console service
                var notAwaited =
                    this.editorSession
                    .PowerShellContext
                    .ExecuteScriptString(evaluateParams.Expression, false, true)
                    .ConfigureAwait(false);
            }
            else
            {
                VariableDetails result = null;

                // VS Code might send this request after the debugger
                // has been resumed, return an empty result in this case.
                if (editorSession.PowerShellContext.IsDebuggerStopped)
                {
                    result =
                        await editorSession.DebugService.EvaluateExpression(
                            evaluateParams.Expression,
                            evaluateParams.FrameId,
                            isFromRepl);
                }

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

            await requestContext.SendResult(
                new EvaluateResponseBody
            {
                Result             = valueString,
                VariablesReference = variableId
            });
        }