1
1
import {
2
2
AstNode ,
3
3
AstNodeDescription ,
4
+ AstReflection ,
4
5
DefaultScopeProvider ,
5
6
EMPTY_SCOPE ,
6
7
getContainerOfType ,
@@ -62,12 +63,14 @@ import { SafeDsTypeComputer } from '../typing/safe-ds-type-computer.js';
62
63
import { SafeDsPackageManager } from '../workspace/safe-ds-package-manager.js' ;
63
64
64
65
export class SafeDsScopeProvider extends DefaultScopeProvider {
66
+ private readonly astReflection : AstReflection ;
65
67
private readonly packageManager : SafeDsPackageManager ;
66
68
private readonly typeComputer : SafeDsTypeComputer ;
67
69
68
70
constructor ( services : SafeDsServices ) {
69
71
super ( services ) ;
70
72
73
+ this . astReflection = services . shared . AstReflection ;
71
74
this . packageManager = services . workspace . PackageManager ;
72
75
this . typeComputer = services . types . TypeComputer ;
73
76
}
@@ -350,6 +353,23 @@ export class SafeDsScopeProvider extends DefaultScopeProvider {
350
353
return this . createScope ( explicitlyImportedDeclarations , outerScope ) ;
351
354
}
352
355
356
+ private builtinDeclarations ( referenceType : string ) : AstNodeDescription [ ] {
357
+ return this . packageManager . getDeclarationsInPackageOrSubpackage ( 'safeds' , {
358
+ nodeType : referenceType ,
359
+ hideInternal : true ,
360
+ } ) ;
361
+ }
362
+
363
+ private declarationsInSamePackage ( packageName : string | null , referenceType : string ) : AstNodeDescription [ ] {
364
+ if ( ! packageName ) {
365
+ return [ ] ;
366
+ }
367
+
368
+ return this . packageManager . getDeclarationsInPackage ( packageName , {
369
+ nodeType : referenceType ,
370
+ } ) ;
371
+ }
372
+
353
373
private explicitlyImportedDeclarations ( referenceType : string , node : AstNode ) : AstNodeDescription [ ] {
354
374
const containingModule = getContainerOfType ( node , isSdsModule ) ;
355
375
const imports = importsOrEmpty ( containingModule ) ;
@@ -359,7 +379,7 @@ export class SafeDsScopeProvider extends DefaultScopeProvider {
359
379
if ( isSdsQualifiedImport ( imp ) ) {
360
380
for ( const importedDeclaration of importedDeclarationsOrEmpty ( imp ) ) {
361
381
const description = importedDeclaration . declaration . $nodeDescription ;
362
- if ( ! description ) {
382
+ if ( ! description || ! this . astReflection . isSubtype ( description . type , referenceType ) ) {
363
383
continue ;
364
384
}
365
385
@@ -380,21 +400,4 @@ export class SafeDsScopeProvider extends DefaultScopeProvider {
380
400
381
401
return result ;
382
402
}
383
-
384
- private declarationsInSamePackage ( packageName : string | null , referenceType : string ) : AstNodeDescription [ ] {
385
- if ( ! packageName ) {
386
- return [ ] ;
387
- }
388
-
389
- return this . packageManager . getDeclarationsInPackage ( packageName , {
390
- nodeType : referenceType ,
391
- } ) ;
392
- }
393
-
394
- private builtinDeclarations ( referenceType : string ) : AstNodeDescription [ ] {
395
- return this . packageManager . getDeclarationsInPackageOrSubpackage ( 'safeds' , {
396
- nodeType : referenceType ,
397
- hideInternal : true ,
398
- } ) ;
399
- }
400
403
}
0 commit comments