8
8
getDocument ,
9
9
ReferenceInfo ,
10
10
Scope ,
11
+ WorkspaceCache ,
11
12
} from 'langium' ;
12
13
import {
13
14
isSdsAbstractCall ,
@@ -36,6 +37,7 @@ import {
36
37
isSdsTypeArgument ,
37
38
isSdsWildcardImport ,
38
39
isSdsYield ,
40
+ SdsAnnotation ,
39
41
SdsArgument ,
40
42
type SdsCallable ,
41
43
SdsDeclaration ,
@@ -82,6 +84,8 @@ export class SafeDsScopeProvider extends DefaultScopeProvider {
82
84
private readonly packageManager : SafeDsPackageManager ;
83
85
private readonly typeComputer : SafeDsTypeComputer ;
84
86
87
+ private readonly coreDeclarationCache : WorkspaceCache < string , AstNodeDescription [ ] > ;
88
+
85
89
constructor ( services : SafeDsServices ) {
86
90
super ( services ) ;
87
91
@@ -90,26 +94,30 @@ export class SafeDsScopeProvider extends DefaultScopeProvider {
90
94
this . nodeMapper = services . helpers . NodeMapper ;
91
95
this . packageManager = services . workspace . PackageManager ;
92
96
this . typeComputer = services . types . TypeComputer ;
97
+
98
+ this . coreDeclarationCache = new WorkspaceCache ( services . shared ) ;
93
99
}
94
100
95
101
override getScope ( context : ReferenceInfo ) : Scope {
96
102
const node = context . container ;
97
103
98
- if ( isSdsArgument ( node ) && context . property === 'parameter' ) {
104
+ if ( isSdsAnnotationCall ( node ) && context . property === 'annotation' ) {
105
+ return this . getScopeForAnnotationCallAnnotation ( context ) ;
106
+ } else if ( isSdsArgument ( node ) && context . property === 'parameter' ) {
99
107
return this . getScopeForArgumentParameter ( node ) ;
100
108
} else if ( isSdsImportedDeclaration ( node ) && context . property === 'declaration' ) {
101
109
return this . getScopeForImportedDeclarationDeclaration ( node ) ;
102
110
} else if ( isSdsNamedType ( node ) && context . property === 'declaration' ) {
103
111
if ( isSdsMemberType ( node . $container ) && node . $containerProperty === 'member' ) {
104
112
return this . getScopeForMemberTypeMember ( node . $container ) ;
105
113
} else {
106
- return super . getScope ( context ) ;
114
+ return this . getScopeForNamedTypeDeclaration ( context ) ;
107
115
}
108
116
} else if ( isSdsReference ( node ) && context . property === 'target' ) {
109
117
if ( isSdsMemberAccess ( node . $container ) && node . $containerProperty === 'member' ) {
110
118
return this . getScopeForMemberAccessMember ( node . $container ) ;
111
119
} else {
112
- return this . getScopeForDirectReferenceTarget ( node , context ) ;
120
+ return this . getScopeForReferenceTarget ( node , context ) ;
113
121
}
114
122
} else if ( isSdsTypeArgument ( node ) && context . property === 'typeParameter' ) {
115
123
return this . getScopeForTypeArgumentTypeParameter ( node ) ;
@@ -120,6 +128,10 @@ export class SafeDsScopeProvider extends DefaultScopeProvider {
120
128
}
121
129
}
122
130
131
+ private getScopeForAnnotationCallAnnotation ( context : ReferenceInfo ) {
132
+ return this . coreDeclarations ( SdsAnnotation , super . getScope ( context ) ) ;
133
+ }
134
+
123
135
private getScopeForArgumentParameter ( node : SdsArgument ) : Scope {
124
136
const containingAbstractCall = getContainerOfType ( node , isSdsAbstractCall ) ;
125
137
const callable = this . nodeMapper . callToCallable ( containingAbstractCall ) ;
@@ -141,7 +153,7 @@ export class SafeDsScopeProvider extends DefaultScopeProvider {
141
153
}
142
154
143
155
const declarationsInPackage = this . packageManager . getDeclarationsInPackage ( containingQualifiedImport . package , {
144
- nodeType : ' SdsDeclaration' ,
156
+ nodeType : SdsDeclaration ,
145
157
hideInternal : containingQualifiedImport . package !== ownPackageName ,
146
158
} ) ;
147
159
return this . createScope ( declarationsInPackage ) ;
@@ -181,6 +193,10 @@ export class SafeDsScopeProvider extends DefaultScopeProvider {
181
193
}
182
194
}
183
195
196
+ private getScopeForNamedTypeDeclaration ( context : ReferenceInfo ) : Scope {
197
+ return this . coreDeclarations ( SdsNamedTypeDeclaration , super . getScope ( context ) ) ;
198
+ }
199
+
184
200
private getScopeForMemberAccessMember ( node : SdsMemberAccess ) : Scope {
185
201
// Static access
186
202
const declaration = this . getUniqueReferencedDeclarationForExpression ( node . receiver ) ;
@@ -249,9 +265,9 @@ export class SafeDsScopeProvider extends DefaultScopeProvider {
249
265
}
250
266
}
251
267
252
- private getScopeForDirectReferenceTarget ( node : SdsReference , context : ReferenceInfo ) : Scope {
268
+ private getScopeForReferenceTarget ( node : SdsReference , context : ReferenceInfo ) : Scope {
253
269
// Declarations in other files
254
- let currentScope = this . getGlobalScope ( ' SdsDeclaration' , context ) ;
270
+ let currentScope = this . getGlobalScope ( SdsDeclaration , context ) ;
255
271
256
272
// Declarations in this file
257
273
currentScope = this . globalDeclarationsInSameFile ( node , currentScope ) ;
@@ -260,7 +276,10 @@ export class SafeDsScopeProvider extends DefaultScopeProvider {
260
276
currentScope = this . containingDeclarations ( node , currentScope ) ;
261
277
262
278
// Declarations in containing blocks
263
- return this . localDeclarations ( node , currentScope ) ;
279
+ currentScope = this . localDeclarations ( node , currentScope ) ;
280
+
281
+ // Core declarations
282
+ return this . coreDeclarations ( SdsDeclaration , currentScope ) ;
264
283
}
265
284
266
285
private containingDeclarations ( node : AstNode , outerScope : Scope ) : Scope {
@@ -465,4 +484,14 @@ export class SafeDsScopeProvider extends DefaultScopeProvider {
465
484
466
485
return result ;
467
486
}
487
+
488
+ private coreDeclarations ( referenceType : string , outerScope : Scope ) : Scope {
489
+ const descriptions = this . coreDeclarationCache . get ( referenceType , ( ) =>
490
+ this . packageManager . getDeclarationsInPackage ( 'safeds.lang' , {
491
+ nodeType : referenceType ,
492
+ hideInternal : true ,
493
+ } ) ,
494
+ ) ;
495
+ return this . createScope ( descriptions , outerScope ) ;
496
+ }
468
497
}
0 commit comments