eclipse-langium / langium

Next-gen language engineering / DSL framework
https://langium.org/
MIT License
754 stars 68 forks source link

Whitespace missing after code generation #1068

Closed Lotes closed 1 year ago

Lotes commented 1 year ago

When I try to generate code using expandToNode the function hides whitespace (but not always), which makes the generated code a bit ugly. I can not see a pattern, my current assumption was that it has to do something with the kind of bracket operators >, <, >=, ... Or the method is trimming whitespace once too much.

Reproduction

Langium version: 1.0.0

import { toString, expandToNode } from 'langium';

test('Reproduction', () => {
    //sub expressions are part of a recursive call
    const left = expandToNode`left`;
    const right = expandToNode`right`;

    //handle binary operator >
    const operator = '>';
    const binaryOperation = expandToNode`${left} ${operator} ${right}`;

    //check expectations
    const actual = toString(binaryOperation)
    expect(actual).toBe('left > right');
    //but actual is "left >right" (whitespace after '>' is missing)
});
sailingKieler commented 1 year ago

I can reproduce your issue with Langium v1.0.1, but cannot with Langium v1.1.0. @Lotes please check on your side.

Lotes commented 1 year ago

Ah ok, same for me. Sorry for the noise :). I will just update my dependency to the latest. Thanks.