Commit Graph

11 Commits

Author SHA1 Message Date
Utku Demir
f86155a8ea Try to contain comments inside enclosing constructs
Attach the comment if the next element is not a sibling. I think this is
quite often what we want, since if we put a comment inside a construct, we
prefer it to stay inside the same element.
2019-08-16 16:11:33 +02:00
mrkkrp
e21e4ef119 Fix mis-formatting of per-argument comments in certain cases 2019-08-13 20:59:22 +02:00
Utku Demir
b6c29bdf12 Handle OPTIONS_GHC and OPTIONS_HADDOCK pragmas
This change adds an ad-hoc parser for module pragmas to handle
OPTIONS_* pragmas. I did not want to use an existing tokenizer,
because I felt like tokenizing and pretty printing the GHC options
are more prone to error without providing much benefit.
2019-08-11 16:04:42 +02:00
Utku Demir
be6d09d148 Workaround GHC tokenizer bug while extracting LANGUAGE pragmas 2019-08-09 11:24:11 +02:00
mrkkrp
93271b2551 Make sure no comments are swallowed at the end 2019-08-08 20:20:17 +02:00
mrkkrp
875c79d88d Implement dropping of trailing whitespace in comments 2019-07-05 21:01:45 +02:00
waddlaw
ae40a33507 Sort language pragmas and fix their placement in modules
The approach we take here is parsing of language pragmas on creation of
comment stream and then pretty-printing them in a separate block.
2019-07-05 20:03:31 +02:00
mrkkrp
f8bad3a855 Only drop indentation present for every line in multiline comments 2019-07-01 00:07:54 +02:00
Basile Henry
faf3d86f14 Recognize gaps between comment blocks 2019-06-30 22:59:21 +02:00
mrkkrp
803f76aab9 Fix Haddock placement for function arguments
I'm not sure it's perfect, but it fixes the original issue and all the tests
pass.

The problem was in entering with locate (or some version of it) the same
span twice. So the algorithm saw an element with identical enclosing element
and the ‘commentFollowsElt’ function got confused.

The solution is two first augment registration of enclosing spans to allow
us to keep more than one item there. Then we can filter out spans which are
just copies of current reference span to get to the “real” enclosing span.

It seems to make sense to attach comments to child element if it starts
exactly at the same position of parent element, hence the distance between
start of enclosing/reference span and start of comment is the same, thus
changing ‘>’ to ‘>=’ in ‘commentFollowsElt’.
2019-06-11 22:21:41 +02:00
mrkkrp
b9c8b64947 Implement more precise comment placement without ‘ghc-exactprint’
‘ghc-exactprint’ (or perhaps lexer of GHC itself) does a fairly poor job at
associating comments with elements of AST. In many cases the result is not
what you'd expect. We ran into insuperable problems with that to the effect
that correct comment placement were impossible.

The new approach is to exploit the raw position information provided by the
GHC lexer, that is, spans attached to AST elements and comments. This
allowed us to place comments in output in a very precise and satisfactory
fashion.
2019-05-08 22:03:21 +02:00