-
I have integrated an external model into Langium as described here, and so far I've succeeded in extracting all references I need for the user-facing language. Whenever my language server receives an update in the external model, I reconstruct the references like this: let ws = services.sharedServices.workspace;
const referenceAST = extractReferencesToAST(externalModel)
let referencesDocument =
ws.LangiumDocumentFactory.fromModel(referenceAST, pathToRefs);
await ws.DocumentBuilder.build(
[referencesDocument],
{validationChecks: 'all'}
);
if (ws.LangiumDocuments.hasDocument(pathToRefs)) {
ws.LangiumDocuments.deleteDocument(pathToRefs);
}
ws.LangiumDocuments.addDocument(referencesDocument); However, with this code, I miss the last update, as the newly calculated references don't show up until I receive the next update. So what am I doing wrong? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Hey @bjthehun, I assume the way you update the document is incorrect. The document builder probably takes the old document instead of the updated one, which would explain why it's always lagging one update cycle behind. The following should work better: let ws = services.sharedServices.workspace;
const referenceAST = extractReferencesToAST(externalModel)
let referencesDocument =
ws.LangiumDocumentFactory.fromModel(referenceAST, pathToRefs);
if (ws.LangiumDocuments.hasDocument(pathToRefs)) {
ws.LangiumDocuments.deleteDocument(pathToRefs);
}
ws.LangiumDocuments.addDocument(referencesDocument);
await ws.DocumentBuilder.update(
[referencesDocument.uri],
[]
); |
Beta Was this translation helpful? Give feedback.
I've figured out that
build
andupdate
work in combination for me:So once I tell
DocumentBuilder
i want to remove the existing external model, the "update" succeeds.Thanks for the tip with
build
.