Formatting problems
I'm trying to update my formatter to be able to format nested Clojure data structures in an intelligent way, but I can't get it to work. I'm seeing large amounts of spurious whitespace inserted, and generally things not obeying the constraints I've set.
A little bit of background - Clojure maps are delimited by {} braces, and are a series of key/value pairs. Keys are normally keywords, which start with a colon (e.g. :namespace). The blocks created for a map use an indent of 1 so they line up inside the braces, and the values are also aligned using a shifting alignment. Here's a simple example of what this looks like:
{:as #<ClEditorSymbol psi>,
:namespace #<ClEditorSymbol plugin.psi>,
:spec #<ClVectorImpl ClVector>}
So far so good. However with more complex structures this breaks down in non-obvious ways:
{:clauses [{:as #<ClEditorSymbol psi>,
:namespace #<ClEditorSymbol plugin.psi>,
:spec #<ClVectorImpl ClVector>}
{:as #<ClEditorSymbol ast>,
:namespace #<ClEditorSymbol plugin.ast>,
:spec #<ClVectorImpl ClVector>}
{:as #<ClEditorSymbol str>,
:namespace #<ClEditorSymbol clojure.string>,
:spec #<ClVectorImpl ClVector>}
{:as #<ClEditorSymbol app>,
:namespace #<ClEditorSymbol plugin.application>,
:spec #<ClVectorImpl ClVector>}
{:as #<ClEditorSymbol format>,
:namespace #<ClEditorSymbol plugin.formatting>,
:spec #<ClVectorImpl ClVector>}],
:require #<ClListImpl ClList>}
Once this starts happening, I also see other strangeness such as the values not being correctly aligned. There's an example of this attached, it's too big to insert here directly - note that the values of the top-level map are not aligned - those from sub-maps are.
Any ideas what might be causing this? I've checked with the PSI viewer, and as far as I can tell the blocks are being created correctly. Any tips as to how I might debug this are very welcome.
Edit: the forum software is doing some strange things to the initial line indent, but both these examples are taken from the attached file - you can see what it actually looks like there.
Attachment(s):
formatting-problem.txt.zip
请先登录再写评论。
I've attached another example, from a REPL session where adding one item to the map (:classes [#<ClEditorSymbol java.util.Map>]) causes the whitespace issue to resolve itself.
Attachment(s):
formatting-problem.txt.zip
I filed this as a bug: https://youtrack.jetbrains.com/issue/IDEA-136426