Skip to content

Commit

Permalink
fix: cannot reference the target of an annotation call from inside th…
Browse files Browse the repository at this point in the history
…e annotation call
  • Loading branch information
lars-reimann committed Oct 30, 2023
1 parent ead1b78 commit c122ccc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from 'langium';
import {
isSdsAbstractCall,
isSdsAnnotationCall,
isSdsArgument,
isSdsAssignment,
isSdsBlock,
Expand Down Expand Up @@ -54,6 +55,7 @@ import {
import { isContainedIn } from '../helpers/astUtils.js';
import {
getAbstractResults,
getAnnotationCallTarget,
getAssignees,
getEnumVariants,
getImportedDeclarations,
Expand Down Expand Up @@ -261,8 +263,17 @@ export class SafeDsScopeProvider extends DefaultScopeProvider {
private containingDeclarations(node: AstNode, outerScope: Scope): Scope {
const result = [];

// Cannot reference the target of an annotation call from inside the annotation call
let start: AstNode | undefined;
const containingAnnotationCall = getContainerOfType(node, isSdsAnnotationCall);
if (containingAnnotationCall) {
start = getAnnotationCallTarget(containingAnnotationCall)?.$container;
} else {
start = node.$container;
}

// Only containing classes, enums, and enum variants can be referenced
let current = getContainerOfType(node.$container, isSdsNamedTypeDeclaration);
let current = getContainerOfType(start, isSdsNamedTypeDeclaration);
while (current) {
result.push(current);
current = getContainerOfType(current.$container, isSdsNamedTypeDeclaration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class »MyClass«(
p = »MyClass«()
)
@MyAnnotation(
// $TEST$ references enum
// $TEST$ unresolved
p = »MyEnum«
)
// $TEST$ target enum
Expand Down Expand Up @@ -73,7 +73,7 @@ class »MyClass«(
}

@MyAnnotation(
// $TEST$ references innerClass
// $TEST$ references outerClass
p = »MyClass«()
)
@MyAnnotation(
Expand Down

0 comments on commit c122ccc

Please sign in to comment.