From f75801c15cd72329faf942616539e90308d18d06 Mon Sep 17 00:00:00 2001 From: Jette Petzold Date: Fri, 29 Sep 2023 14:03:40 +0200 Subject: [PATCH] fixed scoping --- .../src-language-server/fta/fta-module.ts | 10 +++- .../fta/fta-scopeProvider.ts | 55 +++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 extension/src-language-server/fta/fta-scopeProvider.ts diff --git a/extension/src-language-server/fta/fta-module.ts b/extension/src-language-server/fta/fta-module.ts index f38f16ad..76d0b4f7 100644 --- a/extension/src-language-server/fta/fta-module.ts +++ b/extension/src-language-server/fta/fta-module.ts @@ -27,13 +27,17 @@ import { } from "sprotty-elk/lib/elk-layout"; import { FtaDiagramGenerator } from "./diagram/fta-diagram-generator"; import { FtaLayoutConfigurator } from "./diagram/fta-layout-config"; -import { FtaValidationRegistry, FtaValidator } from "./fta-validator"; +import { FtaScopeProvider } from "./fta-scopeProvider"; import { FtaSynthesisOptions } from "./fta-synthesis-options"; +import { FtaValidationRegistry, FtaValidator } from "./fta-validator"; /** * Declaration of custom services. */ export type FtaAddedServices = { + references: { + FtaScopeProvider: FtaScopeProvider; + }; validation: { FtaValidator: FtaValidator; }; @@ -68,6 +72,10 @@ export const FtaModule: Module new FtaScopeProvider(services), + FtaScopeProvider: (services) => new FtaScopeProvider(services), + }, validation: { ValidationRegistry: (services) => new FtaValidationRegistry(services), FtaValidator: () => new FtaValidator(), diff --git a/extension/src-language-server/fta/fta-scopeProvider.ts b/extension/src-language-server/fta/fta-scopeProvider.ts new file mode 100644 index 00000000..ebc8945e --- /dev/null +++ b/extension/src-language-server/fta/fta-scopeProvider.ts @@ -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> = []; + 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; + } +}