@@ -14,8 +14,10 @@ import { getDataModelAndTypeDefs, getDocument, hasAttribute, resolveImport, reso
1414export async function loadDocument (
1515 fileName : string ,
1616 additionalModelFiles : string [ ] = [ ] ,
17+ keepImports : boolean = false ,
1718) : Promise <
18- { success : true ; model : Model ; warnings : string [ ] , services : ZModelServices } | { success : false ; errors : string [ ] ; warnings : string [ ] }
19+ | { success : true ; model : Model ; warnings : string [ ] ; services : ZModelServices }
20+ | { success : false ; errors : string [ ] ; warnings : string [ ] }
1921> {
2022 const { ZModelLanguage : services } = createZModelServices ( false ) ;
2123 const extensions = services . LanguageMetaData . fileExtensions ;
@@ -103,14 +105,16 @@ export async function loadDocument(
103105
104106 const model = document . parseResult . value as Model ;
105107
106- // merge all declarations into the main document
107- const imported = mergeImportsDeclarations ( langiumDocuments , model ) ;
108+ if ( keepImports === false ) {
109+ // merge all declarations into the main document
110+ const imported = mergeImportsDeclarations ( langiumDocuments , model ) ;
108111
109- // remove imported documents
110- imported . forEach ( ( model ) => {
111- langiumDocuments . deleteDocument ( model . $document ! . uri ) ;
112- services . shared . workspace . IndexManager . remove ( model . $document ! . uri ) ;
113- } ) ;
112+ // remove imported documents
113+ imported . forEach ( ( model ) => {
114+ langiumDocuments . deleteDocument ( model . $document ! . uri ) ;
115+ services . shared . workspace . IndexManager . remove ( model . $document ! . uri ) ;
116+ } ) ;
117+ }
114118
115119 // extra validation after merging imported declarations
116120 const additionalErrors = validationAfterImportMerge ( model ) ;
0 commit comments