1
+ {-# LANGUAGE ExplicitNamespaces #-}
2
+ {-# LANGUAGE OverloadedStrings #-}
3
+ {-# LANGUAGE ViewPatterns #-}
1
4
2
5
module FindDefinitionAndHoverTests (tests ) where
3
6
4
7
import Control.Monad
5
- import Control.Monad.IO.Class (liftIO )
6
8
import Data.Foldable
7
9
import 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
20
12
import Language.LSP.Test
21
- import System.FilePath
22
- import System.Info.Extra (isWindows )
13
+ import System.Info.Extra (isWindows )
23
14
24
- import Control.Lens ((^.) )
15
+ import Control.Lens ((^.) )
25
16
import Test.Tasty
26
17
import 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 ((=~) )
29
29
30
30
tests :: TestTree
31
31
tests = let
32
-
33
32
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
43
40
44
- doc <- openTestDataDoc (dir </> sfp)
45
- waitForProgressDone
46
- found <- get doc pos
47
- check found targetRange
48
41
49
42
50
-
51
- checkHover :: Maybe Hover -> Session [Expect ] -> Session ()
43
+ checkHover :: (HasCallStack ) => Maybe Hover -> Session [Expect ] -> Session ()
52
44
checkHover hover expectations = traverse_ check =<< expectations where
53
45
46
+ check :: (HasCallStack ) => Expect -> Session ()
54
47
check expected =
55
48
case hover of
56
49
Nothing -> unless (expected == ExpectNoHover ) $ liftIO $ assertFailure " no hover found"
@@ -100,11 +93,11 @@ tests = let
100
93
mkFindTests tests = testGroup " get"
101
94
[ testGroup " definition" $ mapMaybe fst tests
102
95
, testGroup " hover" $ mapMaybe snd tests
103
- , checkFileCompiles sourceFilePath $
96
+ , testGroup " hover compile " [ checkFileCompiles sourceFilePath $
104
97
expectDiagnostics
105
98
[ ( " GotoHover.hs" , [(DiagnosticSeverity_Error , (62 , 7 ), " Found hole: _" )])
106
99
, ( " GotoHover.hs" , [(DiagnosticSeverity_Error , (65 , 8 ), " Found hole: _" )])
107
- ]
100
+ ]]
108
101
, testGroup " type-definition" typeDefinitionTests
109
102
, testGroup " hover-record-dot-syntax" recordDotSyntaxTests ]
110
103
@@ -117,8 +110,15 @@ tests = let
117
110
, tst (getHover, checkHover) (Position 17 26 ) (T. unpack " RecordDotSyntax.hs" ) (pure [ExpectHoverText [" _ :: MyChild" ]]) " hover over child"
118
111
]
119
112
113
+ test :: (HasCallStack ) => (TestTree -> a ) -> (TestTree -> b ) -> Position -> [Expect ] -> String -> (a , b )
120
114
test runDef runHover look expect = testM runDef runHover look (return expect)
121
115
116
+ testM :: (HasCallStack ) => (TestTree -> a )
117
+ -> (TestTree -> b )
118
+ -> Position
119
+ -> Session [Expect ]
120
+ -> String
121
+ -> (a , b )
122
122
testM runDef runHover look expect title =
123
123
( runDef $ tst def look sourceFilePath expect title
124
124
, runHover $ tst hover look sourceFilePath expect title ) where
@@ -228,8 +228,11 @@ tests = let
228
228
no = const Nothing -- don't run this test at all
229
229
-- skip = const Nothing -- unreliable, don't run
230
230
231
+ xfail :: TestTree -> String -> TestTree
232
+ xfail = flip expectFailBecause
233
+
231
234
checkFileCompiles :: FilePath -> Session () -> TestTree
232
235
checkFileCompiles 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 "
235
238
diag
0 commit comments