Skip to content

Commit 29bf624

Browse files
jhrceksoulomoon
authored andcommitted
refactor plugin: fix regex for extracting import suggestions (haskell#4080)
1 parent c8b286a commit 29bf624

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -931,9 +931,9 @@ suggestExtendImport exportsMap (L _ HsModule {hsmodImports}) Diagnostic{_range=_
931931
| Just [binding, mod, srcspan] <-
932932
matchRegexUnifySpaces _message
933933
#if MIN_VERSION_ghc(9,7,0)
934-
"Add ‘([^’]*)’ to the import list in the import of ‘([^’]*)’ *\\(at (.*)\\)."
934+
"Add ‘([^’]*)’ to the import list in the import of ‘([^’]*)’ *\\(at (.*)\\)\\."
935935
#else
936-
"Perhaps you want to add ‘([^’]*)’ to the import list in the import of ‘([^’]*)’ *\\((.*)\\)."
936+
"Perhaps you want to add ‘([^’]*)’ to the import list in the import of ‘([^’]*)’ *\\((.*)\\)\\."
937937
#endif
938938
= suggestions hsmodImports binding mod srcspan
939939
| Just (binding, mod_srcspan) <-

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

+18
Original file line numberDiff line numberDiff line change
@@ -1275,6 +1275,21 @@ extendImportTests = testGroup "extend import actions"
12751275
, "b :: A"
12761276
, "b = ConstructorFoo"
12771277
])
1278+
, brokenForGHC92 "On GHC 9.2, the error doesn't contain \"perhaps you want ...\" part from which import suggestion can be extracted." $
1279+
testSession "extend single line import in presence of extra parens" $ template
1280+
[]
1281+
("Main.hs", T.unlines
1282+
[ "import Data.Monoid (First)"
1283+
, "f = (First Nothing) <> mempty" -- parens tripped up the regex extracting import suggestions
1284+
])
1285+
(Range (Position 1 6) (Position 1 7))
1286+
[ "Add First(..) to the import list of Data.Monoid"
1287+
, "Add First(First) to the import list of Data.Monoid"
1288+
]
1289+
(T.unlines
1290+
[ "import Data.Monoid (First (..))"
1291+
, "f = (First Nothing) <> mempty"
1292+
])
12781293
, brokenForGHC94 "On GHC 9.4, the error messages with -fdefer-type-errors don't have necessary imported target srcspan info." $
12791294
testSession "extend single line qualified import with value" $ template
12801295
[("ModuleA.hs", T.unlines
@@ -3735,3 +3750,6 @@ withTempDir f = System.IO.Extra.withTempDir $ \dir ->
37353750

37363751
brokenForGHC94 :: String -> TestTree -> TestTree
37373752
brokenForGHC94 = knownBrokenForGhcVersions [GHC94]
3753+
3754+
brokenForGHC92 :: String -> TestTree -> TestTree
3755+
brokenForGHC92 = knownBrokenForGhcVersions [GHC92]

0 commit comments

Comments
 (0)