Skip to content

Commit

Permalink
added getStream() to MultiMap in collection.ts, adjusted evaluati…
Browse files Browse the repository at this point in the history
…on of precomputed scopes in `DefaultScopeProvider`
  • Loading branch information
sailingKieler committed Jan 13, 2025
1 parent 3f9de4c commit 8078681
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/langium/src/references/scope-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ export class DefaultScopeProvider implements ScopeProvider {
if (precomputed) {
let currentNode: AstNode | undefined = context.container;
do {
const allDescriptions = precomputed.get(currentNode);
if (allDescriptions.length > 0) {
const allDescriptions = precomputed.getStream(currentNode);
if (!allDescriptions.isEmpty()) {
scopes.push(stream(allDescriptions).filter(
desc => this.reflection.isSubtype(desc.type, referenceType)));
}
Expand Down
8 changes: 8 additions & 0 deletions packages/langium/src/utils/collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ export class MultiMap<K, V> {
return this.map.get(key) ?? [];
}

/**
* Returns a stream of all values associated with the given key. If no value exists,
* an empty stream is returned.
*/
getStream(key: K): Stream<V> {
return stream(this.get(key));
}

/**
* Operates differently depending on whether a `value` is given:
* * With a value, this method returns `true` if the specific key / value pair is present in the multimap.
Expand Down

0 comments on commit 8078681

Please sign in to comment.