@@ -9,6 +9,7 @@ import Control.Monad.IO.Class (liftIO)
9
9
import qualified Data.Aeson as A
10
10
import Data.Bool (bool )
11
11
import Data.List (isSuffixOf )
12
+ import Data.Maybe (fromMaybe )
12
13
import Data.Proxy (Proxy (.. ))
13
14
import Language.LSP.Protocol.Message (TCustomMessage (NotMess ),
14
15
TNotificationMessage (.. ))
@@ -31,6 +32,7 @@ tests :: TestTree
31
32
tests =
32
33
testGroup " gotoDefinition for dependencies"
33
34
[ dependencyTest
35
+ , transitiveDependencyTest
34
36
]
35
37
36
38
fileDoneIndexing :: [String ] -> Session FilePath
@@ -71,3 +73,49 @@ dependencyTest = testSessionWithExtraFiles "dependency" "gotoDefinition in async
71
73
liftIO $
72
74
assertFailure $ " Wrong location for AsyncCancelled: "
73
75
++ show wrongLocation
76
+
77
+ -- Tests that we can go to the definition of a dependency, and then
78
+ -- from the dependency file we can use gotoDefinition to see a
79
+ -- tranisive dependency.
80
+ transitiveDependencyTest :: TestTree
81
+ transitiveDependencyTest = testSessionWithExtraFiles " dependency" " goto transitive dependency async -> hashable" $
82
+ \ dir -> do
83
+ localDoc <- openDoc (dir </> " Dependency" <.> " hs" ) " haskell"
84
+ _asyncHieFile <- fileDoneIndexing [" Control" , " Concurrent" , " Async.hie" ]
85
+ _hashableHieFile <- fileDoneIndexing [" Data" , " Hashable" , " Class.hie" ]
86
+ asyncDefs <- getDefinitions localDoc (Position 5 20 )
87
+ asyncHsFile <- case asyncDefs of
88
+ InL (Definition (InR [Location uri _actualRange])) ->
89
+ liftIO $ do
90
+ let fp :: FilePath
91
+ fp = fromMaybe " " $ uriToFilePath uri
92
+ locationDirectories :: [String ]
93
+ locationDirectories = splitDirectories fp
94
+ assertBool " AsyncCancelled found in a module that is not Control.Concurrent Async"
95
+ $ [" Control" , " Concurrent" , " Async.hs" ]
96
+ `isSuffixOf` locationDirectories
97
+ pure fp
98
+ wrongLocation ->
99
+ liftIO $
100
+ assertFailure $ " Wrong location for AsyncCancelled: "
101
+ ++ show wrongLocation
102
+ asyncDoc <- openDoc asyncHsFile " haskell"
103
+ hashableDefs <- getDefinitions asyncDoc (Position 246 11 )
104
+ -- The location of the definition of Hashable in
105
+ -- Data.Hashable.Class
106
+ let expRange = Range (Position 198 14 ) (Position 198 22 )
107
+ case hashableDefs of
108
+ InL (Definition (InR [Location uri actualRange])) ->
109
+ liftIO $ do
110
+ let locationDirectories :: [String ]
111
+ locationDirectories =
112
+ maybe [] splitDirectories $
113
+ uriToFilePath uri
114
+ assertBool " Hashable found in a module that is not Data.Hashable.Class"
115
+ $ [" Data" , " Hashable" , " Class.hs" ]
116
+ `isSuffixOf` locationDirectories
117
+ actualRange @?= expRange
118
+ wrongLocation ->
119
+ liftIO $
120
+ assertFailure $ " Wrong location for Hashable: "
121
+ ++ show wrongLocation
0 commit comments