Skip to content

Commit

Permalink
Merge pull request #1170 from Ailrun/fix-class-plugin
Browse files Browse the repository at this point in the history
Fix toMethodName bug of the Class plugin
  • Loading branch information
Ailrun committed Jan 8, 2021
2 parents 6c93300 + d4e666a commit bf642c0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion plugins/hls-class-plugin/src/Ide/Plugin/Class.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion test/functional/Class.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -60,14 +63,18 @@ 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"
_ <- waitForDiagnosticsFromSource doc "typecheck"
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]
8 changes: 8 additions & 0 deletions test/testdata/class/T4.expected.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module T4 where

class Test a where
_f :: a
{-# MINIMAL _f #-}

instance Test Int where
_f = _
7 changes: 7 additions & 0 deletions test/testdata/class/T4.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module T4 where

class Test a where
_f :: a
{-# MINIMAL _f #-}

instance Test Int where

0 comments on commit bf642c0

Please sign in to comment.