Skip to content
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

Ensure scope includes all elements with the same name #104

Merged
merged 1 commit into from
Feb 28, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ import {
DefaultScopeProvider,
EMPTY_SCOPE,
LangiumDocument,
MapScope,
ReferenceInfo,
Scope,
stream,
Stream,
StreamScope,
URI
} from 'langium';
Expand Down Expand Up @@ -66,7 +69,7 @@ export class PackageScopeProvider extends DefaultScopeProvider {
}

// the global scope contains all elements known to the language server
const globalScope = super.getGlobalScope(referenceType, context);
const globalScope = this.getDefaultGlobalScope(referenceType, context);

// see from which package this request is coming from based on the given context
const source = AstUtils.getDocument(context.container);
Expand All @@ -92,6 +95,24 @@ export class PackageScopeProvider extends DefaultScopeProvider {

return packageScope;
}

protected getDefaultGlobalScope(referenceType: string, _context: ReferenceInfo): Scope {
return this.globalScopeCache.get(referenceType, () => new GlobalScope(this.indexManager.allElements(referenceType).toArray()));
}
}

export class GlobalScope extends MapScope {
readonly allElements: Stream<AstNodeDescription>;

constructor(elements: AstNodeDescription[]) {
super(elements);
this.allElements = stream(elements);
}

override getAllElements(): Stream<AstNodeDescription> {
// ensure we return all elements even if they share the same name in different packages
return this.allElements;
}
}

export class CrossModelScopeProvider extends PackageScopeProvider {
Expand Down
Loading