from skillls.helpers import build_node_hierarchy from skillls.types import Node, NodeKind from lsprotocol.types import Range, Position import pytest @pytest.fixture def sample_range(): return Range(Position(0, 0), Position(5, 10)) def test_build_node_hierarchy(): # Create a root node root_range = Range(Position(0, 0), Position(5, 10)) root = Node(node="root", kind=NodeKind.PROC, location=root_range) # Create a child node that should be contained within the root's range child_range = Range(Position(1, 1), Position(2, 2)) child = Node(node="child", kind=NodeKind.LET, location=child_range) # Create another child node that is NOT in the root's range (outside) grandchild_range = Range(Position(6, 0), Position(7, 0)) grandchild = Node(node="grandelse", kind=NodeKind.PROC, location=grandchild_range) # Build hierarchy hierarchy = build_node_hierarchy([root, child, grandchild]) # Root should be in the hierarchy assert root in hierarchy # Child should be a child of root because its range is within root's range (in our mock) assert child in root.children # Grandchild is outside root range so it should be in the top level list assert grandchild in hierarchy