Skip to content

Commit 2cbeef1

Browse files
committed
refactor plugin: fix regex for extracting import suggestions
1 parent e93528b commit 2cbeef1

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

Diff for: 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) <-

Diff for: plugins/hls-refactor-plugin/test/Main.hs

+14
Original file line numberDiff line numberDiff line change
@@ -1275,6 +1275,20 @@ extendImportTests = testGroup "extend import actions"
12751275
, "b :: A"
12761276
, "b = ConstructorFoo"
12771277
])
1278+
, testSession "extend single line import in presence of extra perens" $ template
1279+
[]
1280+
("Main.hs", T.unlines
1281+
[ "import Data.Monoid (First)"
1282+
, "f = (First Nothing) <> mempty" -- parens tripped up the regex extracting import suggestions
1283+
])
1284+
(Range (Position 1 6) (Position 1 7))
1285+
[ "Add First(..) to the import list of Data.Monoid"
1286+
, "Add First(First) to the import list of Data.Monoid"
1287+
]
1288+
(T.unlines
1289+
[ "import Data.Monoid (First (..))"
1290+
, "f = (First Nothing) <> mempty"
1291+
])
12781292
, brokenForGHC94 "On GHC 9.4, the error messages with -fdefer-type-errors don't have necessary imported target srcspan info." $
12791293
testSession "extend single line qualified import with value" $ template
12801294
[("ModuleA.hs", T.unlines

0 commit comments

Comments
 (0)