Skip to content

Commit

Permalink
Merge branch 'main' into fix-formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
ydaveluy authored Aug 14, 2024
2 parents a22fbfc + 245336b commit 09fa930
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/langium/src/lsp/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,11 @@ export abstract class AbstractFormatter implements Formatter {
if (b.hidden) {
return this.createHiddenTextEdits(a, b, formatting, context);
}
// Ignore the edit if the previous node ends after the current node starts
if (a && (a.range.end.line > b.range.start.line ||
(a.range.end.line === b.range.start.line && a.range.end.character > b.range.start.character))) {
return [];
}
const betweenRange: Range = {
start: a?.range.end ?? {
character: 0,
Expand Down
12 changes: 12 additions & 0 deletions packages/langium/test/grammar/lsp/grammar-formatter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,16 @@ describe('Grammar Formatter', () => {
expect(edits.length).toBe(0);
});

test('Formats parser rule definitions with alternatives', async () => {
await formatting({
before: expandToString`
Type:
DataType | Entity;
`,
after: expandToString`
Type:
DataType | Entity;
`
});
});
});

0 comments on commit 09fa930

Please sign in to comment.