-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
introduced dedicated interface PrecomputedScopes, updated implementations of DefaultScopeComputation
and DefaultScopeProvider
#1788
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you overriding MultiMap
in your adopter code? This change feels like the wrong abstraction layer. I would much rather have a dedicated PrecomputedScope
interface (with a default implementation based on MultiMap
), than extend the data type based on a specific adopter need. You can then create your own, stream based PrecomputedScope
implementation.
I introduced an
Indeed, from an outside point-of-view the additional method looks a bit weird, with the constraint in mind that the memory footprint of the precomputed scopes might get too high with a high number of documents this is the origin of the change (instead of the array-based inclusion) langium/packages/langium/src/references/scope-provider.ts Lines 59 to 63 in 8078681
Motivation: Constraint-based visibility of external symbols per document. |
…ations of `DefaultScopeComputation` and `DefaultScopeProvider` * added factory method to `DefaultScopeComputation` * added `getStream()` to new interface in addition to existing `add`, `addAll`, and `get` resembling the methods `MultiMap` in collection.ts
8078681
to
324fa41
Compare
getStream()
to MultiMap
in collection.ts, adjusted evaluation of precomputed scopes in DefaultScopeProvider
DefaultScopeComputation
and DefaultScopeProvider
@msujew I pushed a new version. Does that one meet your idea/proposal? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I think the new API looks much better. I just have one comment, see below.
protected newPrecomputedScopes(_document: LangiumDocument): PrecomputedScopes { | ||
const map = new MultiMap<AstNode, AstNodeDescription>(); | ||
return { | ||
add: map.add.bind(map), | ||
addAll: map.addAll.bind(map), | ||
get: map.get.bind(map), | ||
getStream: (key: AstNode) => stream(map.get(key)) | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: I don't think that the "default implementation" of PrecomputedScopes
should be exclusively available as a method inside of the default implementation of ScopeComputation
. Instead, I would much rather have a MultiMapPrecomputedScopes
class, that can be used by adopters that don't want to override DefaultScopeComputation
.
With this additional method hook, customized implementations of
PrecomputedScopes
contributing lazily computed proposals (for the sake of memory usage optimization) can be employed, and eager in-between evaluations can be avoided by overriding the new method hookgetStream(key)
.