-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* KIELER - Kiel Integrated Environment for Layout Eclipse RichClient | ||
* | ||
* http://rtsys.informatik.uni-kiel.de/kieler | ||
* | ||
* Copyright 2023 by | ||
* + Kiel University | ||
* + Department of Computer Science | ||
* + Real-Time and Embedded Systems Group | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
|
||
import { | ||
AstNode, | ||
AstNodeDescription, | ||
DefaultScopeProvider, | ||
ReferenceInfo, | ||
Scope, | ||
Stream, | ||
getDocument, | ||
stream, | ||
} from "langium"; | ||
|
||
export class FtaScopeProvider extends DefaultScopeProvider { | ||
/* override super method to exclude definitions in other files */ | ||
getScope(context: ReferenceInfo): Scope { | ||
const scopes: Array<Stream<AstNodeDescription>> = []; | ||
const referenceType = this.reflection.getReferenceType(context); | ||
|
||
const precomputed = getDocument(context.container).precomputedScopes; | ||
if (precomputed) { | ||
let currentNode: AstNode | undefined = context.container; | ||
do { | ||
const allDescriptions = precomputed.get(currentNode); | ||
if (allDescriptions.length > 0) { | ||
scopes.push( | ||
stream(allDescriptions).filter((desc) => this.reflection.isSubtype(desc.type, referenceType)) | ||
); | ||
} | ||
currentNode = currentNode.$container; | ||
} while (currentNode); | ||
} | ||
|
||
let result: Scope = this.createScope(scopes[scopes.length - 1]); | ||
for (let i = scopes.length - 2; i >= 0; i--) { | ||
result = this.createScope(scopes[i], result); | ||
} | ||
return result; | ||
} | ||
} |