Skip to content

Commit da403a7

Browse files
authored
Fix exporting operator pattern synonym (#4420)
* Add tests for export unused top binding code action For symbolic pattern synonyms, type families and type classes * Parenthesize symbolic pattern synonyms in add export code action * Refactor printExport * Remove superfluous tests * Revert implementation to correct one
1 parent ae341fe commit da403a7

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ suggestExportUnusedTopBinding srcOpt ParsedModule{pm_parsed_source = L _ HsModul
769769

770770
printExport :: ExportsAs -> T.Text -> T.Text
771771
printExport ExportName x = parenthesizeIfNeeds False x
772-
printExport ExportPattern x = "pattern " <> x
772+
printExport ExportPattern x = "pattern " <> parenthesizeIfNeeds False x
773773
printExport ExportFamily x = parenthesizeIfNeeds True x
774774
printExport ExportAll x = parenthesizeIfNeeds True x <> "(..)"
775775

plugins/hls-refactor-plugin/test/Main.hs

+13
Original file line numberDiff line numberDiff line change
@@ -3413,6 +3413,19 @@ exportUnusedTests = testGroup "export unused actions"
34133413
, "module A (pattern Foo) where"
34143414
, "pattern Foo a <- (a, _)"
34153415
]
3416+
, testSession "unused pattern synonym operator" $ template
3417+
[ "{-# OPTIONS_GHC -Wunused-top-binds #-}"
3418+
, "{-# LANGUAGE PatternSynonyms #-}"
3419+
, "module A () where"
3420+
, "pattern x :+ y = (x, y)"
3421+
]
3422+
(R 3 0 3 12)
3423+
"Export ‘:+’"
3424+
[ "{-# OPTIONS_GHC -Wunused-top-binds #-}"
3425+
, "{-# LANGUAGE PatternSynonyms #-}"
3426+
, "module A (pattern (:+)) where"
3427+
, "pattern x :+ y = (x, y)"
3428+
]
34163429
, testSession "unused data type" $ template
34173430
[ "{-# OPTIONS_GHC -Wunused-top-binds #-}"
34183431
, "module A () where"

0 commit comments

Comments
 (0)