xixiaofinland / afmt

Salesforce Apex code formatter written in Rust
20 stars 3 forks source link

Top-level, one-line multi-variable declaration loses variables after the first #7

Closed aheber closed 3 days ago

aheber commented 6 days ago

Only on class-level objects. If you use the syntax to define multiple variables of the same type, only the first is being printed.

Example:

class Me {
  Integer testVal = 1, anotherVal = 0;
}

Formatted Output:

class Me {
  Integer testVal = 1;
}

Parse tree:

field_declaration [1, 2] - [1, 38]
  type: type_identifier [1, 2] - [1, 9]
  declarator: variable_declarator [1, 10] - [1, 21]
    name: identifier [1, 10] - [1, 17]
    assignment_operator [1, 18] - [1, 19]
    value: int [1, 20] - [1, 21]
  declarator: variable_declarator [1, 23] - [1, 37]
    name: identifier [1, 23] - [1, 33]
    assignment_operator [1, 34] - [1, 35]
    value: int [1, 36] - [1, 37]

For contrast, this formats correctly and doesn't lose anything:

class Me {
  void method1() {
    Integer testVal = 1, anotherVal = 0;
  }
}
xixiaofinland commented 5 days ago

good catch! One node is named "field_declaration", the other is "local_variable_declaration". Despite almost the same, they are implemented in different methods.

This is fixed in v0.0.13, and the new test file guards it.