eclipse-langium / langium

Next-gen language engineering / DSL framework
https://langium.org/
MIT License
754 stars 68 forks source link

Range of CST nodes after repeated tree rewriting #1218

Closed lars-reimann closed 5 months ago

lars-reimann commented 1 year ago

Langium version: 2.0.2 Package name: langium

Steps To Reproduce

  1. Clone the repo linked below. It contains a slightly altered hello-world project that allows writing chained member accesses like A.B or A.B.C. For the member access directly below the root, a warning is issued.
  2. Generate, build, and run the extension.
  3. Create a new file with the .hello extension.
  4. Type A.B into the file.
  5. Type A.B.C into the file.

Link to code example: https://github.com/lars-reimann/langium-cst-range

The current behavior

In step 4, the entire expression gets highlighted correctly:

image

In step 5, however, only the part starting at the dot gets highlighted. The computed range of the CST node is also too short:

image

The playground (or a debugging session) shows that the AST is built properly:

{
  $type: "Module", 
  expression: 
  {
    $type: "MemberAccess", 
    receiver: 
    {
      $type: "MemberAccess", 
      receiver: 
      {
        $type: "Reference", 
        name: "A"
      }, 
      member: 
      {
        $type: "Reference", 
        name: "B"
      }
    }, 
    member: 
    {
      $type: "Reference", 
      name: "C"
    }
  }
}

The expected behavior

The warning should be shown for the entire expression A.B.C in step 5. Likewise, the range of the CST node should be 0:0--0:5.

msujew commented 1 year ago

Might be related to the issue that https://github.com/eclipse-langium/langium/pull/932 attempts to fix. I'll probably take a look at that soon.