Async Scope Computation
Closed this issue · 1 comments
At Jayvee, we were evaluating whether we could implement dynamic document loading on imports (jvalue/jayvee#593).
However, we ran into a roadblock as the ScopeProvider has a synchronous interface for the getScope
method where we ultimately would need to await a promise the loads a document via services.shared.workspace.LangiumDocuments.getOrCreateDocument(documentUri)
.
If there is a better way to do it in a different place, I'd appreciate your expertise :)
Otherwise, would it be possible to make the interface of the ScopeProvider
asynchronous by returning promises?
/**
* Language-specific service for determining the scope of target elements visible in a specific cross-reference context.
*/
export interface ScopeProvider {
/**
* Return a scope describing what elements are visible for the given AST node and cross-reference
* identifier.
*
* @param context Information about the reference for which a scope is requested.
*/
getScope(context: ReferenceInfo): Promise<Scope>;
}
This would also affect some methods of the Linker
and its clients.
Let me know if I can contribute anything to that change!
Hey @georg-schwarz,
The decision to make the getScope
method sync was very deliberate, as otherwise every reference resolution, i.e. every call to ref
becomes async.
There are other ways of solving this, see #1308. The main idea is to hook into the document builder and to load referenced documents before performing the linking.