1+ {-# LANGUAGE ExplicitNamespaces #-}
2+ {-# LANGUAGE OverloadedStrings #-}
3+ {-# LANGUAGE ViewPatterns #-}
14
25module FindDefinitionAndHoverTests (tests ) where
36
47import Control.Monad
5- import Control.Monad.IO.Class (liftIO )
68import Data.Foldable
79import Data.Maybe
8- import qualified Data.Text as T
9- import Development.IDE.GHC.Compat (GhcVersion (.. ), ghcVersion )
10- import Development.IDE.GHC.Util
11- import Development.IDE.Test (expectDiagnostics ,
12- standardizeQuotes )
13- import Development.IDE.Types.Location
14- import qualified Language.LSP.Protocol.Lens as L
15- import Language.LSP.Protocol.Types hiding
16- (SemanticTokenAbsolute (.. ),
17- SemanticTokenRelative (.. ),
18- SemanticTokensEdit (.. ),
19- mkRange )
10+ import qualified Data.Text as T
11+ import qualified Language.LSP.Protocol.Lens as L
2012import Language.LSP.Test
21- import System.FilePath
22- import System.Info.Extra (isWindows )
13+ import System.Info.Extra (isWindows )
2314
24- import Control.Lens ((^.) )
15+ import Control.Lens ((^.) )
2516import Test.Tasty
2617import Test.Tasty.HUnit
27- import TestUtils
28- import Text.Regex.TDFA ((=~) )
18+ -- import TestUtils
19+ import Config
20+ import Debug.Trace (traceM )
21+ import Development.IDE (readFileUtf8 )
22+ import Development.IDE.Test (expectDiagnostics ,
23+ standardizeQuotes )
24+ import System.Directory (copyFile )
25+ import System.FilePath ((</>) )
26+ import Test.Hls
27+ import Test.Hls.FileSystem (copy , copyDir , file , toAbsFp )
28+ import Text.Regex.TDFA ((=~) )
2929
3030tests :: TestTree
3131tests = let
32-
3332 tst :: (TextDocumentIdentifier -> Position -> Session a , a -> Session [Expect ] -> Session () ) -> Position -> String -> Session [Expect ] -> String -> TestTree
34- tst (get, check) pos sfp targetRange title = testSessionWithExtraFiles " hover" title $ \ dir -> do
35-
36- -- Dirty the cache to check that definitions work even in the presence of iface files
37- liftIO $ runInDir dir $ do
38- let fooPath = dir </> " Foo.hs"
39- fooSource <- liftIO $ readFileUtf8 fooPath
40- fooDoc <- createDoc fooPath " haskell" fooSource
41- _ <- getHover fooDoc $ Position 4 3
42- closeDoc fooDoc
33+ tst (get, check) pos sfp targetRange title =
34+ testWithDummyPlugin title (mkIdeTestFs [copyDir " hover" ]) $ do
35+ doc <- openDoc sfp " haskell"
36+ waitForProgressDone
37+ _x <- waitForTypecheck doc
38+ found <- get doc pos
39+ check found targetRange
4340
44- doc <- openTestDataDoc (dir </> sfp)
45- waitForProgressDone
46- found <- get doc pos
47- check found targetRange
4841
4942
50-
51- checkHover :: Maybe Hover -> Session [Expect ] -> Session ()
43+ checkHover :: (HasCallStack ) => Maybe Hover -> Session [Expect ] -> Session ()
5244 checkHover hover expectations = traverse_ check =<< expectations where
5345
46+ check :: (HasCallStack ) => Expect -> Session ()
5447 check expected =
5548 case hover of
5649 Nothing -> unless (expected == ExpectNoHover ) $ liftIO $ assertFailure " no hover found"
@@ -100,11 +93,11 @@ tests = let
10093 mkFindTests tests = testGroup " get"
10194 [ testGroup " definition" $ mapMaybe fst tests
10295 , testGroup " hover" $ mapMaybe snd tests
103- , checkFileCompiles sourceFilePath $
96+ , testGroup " hover compile " [ checkFileCompiles sourceFilePath $
10497 expectDiagnostics
10598 [ ( " GotoHover.hs" , [(DiagnosticSeverity_Error , (62 , 7 ), " Found hole: _" )])
10699 , ( " GotoHover.hs" , [(DiagnosticSeverity_Error , (65 , 8 ), " Found hole: _" )])
107- ]
100+ ]]
108101 , testGroup " type-definition" typeDefinitionTests
109102 , testGroup " hover-record-dot-syntax" recordDotSyntaxTests ]
110103
@@ -117,8 +110,15 @@ tests = let
117110 , tst (getHover, checkHover) (Position 17 26 ) (T. unpack " RecordDotSyntax.hs" ) (pure [ExpectHoverText [" _ :: MyChild" ]]) " hover over child"
118111 ]
119112
113+ test :: (HasCallStack ) => (TestTree -> a ) -> (TestTree -> b ) -> Position -> [Expect ] -> String -> (a , b )
120114 test runDef runHover look expect = testM runDef runHover look (return expect)
121115
116+ testM :: (HasCallStack ) => (TestTree -> a )
117+ -> (TestTree -> b )
118+ -> Position
119+ -> Session [Expect ]
120+ -> String
121+ -> (a , b )
122122 testM runDef runHover look expect title =
123123 ( runDef $ tst def look sourceFilePath expect title
124124 , runHover $ tst hover look sourceFilePath expect title ) where
@@ -228,8 +228,11 @@ tests = let
228228 no = const Nothing -- don't run this test at all
229229 -- skip = const Nothing -- unreliable, don't run
230230
231+ xfail :: TestTree -> String -> TestTree
232+ xfail = flip expectFailBecause
233+
231234checkFileCompiles :: FilePath -> Session () -> TestTree
232235checkFileCompiles fp diag =
233- testSessionWithExtraFiles " hover " (" Does " ++ fp ++ " compile" ) $ \ dir -> do
234- void (openTestDataDoc (dir </> fp))
236+ testWithDummyPlugin (" hover: Does " ++ fp ++ " compile" ) (mkIdeTestFs [copyDir " hover " ]) $ do
237+ _ <- openDoc fp " haskell "
235238 diag
0 commit comments