Skip to content

Commit

Permalink
Add gotoDefinition other file tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nlander committed Jul 21, 2023
1 parent f20562f commit 4b4f8a7
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
33 changes: 29 additions & 4 deletions test/functional/Definition.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,43 @@ import Test.Hls
import Test.Hls.Command

tests :: TestTree
tests = testGroup "definitions" [
tests = testGroup "definitions" [symbolTests, moduleTests]

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

-- gotoDefinition where the definition is in a different file
, testCase "gotoDefinition in other file" $ runSession hlsCommand fullCaps "test/testdata/definition" $ do
doc <- openDoc "Foo.hs" "haskell"
defs <- getDefinitions doc (Position 4 11)
let expRange = Range (Position 2 0) (Position 2 1)
liftIO $ do
fp <- canonicalizePath "test/testdata/definition/Bar.hs"
defs @?= InL (Definition (InR [Location (filePathToUri fp) expRange]))

-- gotoDefinition where the definition is in a different file and the
-- definition in the other file is on a line number that is greater
-- than the number of lines in the file we are requesting from
, testCase "gotoDefinition in other file past lines in this file" $ runSession hlsCommand fullCaps "test/testdata/definition" $ do
doc <- openDoc "Foo.hs" "haskell"
defs <- getDefinitions doc (Position 5 13)
let expRange = Range (Position 8 0) (Position 8 1)
liftIO $ do
fp <- canonicalizePath "test/testdata/definition/Bar.hs"
defs @?= InL (Definition (InR [Location (filePathToUri fp) expRange]))
]

-- -----------------------------------

, ignoreTestBecause "Broken: file:///Users/jwindsor/src/haskell-language-server/test/testdata/Bar.hs" $
moduleTests :: TestTree
moduleTests = testGroup "gotoDefinition on modules"
[ ignoreTestBecause "Broken: file:///Users/jwindsor/src/haskell-language-server/test/testdata/Bar.hs" $
testCase "goto's imported modules" $ runSession hlsCommand fullCaps "test/testdata/definition" $ do
doc <- openDoc "Foo.hs" "haskell"
defs <- getDefinitions doc (Position 2 8)
Expand Down
6 changes: 6 additions & 0 deletions test/testdata/definition/Bar.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
module Bar where

a = 42

-- These blank lines are here
-- to ensure that b is defined
-- on a line number larger than
-- the number of lines in Foo.hs.
b = 43
3 changes: 3 additions & 0 deletions test/testdata/definition/Foo.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
module Foo (module Bar) where

import Bar

fortyTwo = a
fortyThree = b
5 changes: 5 additions & 0 deletions test/testdata/definition/hie.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cradle:
direct:
arguments:
- "Foo"
- "Bar"

0 comments on commit 4b4f8a7

Please sign in to comment.