Skip to content

Commit 6642baa

Browse files
committed
Refactor printExport
1 parent a4c15b1 commit 6642baa

File tree

1 file changed

+9
-11
lines changed
  • plugins/hls-refactor-plugin/src/Development/IDE/Plugin

1 file changed

+9
-11
lines changed

plugins/hls-refactor-plugin/src/Development/IDE/Plugin/CodeAction.hs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -755,23 +755,21 @@ suggestExportUnusedTopBinding srcOpt ParsedModule{pm_parsed_source = L _ HsModul
755755
opLetter :: T.Text
756756
opLetter = ":!#$%&*+./<=>?@\\^|-~"
757757

758-
parenthesizeIfNeeds :: Bool -> T.Text -> T.Text
759-
parenthesizeIfNeeds needsTypeKeyword x
760-
| T.any (c ==) opLetter = (if needsTypeKeyword then "type " else "") <> "(" <> x <> ")"
761-
| otherwise = x
762-
where
763-
c = T.head x
764-
765758
matchWithDiagnostic :: Range -> Located (IdP GhcPs) -> Bool
766759
matchWithDiagnostic Range{_start=l,_end=r} x =
767760
let loc = fmap _start . getLocatedRange $ x
768761
in loc >= Just l && loc <= Just r
769762

770763
printExport :: ExportsAs -> T.Text -> T.Text
771-
printExport ExportName x = parenthesizeIfNeeds False x
772-
printExport ExportPattern x = "pattern " <> parenthesizeIfNeeds False x
773-
printExport ExportFamily x = parenthesizeIfNeeds True x
774-
printExport ExportAll x = parenthesizeIfNeeds True x <> "(..)"
764+
printExport ea name = prefix <> parenthesizedName <> suffix
765+
where
766+
parenthesizedName = if T.any (firstChar ==) opLetter then "(" <> name <> ")" else name
767+
firstChar = T.head name
768+
(prefix, suffix) = case ea of
769+
ExportName -> ("", "")
770+
ExportPattern -> ("pattern ", "")
771+
ExportFamily -> ("type ", "")
772+
ExportAll -> ("type ", "(..)")
775773

776774
isTopLevel :: SrcSpan -> Bool
777775
isTopLevel span = fmap (_character . _start) (srcSpanToRange span) == Just 0

0 commit comments

Comments
 (0)