Exemplo n.º 1
0
        public override void Attach(Response response, dynamic arguments)
        {
            _attachMode = true;

            var host = DynamicHelper.GetString(arguments, "address");

            if (host == null)
            {
                SendErrorResponse(response, 3007, "Property 'address' is missing or empty.");
                return;
            }

            // validate argument 'port'
            var port = DynamicHelper.GetInt(arguments, "port", -1);

            if (port == -1)
            {
                SendErrorResponse(response, 3008, "Property 'port' is missing.");
                return;
            }

            IPAddress address = Utilities.ResolveIPAddress(host);

            if (address == null)
            {
                SendErrorResponse(response, 3013, "Invalid address '{address}'.", new { address });
                return;
            }

            Connect(address, port);

            SendResponse(response);
        }
Exemplo n.º 2
0
        public override void Evaluate(Response response, dynamic arguments)
        {
            var expStr = (string)DynamicHelper.GetString(arguments, "expression");
            var exp    = AphidParser.ParseExpression(expStr);

            var retExp =
                exp.Type != AphidExpressionType.UnaryOperatorExpression ||
                ((UnaryOperatorExpression)exp).Operator != AphidTokenType.retKeyword ?
                new UnaryOperatorExpression(
                    AphidTokenType.retKeyword,
                    exp,
                    isPostfix: false)
                .WithPositionFrom(exp) :
                exp;

            AphidObject value = null;

            try
            {
                value = Interpreter.CreateChild(createChildScope: false).Interpret(exp);
            }
            catch (Exception e)
            {
                SendErrorResponse(response, 3014, ErrorFormatter.FormatByType(e, expStr));
            }

            if (value == null)
            {
                return;
            }

            var v = _explorer.CreateVariable(new KeyValuePair <string, AphidObject>(expStr, value));

            SendResponse(response, new EvaluateResponseBody(v.value, v.variablesReference));


            //var value = (AphidObject)new AphidInterpreter(Interpreter.CurrentScope).Interpret(exp);

            //if (false)
            //{
            //    SendErrorResponse(response, 3014, "Evaluate request failed, invalid expression");
            //}
            //else
            //{
            //    var handle = _variableHandles.Create(value.ToArray());
            //    SendResponse(
            //        response,
            //        new EvaluateResponseBody(
            //            new AphidSerializer(Interpreter).Serialize(value),
            //            handle));
            //}
        }
Exemplo n.º 3
0
        public override async void Launch(Response response, dynamic arguments)
        {
            _attachMode = false;

            //SetExceptionBreakpoints(args.__exceptionOptions);

            // validate argument 'program'
            string programPath = DynamicHelper.GetString(arguments, "program");

            if (programPath == null)
            {
                SendErrorResponse(response, 3001, "Property 'program' is missing or empty.", null);
                return;
            }

            //Program.Log("Program path: {0}\r\n", programPath);

            programPath = ConvertClientPathToDebugger(programPath);
            if (!File.Exists(programPath) && !Directory.Exists(programPath))
            {
                SendErrorResponse(response, 3002, "Program '{path}' does not exist.", new { path = programPath });
                return;
            }

            // validate argument 'cwd'
            var workingDirectory = (string)arguments.cwd;

            if (workingDirectory != null)
            {
                workingDirectory = workingDirectory.Trim();
                if (workingDirectory.Length == 0)
                {
                    SendErrorResponse(response, 3003, "Property 'cwd' is empty.");
                    return;
                }
                workingDirectory = ConvertClientPathToDebugger(workingDirectory);
                if (!Directory.Exists(workingDirectory))
                {
                    SendErrorResponse(response, 3004, "Working directory '{path}' does not exist.", new { path = workingDirectory });
                    return;
                }
            }

            // Todo: handle case insensitive file systems and forward slashes
            _script = Path.GetFullPath(programPath).Replace('/', '\\');
            _code   = File.ReadAllText(programPath);

            if ((_ast = Parse(response, _script)) == null)
            {
                return;
            }

            const string host  = "127.0.0.1";
            var          port  = Utilities.FindFreePort(55555);
            bool         debug = !DynamicHelper.GetBool(arguments, "noDebug", false);

            if (debug)
            {
                Connect(IPAddress.Parse(host), port);
            }

            var termArgs = new
            {
                kind  = "external",
                title = "Aphid Debug Console",
                cwd   = workingDirectory,
                args  = programPath,
                //env = environmentVariables
            };

            var resp = await SendRequest("runInTerminal", termArgs);

            SendResponse(response);
        }