diff --git a/plugins/hls-class-plugin/src/Ide/Plugin/Class.hs b/plugins/hls-class-plugin/src/Ide/Plugin/Class.hs index 9ffaaa30c7..d4915387eb 100644 --- a/plugins/hls-class-plugin/src/Ide/Plugin/Class.hs +++ b/plugins/hls-class-plugin/src/Ide/Plugin/Class.hs @@ -119,7 +119,7 @@ addMethodPlaceholders lf state AddMinimalMethodsParams{..} = fmap (fromMaybe err toMethodName n | Just (h, _) <- T.uncons n - , not (isAlpha h) + , not (isAlpha h || h == '_') = "(" <> n <> ")" | otherwise = n diff --git a/test/functional/Class.hs b/test/functional/Class.hs index 777071c485..e02a0440ad 100644 --- a/test/functional/Class.hs +++ b/test/functional/Class.hs @@ -48,6 +48,9 @@ tests = testGroup , glodenTest "Creates a placeholder for multiple methods 2" "T3" "2" $ \(_:mmAction:_) -> do executeCodeAction mmAction + , glodenTest "Creates a placeholder for a method starting with '_'" "T4" "" + $ \(_fAction:_) -> do + executeCodeAction _fAction ] _CACodeAction :: Prism' CAResult CodeAction @@ -60,7 +63,7 @@ classPath = "test" "testdata" "class" glodenTest :: String -> FilePath -> FilePath -> ([CodeAction] -> Session ()) -> TestTree glodenTest name fp deco execute - = goldenVsStringDiff name goldenGitDiff (classPath fp <.> deco <.> "expected" <.> "hs") + = goldenVsStringDiff name goldenGitDiff (classPath fpWithDeco <.> "expected" <.> "hs") $ runSession hlsCommand fullCaps classPath $ do doc <- openDoc (fp <.> "hs") "haskell" @@ -68,6 +71,10 @@ glodenTest name fp deco execute actions <- concatMap (^.. _CACodeAction) <$> getAllCodeActions doc execute actions BS.fromStrict . T.encodeUtf8 <$> getDocumentEdit doc + where + fpWithDeco + | deco == "" = fp + | otherwise = fp <.> deco goldenGitDiff :: FilePath -> FilePath -> [String] goldenGitDiff fRef fNew = ["git", "diff", "--no-index", "--text", "--exit-code", fRef, fNew] diff --git a/test/testdata/class/T4.expected.hs b/test/testdata/class/T4.expected.hs new file mode 100644 index 0000000000..8f3c2545d8 --- /dev/null +++ b/test/testdata/class/T4.expected.hs @@ -0,0 +1,8 @@ +module T4 where + +class Test a where + _f :: a + {-# MINIMAL _f #-} + +instance Test Int where + _f = _ diff --git a/test/testdata/class/T4.hs b/test/testdata/class/T4.hs new file mode 100644 index 0000000000..f5aeb3ca47 --- /dev/null +++ b/test/testdata/class/T4.hs @@ -0,0 +1,7 @@ +module T4 where + +class Test a where + _f :: a + {-# MINIMAL _f #-} + +instance Test Int where