From 2cbeef12530c2a864147beabae923be30abd06fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Hr=C4=8Dek?= Date: Fri, 16 Feb 2024 18:08:55 +0100 Subject: [PATCH 1/2] refactor plugin: fix regex for extracting import suggestions --- .../src/Development/IDE/Plugin/CodeAction.hs | 4 ++-- plugins/hls-refactor-plugin/test/Main.hs | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/plugins/hls-refactor-plugin/src/Development/IDE/Plugin/CodeAction.hs b/plugins/hls-refactor-plugin/src/Development/IDE/Plugin/CodeAction.hs index f969ac1fdf..20a67ad747 100644 --- a/plugins/hls-refactor-plugin/src/Development/IDE/Plugin/CodeAction.hs +++ b/plugins/hls-refactor-plugin/src/Development/IDE/Plugin/CodeAction.hs @@ -931,9 +931,9 @@ suggestExtendImport exportsMap (L _ HsModule {hsmodImports}) Diagnostic{_range=_ | Just [binding, mod, srcspan] <- matchRegexUnifySpaces _message #if MIN_VERSION_ghc(9,7,0) - "Add ‘([^’]*)’ to the import list in the import of ‘([^’]*)’ *\\(at (.*)\\)." + "Add ‘([^’]*)’ to the import list in the import of ‘([^’]*)’ *\\(at (.*)\\)\\." #else - "Perhaps you want to add ‘([^’]*)’ to the import list in the import of ‘([^’]*)’ *\\((.*)\\)." + "Perhaps you want to add ‘([^’]*)’ to the import list in the import of ‘([^’]*)’ *\\((.*)\\)\\." #endif = suggestions hsmodImports binding mod srcspan | Just (binding, mod_srcspan) <- diff --git a/plugins/hls-refactor-plugin/test/Main.hs b/plugins/hls-refactor-plugin/test/Main.hs index 7ab1d80c76..a355af89ac 100644 --- a/plugins/hls-refactor-plugin/test/Main.hs +++ b/plugins/hls-refactor-plugin/test/Main.hs @@ -1275,6 +1275,20 @@ extendImportTests = testGroup "extend import actions" , "b :: A" , "b = ConstructorFoo" ]) + , testSession "extend single line import in presence of extra perens" $ template + [] + ("Main.hs", T.unlines + [ "import Data.Monoid (First)" + , "f = (First Nothing) <> mempty" -- parens tripped up the regex extracting import suggestions + ]) + (Range (Position 1 6) (Position 1 7)) + [ "Add First(..) to the import list of Data.Monoid" + , "Add First(First) to the import list of Data.Monoid" + ] + (T.unlines + [ "import Data.Monoid (First (..))" + , "f = (First Nothing) <> mempty" + ]) , brokenForGHC94 "On GHC 9.4, the error messages with -fdefer-type-errors don't have necessary imported target srcspan info." $ testSession "extend single line qualified import with value" $ template [("ModuleA.hs", T.unlines From 2c058490f7f794748dc5f2260cd1be891f26980a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Hr=C4=8Dek?= Date: Sat, 17 Feb 2024 06:28:40 +0100 Subject: [PATCH 2/2] Mark it broken on ghc 9.2 --- plugins/hls-refactor-plugin/test/Main.hs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/hls-refactor-plugin/test/Main.hs b/plugins/hls-refactor-plugin/test/Main.hs index a355af89ac..58926b0ab0 100644 --- a/plugins/hls-refactor-plugin/test/Main.hs +++ b/plugins/hls-refactor-plugin/test/Main.hs @@ -1275,7 +1275,8 @@ extendImportTests = testGroup "extend import actions" , "b :: A" , "b = ConstructorFoo" ]) - , testSession "extend single line import in presence of extra perens" $ template + , brokenForGHC92 "On GHC 9.2, the error doesn't contain \"perhaps you want ...\" part from which import suggestion can be extracted." $ + testSession "extend single line import in presence of extra parens" $ template [] ("Main.hs", T.unlines [ "import Data.Monoid (First)" @@ -3749,3 +3750,6 @@ withTempDir f = System.IO.Extra.withTempDir $ \dir -> brokenForGHC94 :: String -> TestTree -> TestTree brokenForGHC94 = knownBrokenForGhcVersions [GHC94] + +brokenForGHC92 :: String -> TestTree -> TestTree +brokenForGHC92 = knownBrokenForGhcVersions [GHC92]