-
Notifications
You must be signed in to change notification settings - Fork 463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make the pretty printer usable for code formatting #369
Comments
An example of a missing feature is "hanging" |
See #867 |
@Kha Should we close this issue? |
I fear I could only close it in good conscience if we used it to reformat our own codebase :) . |
From my point of view there are still several challenges ahead. The applications I have in mind are mostly mathport / code action related, so this list might a bit biased. Formatting rules for special-case formattingThe A complicated (yet common and important) syntax is the structure instance syntax. This is used for different applications, with different formatting requirements.
let s := {
x := 1
y := 2
} Particularly for 1 it would be nice if you could just add a "formatting rule" that says "format See also Combinators for indentation-sensitive syntaxLean 4 has lots of indentation-sensitive syntaxes where lines need to start at specific columns. But the only available formatting combinator to achieve this is See also current hack for Selecting
|
Hi folks! Have y’all looked at Prettier in the JS ecosystem? In particular it deals with a lot of similar complexity as what you seem to be running into. Some details about its approach:
I’m not an expert in this area so it’s hard for me to compare what’s implemented / missing but I wonder if there’s anything in Prettier’s approach, implementation and/or abstraction that would be helpful to take a look at. Separately, I’m also lowkey curious whether it would be difficult to actually write a Prettier plugin for Lean (this would of course be a separate project and would need to somehow parse Lean into JSON, and then use Prettier’s utilities for the actual act of pretty printing). I presume this is a less favored path for folks here (not nice to cross languages or fail to reuse existing work) but I’m still wondering about technical feasibility. I’d just really like to get something running, and Prettier is pretty much the industry standard in JS land. Not sure if any non-JS plugins are good though. Of course a Lean-native implementation is probably the way to go though. But I really want to have something soon-ish as a user… |
The formatter in the pretty printer already produces pretty good output for goals and also makes a reasonable attempt at preserving comments and command-level layout: https://github.com/leanprover/lean4/blob/master/tests/lean/Reformat.lean.expected.out. But it is not yet at a point where we would reformat our code with it despite the advantages of doing so:
The text was updated successfully, but these errors were encountered: