Skip to content

Commit 8263913

Browse files
committed
Revert implementation to correct one
1 parent a8eb8b5 commit 8263913

File tree

1 file changed

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

1 file changed

+11
-9
lines changed

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -755,21 +755,23 @@ 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+
758765
matchWithDiagnostic :: Range -> Located (IdP GhcPs) -> Bool
759766
matchWithDiagnostic Range{_start=l,_end=r} x =
760767
let loc = fmap _start . getLocatedRange $ x
761768
in loc >= Just l && loc <= Just r
762769

763770
printExport :: ExportsAs -> T.Text -> T.Text
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 ", "(..)")
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 <> "(..)"
773775

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

0 commit comments

Comments
 (0)