Skip to content

Commit

Permalink
moved generator API to a dedicated package export, solves #1285
Browse files Browse the repository at this point in the history
* refactored most of our generators to use 'expandToNode' and friends instead of instantiating 'CompositeGeneratorNodes'
  • Loading branch information
sailingKieler committed Nov 10, 2023
1 parent 7066ac4 commit 46e00ef
Show file tree
Hide file tree
Showing 29 changed files with 350 additions and 363 deletions.
3 changes: 2 additions & 1 deletion examples/domainmodel/src/benchmark/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
* terms of the MIT License, which is available in the project root.
******************************************************************************/

import { expandToString, URI } from 'langium';
import { URI } from 'langium';
import { expandToString } from 'langium/generating';
import type { DomainModelServices } from '../language-server/domain-model-module.js';

export function generateWorkspace(services: DomainModelServices, width: number, size: number): void {
Expand Down
5 changes: 2 additions & 3 deletions examples/domainmodel/src/cli/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
* terms of the MIT License, which is available in the project root.
******************************************************************************/

import type { IndentNode } from 'langium';
import type { AbstractElement, Domainmodel, Entity, Feature, Type } from '../language-server/generated/ast.js';
import * as fs from 'node:fs';
import * as path from 'node:path';
import chalk from 'chalk';
import _ from 'lodash';
import { CompositeGeneratorNode, NL, toString } from 'langium';
import { CompositeGeneratorNode, NL, toString } from 'langium/generating';
import { isEntity, isPackageDeclaration } from '../language-server/generated/ast.js';
import { extractAstNode, extractDestinationAndName, setRootFolder } from './cli-util.js';
import { createDomainModelServices } from '../language-server/domain-model-module.js';
Expand Down Expand Up @@ -80,7 +79,7 @@ function generateEntity(entity: Entity, fileNode: CompositeGeneratorNode): void
fileNode.append('}', NL);
}

function generateFeature(feature: Feature, classBody: IndentNode): [() => void, () => void, () => void] {
function generateFeature(feature: Feature, classBody: CompositeGeneratorNode): [() => void, () => void, () => void] {
const name = feature.name;
const type = feature.type.$refText + (feature.many ? '[]' : '');

Expand Down
2 changes: 1 addition & 1 deletion examples/requirements/src/cli/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import type { RequirementModel, TestModel } from '../language-server/generated/ast.js';
import * as fs from 'node:fs';
import * as path from 'node:path';
import { CompositeGeneratorNode, NL, toString } from 'langium';
import { CompositeGeneratorNode, NL, toString } from 'langium/generating';
import { extractDestinationAndName } from './cli-util.js';

/**
Expand Down
3 changes: 1 addition & 2 deletions examples/statemachine/src/cli/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

import * as fs from 'node:fs';
import * as path from 'node:path';
import { expandToNode as toNode, joinToNode as join, toString } from 'langium';
import type { Generated } from 'langium';
import { type Generated, expandToNode as toNode, joinToNode as join, toString } from 'langium/generating';
import type { State, Statemachine } from '../language-server/generated/ast.js';
import { extractDestinationAndName } from './cli-util.js';

Expand Down
8 changes: 4 additions & 4 deletions examples/statemachine/test/generator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
* terms of the MIT License, which is available in the project root.
******************************************************************************/

import type { Generated } from 'langium';
import type { Statemachine } from '../src/language-server/generated/ast.js';
import { describe, expect, test } from 'vitest';
import { EmptyFileSystem, expandToStringWithNL, toString } from 'langium';
import { EmptyFileSystem } from 'langium';
import { expandToStringWithNL, toString, type Generated } from 'langium/generating';
import { parseHelper } from 'langium/test';
import { describe, expect, test } from 'vitest';
import { generateCppContent } from '../src/cli/generator.js';
import type { Statemachine } from '../src/language-server/generated/ast.js';
import { createStatemachineServices } from '../src/language-server/statemachine-module.js';

describe('Tests the code generator', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/generator-langium/test/yeoman-generator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
******************************************************************************/

import { describe, test } from 'vitest';
import { normalizeEOL } from 'langium';
import { normalizeEOL } from 'langium/generating';
import * as path from 'node:path';
import { createHelpers } from 'yeoman-test';

Expand Down
Loading

0 comments on commit 46e00ef

Please sign in to comment.