eclipse-xtext / eclipse-xtext/xtext
Extra indentation on template output after line break
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 831
- Forks
- 330
- Avg merge
- 3d 7h
- Merged PRs (30d)
- 12
Description
I would like to avoid code like this:
def static String silly(List<Integer> someList) '''
class Silly
{
public:
Silly();
~Silly();
«IF someList !== null && !someList.empty»
«FOR n: someList»
int method«n»() const { return «n»; }
«ENDFOR»
«ENDIF»
};
'''
where I have to use an IF to check the list if I want to leave a blank line before the items generated in the FOR loop.
I believe that the logical thing to do would be using this code instead:
def static String silly(List<Integer> someList) '''
class Silly
{
public:
Silly();
~Silly();
«FOR n: someList BEFORE '\n'»
int method«n»() const { return «n»; }
«ENDFOR»
};
'''
However, that makes the following test fail:
@Test
def void TestSilly() {
assertLinesMatch(
'''
class Silly
{
public:
Silly();
~Silly();
int method1() const { return 1; }
int method2() const { return 2; }
int method3() const { return 3; }
};
'''.toString.split(System.getProperty('line.separator')),
silly(#[1,2,3]).split(System.getProperty('line.separator'))
)
}
because the generated code is this:
class Silly
{
public:
Silly();
~Silly();
int method1() const { return 1; }
int method2() const { return 2; }
int method3() const { return 3; }
};
Notice the extra indentation in the line int method1() const....
The result is the same if I use any of the following as argument to BEFORE:
System.getProperty('line.separator')'\n''\r\n'
I am using Eclipse DSL Tools version 2020-12 (4.18.0), Xtext Complete SDK 2.24.0.v20201130-1016, on Windows.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the inline TestSilly case with the FOR loop using BEFORE '\n' and compare it with the expected output shown in the issue. Trace how the template engine handles the first generated item after a line break. Done means the first item has the same indentation as subsequent items and the test passes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100