@@ -35,13 +35,7 @@ import {
35
35
isReferenceExpr ,
36
36
isStringLiteral ,
37
37
} from '@zenstackhq/language/ast' ;
38
- import {
39
- getAuthModel ,
40
- getContainingModel ,
41
- getModelFieldsWithBases ,
42
- isAuthInvocation ,
43
- isFutureExpr ,
44
- } from '@zenstackhq/sdk' ;
38
+ import { getAuthModel , getModelFieldsWithBases , isAuthInvocation , isFutureExpr } from '@zenstackhq/sdk' ;
45
39
import {
46
40
AstNode ,
47
41
AstNodeDescription ,
@@ -52,13 +46,14 @@ import {
52
46
LangiumServices ,
53
47
LinkingError ,
54
48
Reference ,
49
+ getContainerOfType ,
55
50
interruptAndCheck ,
56
51
isReference ,
57
52
streamContents ,
58
53
} from 'langium' ;
59
54
import { match } from 'ts-pattern' ;
60
55
import { CancellationToken } from 'vscode-jsonrpc' ;
61
- import { getAllDataModelsIncludingImports , getContainingDataModel } from '../utils/ast-utils' ;
56
+ import { getAllLoadedAndReachableDataModels , getContainingDataModel } from '../utils/ast-utils' ;
62
57
import { mapBuiltinTypeToExpressionType } from './validator/utils' ;
63
58
64
59
interface DefaultReference extends Reference {
@@ -283,15 +278,17 @@ export class ZModelLinker extends DefaultLinker {
283
278
// eslint-disable-next-line @typescript-eslint/ban-types
284
279
const funcDecl = node . function . ref as FunctionDecl ;
285
280
if ( isAuthInvocation ( node ) ) {
286
- // auth() function is resolved to User model in the current document
287
- const model = getContainingModel ( node ) ;
288
-
289
- if ( model ) {
290
- const allDataModels = getAllDataModelsIncludingImports ( this . langiumDocuments ( ) , model ) ;
291
- const authModel = getAuthModel ( allDataModels ) ;
292
- if ( authModel ) {
293
- node . $resolvedType = { decl : authModel , nullable : true } ;
294
- }
281
+ // auth() function is resolved against all loaded and reachable documents
282
+
283
+ // get all data models from loaded and reachable documents
284
+ const allDataModels = getAllLoadedAndReachableDataModels (
285
+ this . langiumDocuments ( ) ,
286
+ getContainerOfType ( node , isDataModel )
287
+ ) ;
288
+
289
+ const authModel = getAuthModel ( allDataModels ) ;
290
+ if ( authModel ) {
291
+ node . $resolvedType = { decl : authModel , nullable : true } ;
295
292
}
296
293
} else if ( isFutureExpr ( node ) ) {
297
294
// future() function is resolved to current model
0 commit comments