@@ -7,15 +7,15 @@ import { AstNode, getDocument, LangiumDocument, LangiumDocuments, Mutable } from
7
7
import { NodeFileSystem } from 'langium/node' ;
8
8
import path from 'path' ;
9
9
import semver from 'semver' ;
10
+ import { TextDocument } from 'vscode-languageserver-textdocument' ;
10
11
import { URI } from 'vscode-uri' ;
11
12
import { PLUGIN_MODULE_NAME , STD_LIB_MODULE_NAME } from '../language-server/constants' ;
13
+ import { ZModelFormatter } from '../language-server/zmodel-formatter' ;
12
14
import { createZModelServices , ZModelServices } from '../language-server/zmodel-module' ;
13
15
import { mergeBaseModel , resolveImport , resolveTransitiveImports } from '../utils/ast-utils' ;
16
+ import { findPackageJson } from '../utils/pkg-utils' ;
14
17
import { getVersion } from '../utils/version-utils' ;
15
18
import { CliError } from './cli-error' ;
16
- import { ZModelFormatter } from '../language-server/zmodel-formatter' ;
17
- import { TextDocument } from 'vscode-languageserver-textdocument' ;
18
- import { getPackageJson } from '../utils/pkg-utils' ;
19
19
20
20
// required minimal version of Prisma
21
21
export const requiredPrismaVersion = '4.8.0' ;
@@ -279,13 +279,19 @@ export async function formatDocument(fileName: string) {
279
279
}
280
280
281
281
export function getDefaultSchemaLocation ( ) {
282
- let location = path . resolve ( 'schema.zmodel' ) ;
283
-
284
282
// handle override from package.json
285
- const pkgJson = getPackageJson ( ) ;
286
- if ( typeof pkgJson ?. zenstack ?. schema === 'string' ) {
287
- location = path . resolve ( pkgJson . zenstack . schema ) ;
283
+ const pkgJsonPath = findPackageJson ( ) ;
284
+ if ( pkgJsonPath ) {
285
+ const pkgJson = JSON . parse ( fs . readFileSync ( pkgJsonPath , 'utf-8' ) ) ;
286
+ if ( typeof pkgJson ?. zenstack ?. schema === 'string' ) {
287
+ if ( path . isAbsolute ( pkgJson . zenstack . schema ) ) {
288
+ return pkgJson . zenstack . schema ;
289
+ } else {
290
+ // resolve relative to package.json
291
+ return path . resolve ( path . dirname ( pkgJsonPath ) , pkgJson . zenstack . schema ) ;
292
+ }
293
+ }
288
294
}
289
295
290
- return location ;
296
+ return path . resolve ( 'schema.zmodel' ) ;
291
297
}
0 commit comments