Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions ghcide-test/data/references/Fields.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{-# LANGUAGE RecordWildCards #-}
module Fields where

data Foo = MkFoo
{
barr :: String,
bazz :: String
}

fooUse0 :: Foo -> String
fooUse0 MkFoo{barr} = "5"

fooUse1 :: Foo -> String
fooUse1 MkFoo{..} = "6"

fooUse2 :: String -> String -> Foo
fooUse2 bar baz =
MkFoo{..}
5 changes: 4 additions & 1 deletion ghcide-test/data/references/Main.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Main where

import References

import Fields
main :: IO ()
main = return ()

Expand All @@ -12,3 +12,6 @@ b = a + 1

acc :: Account
acc = Savings

fooUse3 :: String -> String -> Foo
fooUse3 bar baz = MkFoo{barr = bar, bazz = baz}
2 changes: 1 addition & 1 deletion ghcide-test/data/references/hie.yaml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
cradle: {direct: {arguments: ["Main","OtherModule","OtherOtherModule","References"]}}
cradle: {direct: {arguments: ["Main","OtherModule","OtherOtherModule","References", "Fields"]}}
22 changes: 22 additions & 0 deletions ghcide-test/exe/ReferenceTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,28 @@ tests = testGroup "references"
, ("References.hs", 16, 0)
]
]
-- Fields.hs does not depend on Main.hs
-- so we can only find references in Fields.hs
, testGroup "references to record fields"
[ referenceTest "references record fields in the same file"
("Fields.hs", 5, 4)
YesIncludeDeclaration
[ ("Fields.hs", 5, 4)
, ("Fields.hs", 10, 14)
, ("Fields.hs", 13, 14)
]

-- Main.hs depends on Fields.hs, so we can find references
-- from Main.hs to Fields.hs
, referenceTest "references record fields cross modules"
("Main.hs", 16, 24)
YesIncludeDeclaration
[ ("Fields.hs", 5, 4)
, ("Fields.hs", 10, 14)
, ("Fields.hs", 13, 14)
, ("Main.hs", 16, 24)
]
]
]

-- | When we ask for all references to symbol "foo", should the declaration "foo
Expand Down
2 changes: 1 addition & 1 deletion ghcide/src/Development/IDE/Spans/AtPoint.hs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ foiReferencesAtPoint file pos (FOIReferences asts) =

getNamesAtPoint :: HieASTs a -> Position -> PositionMapping -> [Name]
getNamesAtPoint hf pos mapping =
concat $ pointCommand hf posFile (rights . M.keys . getNodeIds)
concat $ pointCommand hf posFile (rights . M.keys . getSourceNodeIds)
where
posFile = fromMaybe pos $ fromCurrentPosition mapping pos

Expand Down
Loading