public static async Task<IEnumerable<FileMemberElement>> Compute(IEnumerable<Document> documents)
 {
     var root = new FileMemberElement() { ChildNodes = new List<FileMemberElement>() };
     var visitor = new StructureComputer(root);
     foreach (var document in documents)
     {
         visitor.CurrentProject = document.Project.Name;
         ((CSharpSyntaxNode)await document.GetSyntaxRootAsync()).Accept(visitor);
     }
     return root.ChildNodes;
 }
        public async Task <IEnumerable <QuickFix> > MembersAsFlat(Request request)
        {
            var stack = new List <FileMemberElement>(await StructureComputer.Compute(_workspace.GetDocuments(request.FileName)));
            var ret   = new List <QuickFix>();

            while (stack.Count > 0)
            {
                var node = stack[0];
                stack.Remove(node);
                ret.Add(node.Location);
                stack.AddRange(node.ChildNodes);
            }
            return(ret);
        }
Example #3
0
        public static async Task <IEnumerable <FileMemberElement> > Compute(IEnumerable <Document> documents)
        {
            var root = new FileMemberElement()
            {
                ChildNodes = new List <FileMemberElement>()
            };
            var visitor = new StructureComputer(root);

            foreach (var document in documents)
            {
                visitor.CurrentProject = document.Project.Name;
                ((CSharpSyntaxNode)await document.GetSyntaxRootAsync()).Accept(visitor);
            }
            return(root.ChildNodes);
        }
        public static async Task <IEnumerable <FileMemberElement> > Compute(
            IEnumerable <Document> documents,
            IEnumerable <ISyntaxFeaturesDiscover> featureDiscovers)
        {
            var root = new FileMemberElement()
            {
                ChildNodes = new List <FileMemberElement>()
            };
            var visitor = new StructureComputer(root, featureDiscovers);

            foreach (var document in documents)
            {
                await visitor.Process(document);
            }

            return(root.ChildNodes);
        }
Example #5
0
        private async Task <NavigateResponse> Navigate(Request request, Func <FileMemberElement, FileMemberElement, Request, bool> IsCloserNode)
        {
            var stack    = new List <FileMemberElement>(await StructureComputer.Compute(_workspace.GetDocuments(request.FileName)));
            var response = new NavigateResponse();

            //Retain current line in case we dont need to navigate.
            response.Line   = request.Line;
            response.Column = request.Column;

            FileMemberElement closestNode = null;
            FileMemberElement thisNode    = null;

            while (stack.Count > 0)
            {
                var node = stack[0];
                stack.Remove(node);
                var isCloserNode = IsCloserNode(node, closestNode, request);
                if (isCloserNode)
                {
                    closestNode = node;
                }
                if (node.Location.Line == request.Line)
                {
                    thisNode = node;
                }
                stack.AddRange(node.ChildNodes);
            }

            //If there is a closest node, use its line and column.
            //or if we are on the last node, adjust column.
            //if we are above the first or below the last node, do nothing.
            if (closestNode != null)
            {
                response.Line   = closestNode.Location.Line;
                response.Column = closestNode.Location.Column;
            }
            else if (thisNode != null)
            {
                response.Column = thisNode.Location.Column;
            }
            return(response);
        }
        public async Task <IActionResult> MembersAsFlat([FromBody] Request request)
        {
            var document = _workspace.GetDocument(request.FileName);

            if (document == null)
            {
                return(new HttpNotFoundResult());
            }
            var stack = new List <Node>(StructureComputer.Compute((CSharpSyntaxNode)await document.GetSyntaxRootAsync()));
            var ret   = new List <QuickFix>();

            while (stack.Count > 0)
            {
                var node = stack[0];
                stack.Remove(node);
                ret.Add(node.Location);
                stack.AddRange(node.ChildNodes);
            }
            return(new ObjectResult(ret));
        }