@@ -38,6 +38,20 @@ p_classDecl ctx name HsQTvs {..} fixity fdeps csigs cdefs cats catdefs cdocs = d
38 signatureSpans = getLoc name : variableSpans
38 signatureSpans = getLoc name : variableSpans
39 dependencySpans = getLoc <$> fdeps
39 dependencySpans = getLoc <$> fdeps
40 combinedSpans = getLoc ctx : (signatureSpans ++ dependencySpans)
40 combinedSpans = getLoc ctx : (signatureSpans ++ dependencySpans)
41+ -- GHC's AST does not necessarily store each kind of element in source
42+ -- location order. This happens because different declarations are stored
43+ -- in different lists. Consequently, to get all the declarations in proper
44+ -- order, they need to be manually sorted.
45+ sigs = (getLoc &&& fmap (SigD NoExt)) <$> csigs
46+ vals = (getLoc &&& fmap (ValD NoExt)) <$> toList cdefs
47+ tyFams = (getLoc &&& fmap (TyClD NoExt . FamDecl NoExt)) <$> cats
48+ docs = (getLoc &&& fmap (DocD NoExt)) <$> cdocs
50+ ( getLoc &&& fmap (InstD NoExt . TyFamInstD NoExt . defltEqnToInstDecl)
54+ snd <$> sortOn fst (sigs <> vals <> tyFams <> tyFamDefs <> docs)
41 txt "class"
55 txt "class"
42 switchLayout combinedSpans $ do
56 switchLayout combinedSpans $ do
43 breakpoint
57 breakpoint
@@ -50,23 +64,10 @@ p_classDecl ctx name HsQTvs {..} fixity fdeps csigs cdefs cats catdefs cdocs = d
50 (p_rdrName name)
64 (p_rdrName name)
51 (located' p_hsTyVarBndr <$> hsq_explicit)
65 (located' p_hsTyVarBndr <$> hsq_explicit)
52 inci (p_classFundeps fdeps)
66 inci (p_classFundeps fdeps)
53− -- GHC's AST does not necessarily store each kind of element in source
54− -- location order. This happens because different declarations are stored
55− -- in different lists. Consequently, to get all the declarations in proper
56− -- order, they need to be manually sorted.
57− let sigs = (getLoc &&& fmap (SigD NoExt)) <$> csigs
58− vals = (getLoc &&& fmap (ValD NoExt)) <$> toList cdefs
59− tyFams = (getLoc &&& fmap (TyClD NoExt . FamDecl NoExt)) <$> cats
60− docs = (getLoc &&& fmap (DocD NoExt)) <$> cdocs
62− ( getLoc &&& fmap (InstD NoExt . TyFamInstD NoExt . defltEqnToInstDecl)
65− allDecls =
67+ unless (null allDecls) $ do
66− snd <$> sortOn fst (sigs <> vals <> tyFams <> tyFamDefs <> docs)
68+ breakpoint
67 unless (null allDecls) $ do
70 unless (null allDecls) $ do
70 breakpoint -- Ensure whitespace is added after where clause.
71 breakpoint -- Ensure whitespace is added after where clause.
71 inci (p_hsDeclsRespectGrouping Associated allDecls)
72 inci (p_hsDeclsRespectGrouping Associated allDecls)
72p_classDecl _ _ XLHsQTyVars {} _ _ _ _ _ _ _ = notImplemented "XLHsQTyVars"
73p_classDecl _ _ XLHsQTyVars {} _ _ _ _ _ _ _ = notImplemented "XLHsQTyVars"