Skip to content

Commit 89a0793

Browse files
committed
Add gotoDefinition other file tests
1 parent c501f38 commit 89a0793

File tree

4 files changed

+43
-4
lines changed

4 files changed

+43
-4
lines changed

test/functional/Definition.hs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,43 @@ import Test.Hls
77
import Test.Hls.Command
88

99
tests :: TestTree
10-
tests = testGroup "definitions" [
10+
tests = testGroup "definitions" [symbolTests, moduleTests]
1111

12-
ignoreTestBecause "Broken: file:///Users/jwindsor/src/haskell-language-server/test/testdata/References.hs" $
13-
testCase "goto's symbols" $ runSession hlsCommand fullCaps "test/testdata" $ do
12+
symbolTests :: TestTree
13+
symbolTests = testGroup "gotoDefinition on symbols"
14+
-- gotoDefinition where the definition is in the same file
15+
[ testCase "gotoDefinition in this file" $ runSession hlsCommand fullCaps "test/testdata" $ do
1416
doc <- openDoc "References.hs" "haskell"
1517
defs <- getDefinitions doc (Position 7 8)
1618
let expRange = Range (Position 4 0) (Position 4 3)
1719
liftIO $ defs @?= InL (Definition (InR [Location (doc ^. uri) expRange]))
1820

21+
-- gotoDefinition where the definition is in a different file
22+
, testCase "gotoDefinition in other file" $ runSession hlsCommand fullCaps "test/testdata/definition" $ do
23+
doc <- openDoc "Foo.hs" "haskell"
24+
defs <- getDefinitions doc (Position 4 11)
25+
let expRange = Range (Position 2 0) (Position 2 1)
26+
liftIO $ do
27+
fp <- canonicalizePath "test/testdata/definition/Bar.hs"
28+
defs @?= InL (Definition (InR [Location (filePathToUri fp) expRange]))
29+
30+
-- gotoDefinition where the definition is in a different file and the
31+
-- definition in the other file is on a line number that is greater
32+
-- than the number of lines in the file we are requesting from
33+
, testCase "gotoDefinition in other file past lines in this file" $ runSession hlsCommand fullCaps "test/testdata/definition" $ do
34+
doc <- openDoc "Foo.hs" "haskell"
35+
defs <- getDefinitions doc (Position 5 13)
36+
let expRange = Range (Position 8 0) (Position 8 1)
37+
liftIO $ do
38+
fp <- canonicalizePath "test/testdata/definition/Bar.hs"
39+
defs @?= InL (Definition (InR [Location (filePathToUri fp) expRange]))
40+
]
41+
1942
-- -----------------------------------
2043

21-
, ignoreTestBecause "Broken: file:///Users/jwindsor/src/haskell-language-server/test/testdata/Bar.hs" $
44+
moduleTests :: TestTree
45+
moduleTests = testGroup "gotoDefinition on modules"
46+
[ ignoreTestBecause "Broken: file:///Users/jwindsor/src/haskell-language-server/test/testdata/Bar.hs" $
2247
testCase "goto's imported modules" $ runSession hlsCommand fullCaps "test/testdata/definition" $ do
2348
doc <- openDoc "Foo.hs" "haskell"
2449
defs <- getDefinitions doc (Position 2 8)

test/testdata/definition/Bar.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
module Bar where
22

33
a = 42
4+
5+
-- These blank lines are here
6+
-- to ensure that b is defined
7+
-- on a line number larger than
8+
-- the number of lines in Foo.hs.
9+
b = 43

test/testdata/definition/Foo.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
module Foo (module Bar) where
22

33
import Bar
4+
5+
fortyTwo = a
6+
fortyThree = b

test/testdata/definition/hie.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
cradle:
2+
direct:
3+
arguments:
4+
- "Foo"
5+
- "Bar"

0 commit comments

Comments
 (0)