예제 #1
0
        public void AreNeighbors_ShouldProduceCorrectResult(string firstSpan, string secondSpan, bool expectedResult)
        {
            var first  = TextSpan.Parse(firstSpan);
            var second = TextSpan.Parse(secondSpan);

            TextSpan.AreNeighbors(first, second).Should().Be(expectedResult);
        }
예제 #2
0
        /// <summary>
        /// Returnes nodes whose span contains the specified offset from least specific to the most specific.
        /// </summary>
        /// <param name="syntax">The program node</param>
        /// <param name="offset">The offset</param>
        private static List <SyntaxBase> FindNodesMatchingOffset(ProgramSyntax syntax, int offset)
        {
            var nodes = new List <SyntaxBase>();

            syntax.TryFindMostSpecificNodeInclusive(offset, current =>
            {
                // callback is invoked only if node span contains the offset
                // in inclusive mode, 2 nodes can be returned if cursor is between end of one node and beginning of another
                // we will pick the node to the left as the winner
                if (nodes.Any() == false || TextSpan.AreNeighbors(nodes.Last(), current) == false)
                {
                    nodes.Add(current);
                }

                // don't filter out the nodes
                return(true);
            });

            return(nodes);
        }
예제 #3
0
        /// <summary>
        /// Returns nodes whose span contains the specified offset from least specific to the most specific.
        /// </summary>
        /// <param name="syntax">The program node</param>
        /// <param name="offset">The offset</param>
        public static List <SyntaxBase> FindNodesMatchingOffset(ProgramSyntax syntax, int offset)
        {
            var nodes = new List <SyntaxBase>();

            syntax.TryFindMostSpecificNodeInclusive(offset, current =>
            {
                // callback is invoked only if node span contains the offset
                // in inclusive mode, 2 nodes can be returned if cursor is between end of one node and beginning of another
                // we will pick the node to the left as the winner if it's not a newline. Otherwise, pick the right one instead.
                if (!nodes.Any())
                {
                    nodes.Add(current);
                }
                else
                {
                    var lastNode = nodes[^ 1];

                    if (TextSpan.AreNeighbors(lastNode, current) && lastNode is Token {
                        Type: TokenType.NewLine
                    })