@@ -32,7 +32,8 @@ import TestUtils (testSessionWithExtraFiles, kno
32
32
tests :: TestTree
33
33
tests =
34
34
testGroup " gotoDefinition for dependencies"
35
- [ dependencyTest
35
+ [ dependencyTermTest
36
+ , dependencyTypeTest
36
37
, transitiveDependencyTest
37
38
, autogenDependencyTest
38
39
]
@@ -53,8 +54,11 @@ fileDoneIndexing fpSuffix =
53
54
fpSuffix `isSuffixOf` fpDirs
54
55
other -> error $ " Failed to parse ghcide/reference/ready file: " <> show other
55
56
56
- dependencyTest :: TestTree
57
- dependencyTest = testSessionWithExtraFiles " dependency" " gotoDefinition in async" $
57
+ -- Tests that we can go to the definition of a term in a dependency.
58
+ -- In this case, we are getting the definition of the data
59
+ -- constructor AsyncCancelled.
60
+ dependencyTermTest :: TestTree
61
+ dependencyTermTest = testSessionWithExtraFiles " dependency" " gotoDefinition term in async" $
58
62
\ dir -> do
59
63
doc <- openDoc (dir </> " Dependency" <.> " hs" ) " haskell"
60
64
_hieFile <- fileDoneIndexing [" Control" , " Concurrent" , " Async.hie" ]
@@ -76,6 +80,31 @@ dependencyTest = testSessionWithExtraFiles "dependency" "gotoDefinition in async
76
80
assertFailure $ " Wrong location for AsyncCancelled: "
77
81
++ show wrongLocation
78
82
83
+ -- Tests that we can go to the definition of a type in a dependency.
84
+ -- In this case, we are getting the definition of the type AsyncCancelled.
85
+ dependencyTypeTest :: TestTree
86
+ dependencyTypeTest = testSessionWithExtraFiles " dependency" " gotoDefinition type in async" $
87
+ \ dir -> do
88
+ doc <- openDoc (dir </> " Dependency" <.> " hs" ) " haskell"
89
+ _hieFile <- fileDoneIndexing [" Control" , " Concurrent" , " Async.hie" ]
90
+ defs <- getDefinitions doc (Position 4 21 )
91
+ let expRange = Range (Position 430 0 ) (Position 435 5 )
92
+ case defs of
93
+ InL (Definition (InR [Location fp actualRange])) ->
94
+ liftIO $ do
95
+ let locationDirectories :: [String ]
96
+ locationDirectories =
97
+ maybe [] splitDirectories $
98
+ uriToFilePath fp
99
+ assertBool " AsyncCancelled found in a module that is not Control.Concurrent Async"
100
+ $ [" Control" , " Concurrent" , " Async.hs" ]
101
+ `isSuffixOf` locationDirectories
102
+ actualRange @?= expRange
103
+ wrongLocation ->
104
+ liftIO $
105
+ assertFailure $ " Wrong location for AsyncCancelled: "
106
+ ++ show wrongLocation
107
+
79
108
-- Tests that we can go to the definition of a dependency, and then
80
109
-- from the dependency file we can use gotoDefinition to see a
81
110
-- tranisive dependency.
0 commit comments