-
When programming a CLI I do not have all aspects of my model in memory (only the model aspects from the files I decide to read; this is different from vscode where I have all models of my vscode project in memory). So I need to decide which files to read (and then build my model from them) in order, e.g., to resolve all cross-file references. One solution is to glob all model files. When loading const documents : Array<LangiumDocument> = [];
globSync(path.join(path.dirname(fileName), "**/*.model")).forEach(otherFileName=>{
documents.push(services.shared.workspace.LangiumDocuments.getOrCreateDocument(URI.file(path.resolve(otherFileName))));
});
const mainDocument = services.shared.workspace.LangiumDocuments.getOrCreateDocument(URI.file(path.resolve(fileName)));
documents.push(mainDocument);
await services.shared.workspace.DocumentBuilder.build(documents, { validationChecks: 'all' });
//... now check the validation results and generate whatever you need to generate My question:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hey @goto40,
While you can use Langium like this to build a CLI, it's probably easier to just use the
The |
Beta Was this translation helpful? Give feedback.
Hey @goto40,
While you can use Langium like this to build a CLI, it's probably easier to just use the
services.shared.workspace.WorkspaceManager.initialize()
function to initialize a whole folder and all documents within it. This is effectively what we call from the language server to initialize the whole vscode workspace (with all folders). If you need more fine grained control, you might want to go for the approach that you're already using though.The
NodeFileSystem
allows anyone…