Instance methods don't seem to be formatted #17
Labels
No Label
blocked: dependency
blocked: info-needed
bug
duplicate
enhancement
fixed in HEAD
help wanted
hs:arrows
hs:brackets
hs:classes
hs:comments
hs:do-notation
hs:guards
hs:lists
hs:operators
hs:patterns
hs:records
hs:types
invalid
language extension support
layouting
needs confirmation
priority: high
priority: low
question
revisit before next release
wontfix
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: hexagoxel/brittany#17
Loading…
Reference in New Issue
There is no content yet.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may exist for a short time before cleaning up, in most cases it CANNOT be undone. Continue?
Doesn't seem to be reformatted at all.
Well, it is accurately described in the README
But that certainly (only) is a description of the current state of things, and implementing support for instances is on the to-do list.
I would love to have Brittany be able to format classes and instances! How can I help here?
Implementation-wise, the task is not much different from supporting data-type declarations: Take some class or instance definition, consider its AST and add the corresponding case to
layoutDecl
(which by now lives inLanguage.Haskell.Brittany.Internal.Layouters.Decl
) and handle theGHC-AST -> (To)BriDoc
conversion. See my comment of this process over at the data-type issue.For both classes and instances we will of course re-use the existing layouters for signatures and bindings, but the headers will need new layouters. So the layouters will probably both have some form like
(overly simplified)
Implementation is just one step; a rough roadmap might look like:
Very simple input would e.g. be
(The unnecessary whitespace will indicate if things are working.)
For something very complex, consider something like
(this might have a better layout, just some example to serve as input.)
(And yes, we assume
-XMultiParamTypeClasses
and-XFunctionalDependencies
here. Feel free to not support any extensions that are hard to design/implement - better get support for 2010 Haskell than get stuck with those.)Any chance we could get just the instance body for now? That at least seems trivial. The harder problem of the instance head can be solved after, right?
Instance body is a great incremental step. There may be some blockers since
instance
syntax can get pretty flexible...I'd approach this using the following technique: Take the instance ast, remove all children from it, and pass that to exactprint. With some luck this gets us just the unmodified head including any comments connected to it. Then use
layoutDecl
on the children we removed, and wrap the resulting list of BriDocs to add the desired indentation.(Whole modules were done in the same manner, before we had head/exports/imports formatting.)
I'm working on a PR for this now - it's working with the
stack.yaml
, so just need to test it with other versions of GHC.Right now it's just for instances and calls through to
ExactPrint
in a couple of places. I'm concerned aboutdata
definitions in instances, because theExactPrint
results contain newlines and indentation. I think I might have to implement a layouter for data definitions too, otherwise you end up doing someText
processing on the resultingBDFExternal
, which is not ideal.I can put a PR up with the
Text
processing stuff in place and maybe you can take a look, @lspitzner, and let me know if you can think of any other simple solutions.@ruhatch I'd happily test this against Freckle's codebase when you have the branch up. Thanks for the work!
The PR is up and linked above.
@eborden Running that over Freckle's codebase and carefully checking any complex instances would be great.
@lspitzner If you could take a look at the
stripWhitespace'
function and let me know if you can see any better ways of doing it, that'd be awesome :)@ruhatch Output looks great to me. I'm only seeing 3 additional
brittany
errors, but those are all coming from instance bodies that include splices, that were previously ignored. Great work!This was fixed by #187. Thanks @ruhatch!