(node: DataField, document: LangiumDocument<AstNode>, extraScopes: ScopeProvider[])
| 463 | } |
| 464 | |
| 465 | private resolveDataField(node: DataField, document: LangiumDocument<AstNode>, extraScopes: ScopeProvider[]) { |
| 466 | // Field declaration may contain enum references, and enum fields are pushed to the global |
| 467 | // scope, so if there're enums with fields with the same name, an arbitrary one will be |
| 468 | // used as resolution target. The correct behavior is to resolve to the enum that's used |
| 469 | // as the declaration type of the field: |
| 470 | // |
| 471 | // enum FirstEnum { |
| 472 | // E1 |
| 473 | // E2 |
| 474 | // } |
| 475 | |
| 476 | // enum SecondEnum { |
| 477 | // E1 |
| 478 | // E3 |
| 479 | // E4 |
| 480 | // } |
| 481 | |
| 482 | // model M { |
| 483 | // id Int @id |
| 484 | // first SecondEnum @default(E1) <- should resolve to SecondEnum |
| 485 | // second FirstEnum @default(E1) <- should resolve to FirstEnum |
| 486 | // } |
| 487 | // |
| 488 | |
| 489 | // make sure type is resolved first |
| 490 | this.resolve(node.type, document, extraScopes); |
| 491 | |
| 492 | let scopes = extraScopes; |
| 493 | |
| 494 | // if the field has enum declaration type, resolve the rest with that enum's fields on top of the scopes |
| 495 | if (node.type.reference?.ref && isEnum(node.type.reference.ref)) { |
| 496 | const contextEnum = node.type.reference.ref as Enum; |
| 497 | const enumScope: ScopeProvider = (name) => contextEnum.fields.find((f) => f.name === name); |
| 498 | scopes = [enumScope, ...scopes]; |
| 499 | } |
| 500 | |
| 501 | this.resolveDefault(node, document, scopes); |
| 502 | } |
| 503 | |
| 504 | private resolveDefault(node: AstNode, document: LangiumDocument<AstNode>, extraScopes: ScopeProvider[]) { |
| 505 | AstUtils.streamReferences(node).forEach((ref) => { |
no test coverage detected