rescript-association / reanalyze

Experimental analyses for ReScript and OCaml: globally dead values/types, exception analysis, and termination analysis.
MIT License
277 stars 20 forks source link

Variants location adjustment to insert annotations. #171

Closed cristianoc closed 2 years ago

cristianoc commented 2 years ago

Special treatment for variants location in json output.

The location of variants declarations in the typed tree includes the "|" and whatever spaces are there. This complicates adding annotations that need to handle a number of special cases.

E.g.

type v = A | B | C

The locations are as follows: A and | B and | C.

Because of this issue https://github.com/rescript-lang/syntax/issues/506 the case of A needs to be special-cased by adding |.

For B and C we take the convention of adding the annotation 2 characters after the reported location. Which is not good for A|B|C but works well on formatted code.