Skip to content

Commit bf642c0

Browse files
authored
Merge pull request #1170 from Ailrun/fix-class-plugin
Fix toMethodName bug of the Class plugin
2 parents 6c93300 + d4e666a commit bf642c0

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

plugins/hls-class-plugin/src/Ide/Plugin/Class.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ addMethodPlaceholders lf state AddMinimalMethodsParams{..} = fmap (fromMaybe err
119119

120120
toMethodName n
121121
| Just (h, _) <- T.uncons n
122-
, not (isAlpha h)
122+
, not (isAlpha h || h == '_')
123123
= "(" <> n <> ")"
124124
| otherwise
125125
= n

test/functional/Class.hs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ tests = testGroup
4848
, glodenTest "Creates a placeholder for multiple methods 2" "T3" "2"
4949
$ \(_:mmAction:_) -> do
5050
executeCodeAction mmAction
51+
, glodenTest "Creates a placeholder for a method starting with '_'" "T4" ""
52+
$ \(_fAction:_) -> do
53+
executeCodeAction _fAction
5154
]
5255

5356
_CACodeAction :: Prism' CAResult CodeAction
@@ -60,14 +63,18 @@ classPath = "test" </> "testdata" </> "class"
6063

6164
glodenTest :: String -> FilePath -> FilePath -> ([CodeAction] -> Session ()) -> TestTree
6265
glodenTest name fp deco execute
63-
= goldenVsStringDiff name goldenGitDiff (classPath </> fp <.> deco <.> "expected" <.> "hs")
66+
= goldenVsStringDiff name goldenGitDiff (classPath </> fpWithDeco <.> "expected" <.> "hs")
6467
$ runSession hlsCommand fullCaps classPath
6568
$ do
6669
doc <- openDoc (fp <.> "hs") "haskell"
6770
_ <- waitForDiagnosticsFromSource doc "typecheck"
6871
actions <- concatMap (^.. _CACodeAction) <$> getAllCodeActions doc
6972
execute actions
7073
BS.fromStrict . T.encodeUtf8 <$> getDocumentEdit doc
74+
where
75+
fpWithDeco
76+
| deco == "" = fp
77+
| otherwise = fp <.> deco
7178

7279
goldenGitDiff :: FilePath -> FilePath -> [String]
7380
goldenGitDiff fRef fNew = ["git", "diff", "--no-index", "--text", "--exit-code", fRef, fNew]

test/testdata/class/T4.expected.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module T4 where
2+
3+
class Test a where
4+
_f :: a
5+
{-# MINIMAL _f #-}
6+
7+
instance Test Int where
8+
_f = _

test/testdata/class/T4.hs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module T4 where
2+
3+
class Test a where
4+
_f :: a
5+
{-# MINIMAL _f #-}
6+
7+
instance Test Int where

0 commit comments

Comments
 (0)