public async Task <IEnumerable <QuickFix> > Handle(MembersFlatRequest 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);
        }
Beispiel #2
0
        public async Task SimpleInterface()
        {
            var source =
                @"public interface Far {

                }";

            var workspace = await TestHelpers.CreateSimpleWorkspace(source, "d.cs");

            var nodes = await StructureComputer.Compute(workspace.GetDocuments("d.cs"));

            Assert.Equal(1, nodes.Count());
            Assert.Equal("Far", nodes.First().Location.Text);
            Assert.Equal(SyntaxKind.InterfaceDeclaration.ToString(), nodes.First().Kind);
        }
Beispiel #3
0
        public async void SimpleClass()
        {
            var source =
                @"public class Far {
					
				}"                ;

            var workspace = TestHelpers.CreateSimpleWorkspace(source, "d.cs");
            var root      = await workspace.GetDocument("d.cs").GetSyntaxRootAsync();

            var nodes = StructureComputer.Compute((CSharpSyntaxNode)root);

            Assert.Equal(1, nodes.Count());
            Assert.Equal("Far", nodes.First().Location.Text);
            Assert.Equal(SyntaxKind.ClassDeclaration.ToString(), nodes.First().Kind);
        }
Beispiel #4
0
        public static async Task <NavigateResponse> Navigate(OmniSharpWorkspace workspace, 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);
        }