jvalue / jayvee

Jayvee is a domain-specific language and runtime for automated processing of data pipelines
https://jvalue.github.io/jayvee/
150 stars 15 forks source link

Add custom Jayvee formatter #562

Closed georg-schwarz closed 6 months ago

georg-schwarz commented 6 months ago

Adds a custom formatter to via the language server protocol. Future updates might enable using the formatted from CLI.

Works around an issue with comments not being correctly formatted: https://github.com/eclipse-langium/langium/issues/1351

georg-schwarz commented 6 months ago

Thx, good catches!

I noticed in the meanwhile that Langium itself does AST-node-specific formatting. Probably sth we should consider as well (e.g., for the colons). https://github.com/eclipse-langium/langium/blob/main/packages/langium/src/grammar/lsp/grammar-formatter.ts

joluj commented 6 months ago

I noticed in the meanwhile that Langium itself does AST-node-specific formatting. Probably sth we should consider as well (e.g., for the colons).

I've tried that when I've created the initial POC. For the colons end brackets, I decided against it. With it, we need to explicitly provide every relevant AST element, which seemed laborious for a POC. However, since it goes to production now, we should reevaluate.

georg-schwarz commented 6 months ago

Fixed the issues and converted all examples to use 2 spaces.

Every file should end with exactly one empty line https://stackoverflow.com/questions/729692/why-should-text-files-end-with-a-newline

That should be tackled in a separate issue (#567).

In general, I'm not too happy with the implementation. At some points two formatting are valid that the formatting function switches between when applied. But I'll leave that to future PRs, together with the refactoring to apply formatting not globally but AST node specifically.