Skip to content

Commit

Permalink
fixed scoping
Browse files Browse the repository at this point in the history
  • Loading branch information
Drakae committed Sep 29, 2023
1 parent 1f6947c commit f75801c
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
10 changes: 9 additions & 1 deletion extension/src-language-server/fta/fta-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down Expand Up @@ -68,6 +72,10 @@ export const FtaModule: Module<FtaServices, PartialLangiumServices & SprottyDiag
services.layout.LayoutConfigurator
) as any,
},
references: {
ScopeProvider: (services) => new FtaScopeProvider(services),
FtaScopeProvider: (services) => new FtaScopeProvider(services),
},
validation: {
ValidationRegistry: (services) => new FtaValidationRegistry(services),
FtaValidator: () => new FtaValidator(),
Expand Down
55 changes: 55 additions & 0 deletions extension/src-language-server/fta/fta-scopeProvider.ts
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;
}
}

0 comments on commit f75801c

Please sign in to comment.