The formatter is one of the favourite IDE features of many developers. Always having a consistent code style, never having to worry about tabs, spaces, indentation or alignment is a tremendous help. But have you ever wondered how a formatter works?
With release 2.9, Xtext introduced the world to their new formatter2 API. It allows a formatter to access the text and the node model, as well as the AST. This allows the formatter to have a better understanding of the context, which in turn enables complicated conditional and pattern-aware code formatting.
At Sigasi we used the new API to reimplement our existing VHDL formatter, porting over features such as comment aligning and consistent keyword casing. This also means we had to add brand new features that are not readily available in Xtext.
In this talk we will summarize the basics of Xtext’s formatter2 API, demonstrate the implementation of our enhancements and discuss the problems we encountered along the way.





















