Skip to content

Commit

Permalink
build: bump Langium to release candidate for 3.0 (#924)
Browse files Browse the repository at this point in the history
### Summary of Changes

Bump `langium` to the release candidate for v3.0 to prepare for upcoming
API changes before we add more features.
  • Loading branch information
lars-reimann authored Feb 26, 2024
1 parent c22ab5f commit d6eec5d
Show file tree
Hide file tree
Showing 65 changed files with 318 additions and 677 deletions.
30 changes: 15 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/safe-ds-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"chalk": "^5.3.0",
"commander": "^11.1.0",
"glob": "^10.3.10",
"langium": "^2.1.3",
"langium": "^3.0.0-next.e78aeba",
"true-myth": "^7.1.0"
},
"devDependencies": {
Expand Down
7 changes: 4 additions & 3 deletions packages/safe-ds-cli/src/helpers/documents.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { LangiumDocument, LangiumServices, stream, URI } from 'langium';
import { LangiumDocument, stream, URI } from 'langium';
import fs from 'node:fs';
import path from 'node:path';
import { ExitCode } from '../cli/exitCode.js';
import { globSync } from 'glob';
import { Result } from 'true-myth';
import chalk from 'chalk';
import { type LangiumServices } from 'langium/lsp';

/**
* Extracts a document from a file name.
* Extracts documents at the given paths.
*/
export const extractDocuments = async function (
services: LangiumServices,
Expand All @@ -24,7 +25,7 @@ export const extractDocuments = async function (
process.exit(uris.error.code);
}

const documents = uris.value.map((uri) => langiumDocuments.getOrCreateDocument(uri));
const documents = await Promise.all(uris.value.map((uri) => langiumDocuments.getOrCreateDocument(uri)));
await documentBuilder.build(documents, { validation: true });
return documents;
};
Expand Down
4 changes: 2 additions & 2 deletions packages/safe-ds-lang/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"dependencies": {
"chevrotain": "^11.0.3",
"glob": "^10.3.10",
"langium": "^2.1.3",
"langium": "^3.0.0-next.e78aeba",
"semver": "^7.6.0",
"source-map": "^0.7.4",
"tree-kill": "^1.2.2",
Expand All @@ -56,7 +56,7 @@
"devDependencies": {
"@types/node": "^18.18.12",
"@types/ws": "^8.5.10",
"langium-cli": "^2.1.0",
"langium-cli": "^3.0.0-next.e78aeba",
"true-myth": "^7.1.0"
},
"engines": {
Expand Down
8 changes: 5 additions & 3 deletions packages/safe-ds-lang/src/language/builtins/safe-ds-enums.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getContainerOfType, URI } from 'langium';
import { AstUtils, URI } from 'langium';
import { resourceNameToUri } from '../../helpers/resources.js';
import { isSdsEnum, SdsEnum, type SdsEnumVariant } from '../generated/ast.js';
import { getEnumVariants } from '../helpers/nodeProperties.js';
Expand All @@ -15,14 +15,16 @@ export class SafeDsEnums extends SafeDsModuleMembers<SdsEnum> {
}

isEvaluatedAnnotationTarget = (node: EvaluatedNode): node is EvaluatedEnumVariant =>
node instanceof EvaluatedEnumVariant && getContainerOfType(node.variant, isSdsEnum) === this.AnnotationTarget;
node instanceof EvaluatedEnumVariant &&
AstUtils.getContainerOfType(node.variant, isSdsEnum) === this.AnnotationTarget;

get ImpurityReason(): SdsEnum | undefined {
return this.getEnum(PURITY_URI, 'ImpurityReason');
}

isEvaluatedImpurityReason = (node: EvaluatedNode): node is EvaluatedEnumVariant =>
node instanceof EvaluatedEnumVariant && getContainerOfType(node.variant, isSdsEnum) === this.ImpurityReason;
node instanceof EvaluatedEnumVariant &&
AstUtils.getContainerOfType(node.variant, isSdsEnum) === this.ImpurityReason;

private getEnum(uri: URI, name: string): SdsEnum | undefined {
return this.getModuleMember(uri, name, isSdsEnum);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ export abstract class SafeDsModuleMembers<T extends SdsModuleMember> {
return this.cache.get(key);
}

if (!this.langiumDocuments.hasDocument(uri)) {
const document = this.langiumDocuments.getDocument(uri);
if (!document) {
/* c8 ignore next 2 */
return undefined;
}

const document = this.langiumDocuments.getOrCreateDocument(uri);
const root = document.parseResult.value;
if (!isSdsModule(root)) {
/* c8 ignore next 2 */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
AstNode,
getContainerOfType,
AstUtils,
isJSDoc,
JSDocComment,
JSDocDocumentationProvider,
Expand All @@ -25,7 +25,7 @@ const TYPE_PARAM_TAG = 'typeParam';
export class SafeDsDocumentationProvider extends JSDocDocumentationProvider {
override getDocumentation(node: AstNode): string | undefined {
if (isSdsParameter(node) || isSdsResult(node) || isSdsTypeParameter(node)) {
const containingCallable = getContainerOfType(node, isSdsCallable);
const containingCallable = AstUtils.getContainerOfType(node, isSdsCallable);
/* c8 ignore start */
if (!containingCallable) {
return undefined;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
import {
AstNode,
type AstNodeLocator,
getContainerOfType,
getDocument,
stream,
streamAst,
WorkspaceCache,
} from 'langium';
import { AstNode, type AstNodeLocator, AstUtils, stream, WorkspaceCache } from 'langium';
import {
isSdsBlockLambda,
isSdsCall,
Expand Down Expand Up @@ -197,7 +189,7 @@ export class SafeDsCallGraphComputer {
}

return [...callsInDefaultValues, ...callsInBody]
.filter((it) => getContainerOfType(it, isSdsCallable) === callable)
.filter((it) => AstUtils.getContainerOfType(it, isSdsCallable) === callable)
.map((it) => this.createSyntheticCallForCall(it, substitutions));
}

Expand Down Expand Up @@ -334,11 +326,11 @@ export class SafeDsCallGraphComputer {
}

const key = this.getNodeId(node);
return this.callCache.get(key, () => streamAst(node).filter(isSdsCall).toArray());
return this.callCache.get(key, () => AstUtils.streamAst(node).filter(isSdsCall).toArray());
}

private getNodeId(node: AstNode) {
const documentUri = getDocument(node).uri.toString();
const documentUri = AstUtils.getDocument(node).uri.toString();
const nodePath = this.astNodeLocator.getAstNodePath(node);
return `${documentUri}~${nodePath}`;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
import { AstUtils, LangiumDocument, TreeStreamImpl, URI } from 'langium';
import {
CompositeGeneratorNode,
expandToNode,
expandTracedToNode,
findRootNode,
getContainerOfType,
getDocument,
joinToNode,
joinTracedToNode,
LangiumDocument,
NL,
streamAllContents,
toStringAndTrace,
TraceRegion,
traceToNode,
TreeStreamImpl,
URI,
} from 'langium';
} from 'langium/generate';
import path from 'path';
import { SourceMapGenerator, StartOfSourceMap } from 'source-map';
import { TextDocument } from 'vscode-languageserver-textdocument';
Expand Down Expand Up @@ -310,7 +304,7 @@ export class SafeDsPythonGenerator {
if (currentName) {
segments.unshift(currentName);
}
current = getContainerOfType(current.$container, isSdsDeclaration);
current = AstUtils.getContainerOfType(current.$container, isSdsDeclaration);
}

return segments.join('.');
Expand Down Expand Up @@ -531,14 +525,14 @@ export class SafeDsPythonGenerator {
statementsWithEffect: SdsStatement[],
): SdsStatement[] {
// Find assignment of placeholder, to search used placeholders and impure dependencies
const assignment = getContainerOfType(targetPlaceholder, isSdsAssignment);
const assignment = AstUtils.getContainerOfType(targetPlaceholder, isSdsAssignment);
if (!assignment || !assignment.expression) {
/* c8 ignore next 2 */
throw new Error(`No assignment for placeholder: ${targetPlaceholder.name}`);
}
// All collected referenced placeholders that are needed for calculating the target placeholder. An expression in the assignment will always exist here
const referencedPlaceholders = new Set<SdsPlaceholder>(
streamAllContents(assignment.expression!)
AstUtils.streamAllContents(assignment.expression!)
.filter(isSdsReference)
.filter((reference) => isSdsPlaceholder(reference.target.ref))
.map((reference) => <SdsPlaceholder>reference.target.ref!)
Expand Down Expand Up @@ -569,7 +563,7 @@ export class SafeDsPythonGenerator {
collectedStatements.push(prevStatement);
// Collect all referenced placeholders
if (isSdsExpressionStatement(prevStatement) || isSdsAssignment(prevStatement)) {
streamAllContents(prevStatement.expression!)
AstUtils.streamAllContents(prevStatement.expression!)
.filter(isSdsReference)
.filter((reference) => isSdsPlaceholder(reference.target.ref))
.map((reference) => <SdsPlaceholder>reference.target.ref!)
Expand All @@ -595,7 +589,7 @@ export class SafeDsPythonGenerator {
const blockLambdaCode: CompositeGeneratorNode[] = [];
if (isSdsAssignment(statement)) {
if (statement.expression) {
for (const lambda of streamAllContents(statement.expression).filter(isSdsBlockLambda)) {
for (const lambda of AstUtils.streamAllContents(statement.expression).filter(isSdsBlockLambda)) {
blockLambdaCode.push(this.generateBlockLambda(lambda, frame));
}
}
Expand All @@ -604,7 +598,7 @@ export class SafeDsPythonGenerator {
separator: NL,
})!;
} else if (isSdsExpressionStatement(statement)) {
for (const lambda of streamAllContents(statement.expression).filter(isSdsBlockLambda)) {
for (const lambda of AstUtils.streamAllContents(statement.expression).filter(isSdsBlockLambda)) {
blockLambdaCode.push(this.generateBlockLambda(lambda, frame));
}
blockLambdaCode.push(this.generateExpression(statement.expression, frame));
Expand Down Expand Up @@ -874,7 +868,7 @@ export class SafeDsPythonGenerator {
const suffix = isSdsCall(expression.$container) ? '' : '()';
return expandTracedToNode(expression)`${receiver}.${enumMember}${suffix}`;
} else if (isSdsAbstractResult(member)) {
const resultList = getAbstractResults(getContainerOfType(member, isSdsCallable));
const resultList = getAbstractResults(AstUtils.getContainerOfType(member, isSdsCallable));
if (resultList.length === 1) {
return traceToNode(expression)(receiver);
}
Expand Down Expand Up @@ -1109,8 +1103,8 @@ export class SafeDsPythonGenerator {
}

// Root Node is always a module.
const currentModule = <SdsModule>findRootNode(expression);
const targetModule = <SdsModule>findRootNode(declaration);
const currentModule = <SdsModule>AstUtils.findRootNode(expression);
const targetModule = <SdsModule>AstUtils.findRootNode(declaration);
for (const value of getImports(currentModule)) {
// Verify same package
if (value.package !== targetModule.name) {
Expand Down Expand Up @@ -1150,8 +1144,8 @@ export class SafeDsPythonGenerator {
declaration: SdsDeclaration,
): ImportData | undefined {
// Root Node is always a module.
const currentModule = <SdsModule>findRootNode(expression);
const targetModule = <SdsModule>findRootNode(declaration);
const currentModule = <SdsModule>AstUtils.findRootNode(expression);
const targetModule = <SdsModule>AstUtils.findRootNode(declaration);
if (currentModule !== targetModule && !isInStubFile(targetModule)) {
return {
importPath: `${this.getPythonModuleOrDefault(targetModule)}.${this.formatGeneratedFileName(
Expand All @@ -1164,7 +1158,7 @@ export class SafeDsPythonGenerator {
}

private getModuleFileBaseName(module: SdsModule): string {
const filePath = getDocument(module).uri.fsPath;
const filePath = AstUtils.getDocument(module).uri.fsPath;
return path.basename(filePath, path.extname(filePath));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { convertBigint, CstNode, DefaultValueConverter, GrammarAST, ValueType } from 'langium';
import { CstNode, DefaultValueConverter, GrammarAST, ValueConverter, ValueType } from 'langium';

export class SafeDsValueConverter extends DefaultValueConverter {
protected override runConverter(rule: GrammarAST.AbstractRule, input: string, cstNode: CstNode): ValueType {
switch (rule.name.toUpperCase()) {
case 'ID':
return input.replaceAll('`', '');
case 'INT':
return convertBigint(input);
return ValueConverter.convertBigint(input);
case 'STRING':
return convertString(input, 1, 1);
case 'TEMPLATE_STRING_START':
Expand Down
4 changes: 2 additions & 2 deletions packages/safe-ds-lang/src/language/helpers/astUtils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { AstNode, hasContainerOfType } from 'langium';
import { AstNode, AstUtils } from 'langium';

/**
* Returns whether the inner node is contained in the outer node or equal to it.
*/
export const isContainedInOrEqual = (inner: AstNode | undefined, outer: AstNode | undefined): boolean => {
return hasContainerOfType(inner, (it) => it === outer);
return AstUtils.hasContainerOfType(inner, (it) => it === outer);
};
8 changes: 4 additions & 4 deletions packages/safe-ds-lang/src/language/helpers/fileExtensions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AstNode, getDocument, LangiumDocument } from 'langium';
import { AstNode, AstUtils, LangiumDocument } from 'langium';

/**
* Marks the file as a pipeline file, which can be executed by our runtime component.
Expand Down Expand Up @@ -38,17 +38,17 @@ export type SdSFileExtension = typeof PIPELINE_FILE_EXTENSION | typeof STUB_FILE
/**
* Returns whether the object is contained in a pipeline file.
*/
export const isInPipelineFile = (node: AstNode) => isPipelineFile(getDocument(node));
export const isInPipelineFile = (node: AstNode) => isPipelineFile(AstUtils.getDocument(node));

/**
* Returns whether the object is contained in a stub file.
*/
export const isInStubFile = (node: AstNode) => isStubFile(getDocument(node));
export const isInStubFile = (node: AstNode) => isStubFile(AstUtils.getDocument(node));

/**
* Returns whether the object is contained in a test file.
*/
export const isInTestFile = (node: AstNode) => isTestFile(getDocument(node));
export const isInTestFile = (node: AstNode) => isTestFile(AstUtils.getDocument(node));

/**
* Returns whether the resource represents a pipeline file.
Expand Down
Loading

0 comments on commit d6eec5d

Please sign in to comment.