Exemplo n.º 1
0
        protected override void HandleLaunchRequestAsync(IRequestResponder <LaunchArguments> responder)
        {
            if (session != null)
            {
                var ex = new InvalidOperationException();
                Log(ex.Message, LogCategory.DebugAdapterOutput);
                responder.SetError(new ProtocolException(ex.Message, ex));
                return;
            }

            _ = LaunchConfigParser.CreateDebugSessionAsync(responder.Arguments, Protocol.SendEvent, defaultDebugView)
                .ContinueWith(t =>
            {
                if (t.IsCompletedSuccessfully)
                {
                    session = t.Result;
                    session.Start();
                    Protocol.SendEvent(new InitializedEvent());
                    responder.SetResponse(new LaunchResponse());
                }
                else
                {
                    if (t.Exception != null)
                    {
                        responder.SetError(new ProtocolException(t.Exception.Message, t.Exception));
                    }
                    else
                    {
                        responder.SetError(new ProtocolException($"Unknown error in {nameof(LaunchConfigParser.CreateDebugSessionAsync)}"));
                    }
                }
            }, TaskScheduler.Current);
        }
Exemplo n.º 2
0
        void HandleInlineVariable(IRequestResponder <InlineVariableArguments> handler)
        {
            List <InlineVaiable> res = new List <InlineVaiable>();
            var DocumentName         = handler.Arguments.DocumentName;

            try
            {
                if (File.Exists(DocumentName))
                {
                    using (var stream = File.OpenRead(DocumentName))
                    {
                        SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(SourceText.From(stream), path: DocumentName);
                        TextLine   textLine   = syntaxTree.GetText().Lines[handler.Arguments.Line];
                        Location   location   = syntaxTree.GetLocation(textLine.Span);
                        SyntaxTree sourceTree = location.SourceTree;
                        SyntaxNode node       = location.SourceTree.GetRoot().FindNode(location.SourceSpan, true, true);

                        bool isLambda = GetParentMethod <LambdaExpressionSyntax>(node.Parent) != null;
                        BaseMethodDeclarationSyntax method = GetParentMethod <MethodDeclarationSyntax>(node.Parent);
                        if (method == null)
                        {
                            method = GetParentMethod <ConstructorDeclarationSyntax>(node.Parent);
                        }

                        foreach (var i in method.ParameterList.Parameters)
                        {
                            var span = syntaxTree.GetLineSpan(i.Identifier.Span);
                            if (span.StartLinePosition.Line > handler.Arguments.Line)
                            {
                                continue;
                            }
                            res.Add(InlineVaiable.FromIdentifier(i.Identifier));
                        }

                        foreach (var i in method.Body.Statements)
                        {
                            if (i is LocalDeclarationStatementSyntax local)
                            {
                                foreach (var j in local.Declaration.Variables)
                                {
                                    var span = syntaxTree.GetLineSpan(j.Identifier.Span);
                                    if (span.StartLinePosition.Line > handler.Arguments.Line)
                                    {
                                        continue;
                                    }
                                    res.Add(InlineVaiable.FromIdentifier(j.Identifier));
                                }
                            }
                            if (i is ForStatementSyntax fore)
                            {
                                foreach (var j in fore.Declaration.Variables)
                                {
                                    var span = syntaxTree.GetLineSpan(j.Identifier.Span);
                                    if (span.StartLinePosition.Line > handler.Arguments.Line)
                                    {
                                        continue;
                                    }

                                    res.Add(InlineVaiable.FromIdentifier(j.Identifier));
                                }
                            }
                            if (i is ForEachStatementSyntax fore2)
                            {
                            }
                        }
                    }
                }
                handler.SetResponse(new InlineVariableResponse()
                {
                    Variables = res
                });
            }
            catch (Exception ex)
            {
                handler.SetError(new ProtocolException(ex.ToString()));
            }
        }