@@ -52,37 +52,17 @@ groupPerLine :: [((Int, Int), a)] -> [(Int, [(Int, a)])]
5252groupPerLine = M. toList . M. fromListWith (++) .
5353 map (\ ((r, c), x) -> (r, [(c, x)]))
5454
55-
56- --------------------------------------------------------------------------------
57- typeSigs :: Module -> Lines -> [((Int , Int ), String )]
58- typeSigs module' ls =
59- [ (pos, " :: " )
55+ -- | Find symbol positions in the module. Currently only searches in type
56+ -- signatures.
57+ findSymbol :: Module -> Lines -> String -> [((Int , Int ), String )]
58+ findSymbol module' ls sym =
59+ [ (pos, sym )
6060 | TypeSig _ funLoc typeLoc <- everything (rawModuleDecls $ moduleDecls module') :: [Sig GhcPs ]
61- , (_, funEnd) <- infoPoints funLoc
62- , (typeStart, _) <- infoPoints [hsSigWcType typeLoc]
63- , pos <- maybeToList $ between funEnd typeStart " ::" ls
64- ]
65-
66- --------------------------------------------------------------------------------
67- contexts :: Module -> Lines -> [((Int , Int ), String )]
68- contexts module' ls =
69- [ (pos, " =>" )
70- | TypeSig _ _ typeLoc <- everything (rawModuleDecls $ moduleDecls module') :: [Sig GhcPs ]
71- , (start, end) <- infoPoints [hsSigWcType typeLoc]
72- , pos <- maybeToList $ between start end " =>" ls
61+ , (funStart, _) <- infoPoints funLoc
62+ , (_, typeEnd) <- infoPoints [hsSigWcType typeLoc]
63+ , pos <- maybeToList $ between funStart typeEnd sym ls
7364 ]
7465
75-
76- --------------------------------------------------------------------------------
77- typeFuns :: Module -> Lines -> [((Int , Int ), String )]
78- typeFuns module' ls =
79- [ (pos, " ->" )
80- | TypeSig _ _ typeLoc <- everything (rawModuleDecls $ moduleDecls module') :: [Sig GhcPs ]
81- , (start, end) <- infoPoints [hsSigWcType typeLoc]
82- , pos <- maybeToList $ between start end " ->" ls
83- ]
84-
85-
8666--------------------------------------------------------------------------------
8767-- | Search for a needle in a haystack of lines. Only part the inside (startRow,
8868-- startCol), (endRow, endCol) is searched. The return value is the position of
@@ -113,7 +93,5 @@ step' alp lg ls module' = applyChanges changes ls
11393 where
11494 changes = (if alp then addLanguagePragma lg " UnicodeSyntax" module' else [] ) ++
11595 replaceAll perLine
116- perLine = sort $ groupPerLine $
117- typeSigs module' ls ++
118- contexts module' ls ++
119- typeFuns module' ls
96+ toReplace = [ " ::" , " =>" , " ->" ]
97+ perLine = sort $ groupPerLine $ concatMap (findSymbol module' ls) toReplace
0 commit comments