How to calculate Tree positions?

Can you tell me please how to calculate this property correctly? Lezer Reference Manual this

Right now my highlighting is not working accurately, it does not fall in the right range.
I tried to use the start position for all children, use offset relative to 0, and also paid attention to this property Lezer Reference Manual (but I don’t think it’s about that…).

How should the positions for the bold node of the following tree look like?

root [0-7]
  bold [0-7]
    operator [0-1] ("*")
    text [1-6] ("hello")
    operator [6-7] ("*")

When i use start positions [0, 1, 6] (I subtracted from the initial position of each child node the initial position of the parent node) for bold node it doesn’t work

My full CM Tree
{
  "length": 7,
  "positions": [
    0
  ],
  "type": {
    "flags": 1,
    "id": 1,
    "name": "root",
    "tags": [
      {
        "id": 990
      }
    ]
  },
  "children": [
    {
      "length": 7,
      "positions": [
        0,
        1,
        6
      ],
      "type": {
        "flags": 0,
        "id": 18,
        "name": "bold",
        "tags": [
          {
            "id": 1007
          }
        ]
      },
      "children": [
        {
          "length": 1,
          "positions": [],
          "type": {
            "flags": 0,
            "id": 5,
            "name": "operator",
            "tags": [
              {
                "id": 994
              }
            ]
          },
          "children": []
        },
        {
          "length": 5,
          "positions": [],
          "type": {
            "flags": 0,
            "id": 3,
            "name": "text",
            "tags": [
              {
                "id": 992
              }
            ]
          },
          "children": []
        },
        {
          "length": 1,
          "positions": [],
          "type": {
            "flags": 0,
            "id": 5,
            "name": "operator",
            "tags": [
              {
                "id": 994
              }
            ]
          },
          "children": []
        }
      ]
    }
  ]
}

position is relative to the start of the node (though in your example all nodes with children start at 0 so it’s not possible to see whether you are using that or the start of the document). That tree looks correct. How does the highlighting for go wrong, precisely?

Specifically in this example, there is no backlighting at all

But if I set positions [0, 7] for the bold node, I see the following behavior (I just tried to check if the highlighting works at all)

I made small example for reproduction: https://github.com/Artawower/bug-reproduction/blob/master/src/parser.ts

I output to the console the trees, they look plausible, maybe I’ve set up the highlighting incorrectly somehow

I think I found the culprit, it happens when using nested style tags.

But. how do I create a tag for the tricky situation where one tag is inside another? For example, for a tree:

root [0-15]
  bold [0-15]
    operator [0-1] ("*")
    text [1-7] ("Hello ")
    italic [7-14]
      operator [7-8] ("/")
      text [8-13] ("world")
      operator [13-14] ("/")
    operator [14-15] ("*")

I have next behaviour:

But I’d like to make nested italic text bold text

I apologize for the noise. I fixed it using rules for styles, I initially thought that if tags are nested then styles will be applied automatically for all nested tags

Thanks for your help and for your project :heart_hands:

By default, the style of a piece of text is determined by the innermost node that has a style tag assigned. You can use the /... notation in styleTags to make styling also apply to child nodes.