Skip to content

Commit b7c4274

Browse files
authored
Record Dot Hover Types (#3016)
* patch hieast * add comments * add hlint ignore * update readme * add tests
1 parent 2e2b3f1 commit b7c4274

File tree

7 files changed

+2188
-12
lines changed

7 files changed

+2188
-12
lines changed
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{-# LANGUAGE CPP #-}
2+
#if __GLASGOW_HASKELL__ >= 902
3+
{-# LANGUAGE OverloadedRecordDot, DuplicateRecordFields, NoFieldSelectors #-}
4+
5+
module RecordDotSyntax ( module RecordDotSyntax) where
6+
7+
import qualified Data.Maybe as M
8+
9+
data MyRecord = MyRecord
10+
{ a :: String
11+
, b :: Integer
12+
, c :: MyChild
13+
} deriving (Eq, Show)
14+
15+
newtype MyChild = MyChild
16+
{ z :: String
17+
} deriving (Eq, Show)
18+
19+
x = MyRecord { a = "Hello", b = 12, c = MyChild { z = "there" } }
20+
y = x.a ++ show x.b ++ x.c.z
21+
#endif

ghcide/test/data/hover/hie.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
cradle: {direct: {arguments: ["Foo", "Bar", "GotoHover"]}}
1+
cradle: {direct: {arguments: ["Foo", "Bar", "GotoHover", "RecordDotSyntax"]}}

ghcide/test/exe/Main.hs

+18-9
Original file line numberDiff line numberDiff line change
@@ -4283,8 +4283,8 @@ canonicalizeLocation (Location uri range) = Location <$> canonicalizeUri uri <*>
42834283
findDefinitionAndHoverTests :: TestTree
42844284
findDefinitionAndHoverTests = let
42854285

4286-
tst :: (TextDocumentIdentifier -> Position -> Session a, a -> Session [Expect] -> Session ()) -> Position -> Session [Expect] -> String -> TestTree
4287-
tst (get, check) pos targetRange title = testSessionWithExtraFiles "hover" title $ \dir -> do
4286+
tst :: (TextDocumentIdentifier -> Position -> Session a, a -> Session [Expect] -> Session ()) -> Position -> String -> Session [Expect] -> String -> TestTree
4287+
tst (get, check) pos sfp targetRange title = testSessionWithExtraFiles "hover" title $ \dir -> do
42884288

42894289
-- Dirty the cache to check that definitions work even in the presence of iface files
42904290
liftIO $ runInDir dir $ do
@@ -4294,7 +4294,7 @@ findDefinitionAndHoverTests = let
42944294
_ <- getHover fooDoc $ Position 4 3
42954295
closeDoc fooDoc
42964296

4297-
doc <- openTestDataDoc (dir </> sourceFilePath)
4297+
doc <- openTestDataDoc (dir </> sfp)
42984298
waitForProgressDone
42994299
found <- get doc pos
43004300
check found targetRange
@@ -4352,16 +4352,25 @@ findDefinitionAndHoverTests = let
43524352
[ ( "GotoHover.hs", [(DsError, (62, 7), "Found hole: _")])
43534353
, ( "GotoHover.hs", [(DsError, (65, 8), "Found hole: _")])
43544354
]
4355-
, testGroup "type-definition" typeDefinitionTests ]
4356-
4357-
typeDefinitionTests = [ tst (getTypeDefinitions, checkDefs) aaaL14 (pure tcData) "Saturated data con"
4358-
, tst (getTypeDefinitions, checkDefs) aL20 (pure [ExpectNoDefinitions]) "Polymorphic variable"]
4355+
, testGroup "type-definition" typeDefinitionTests
4356+
, testGroup "hover-record-dot-syntax" recordDotSyntaxTests ]
4357+
4358+
typeDefinitionTests = [ tst (getTypeDefinitions, checkDefs) aaaL14 sourceFilePath (pure tcData) "Saturated data con"
4359+
, tst (getTypeDefinitions, checkDefs) aL20 sourceFilePath (pure [ExpectNoDefinitions]) "Polymorphic variable"]
4360+
4361+
recordDotSyntaxTests
4362+
| ghcVersion == GHC92 =
4363+
[ tst (getHover, checkHover) (Position 19 24) (T.unpack "RecordDotSyntax.hs") (pure [ExpectHoverText ["x :: MyRecord"]]) "hover over parent"
4364+
, tst (getHover, checkHover) (Position 19 25) (T.unpack "RecordDotSyntax.hs") (pure [ExpectHoverText ["_ :: MyChild"]]) "hover over dot shows child"
4365+
, tst (getHover, checkHover) (Position 19 26) (T.unpack "RecordDotSyntax.hs") (pure [ExpectHoverText ["_ :: MyChild"]]) "hover over child"
4366+
]
4367+
| otherwise = []
43594368

43604369
test runDef runHover look expect = testM runDef runHover look (return expect)
43614370

43624371
testM runDef runHover look expect title =
4363-
( runDef $ tst def look expect title
4364-
, runHover $ tst hover look expect title ) where
4372+
( runDef $ tst def look sourceFilePath expect title
4373+
, runHover $ tst hover look sourceFilePath expect title ) where
43654374
def = (getDefinitions, checkDefs)
43664375
hover = (getHover , checkHover)
43674376

hie-compat/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@ Mainly a backport of [HIE
44
Files](https://gitlab.haskell.org/ghc/ghc/-/wikis/hie-files) for ghc 8.6, along
55
with a few other backports of fixes useful for `ghcide`
66

7+
Also includes backport of record-dot-syntax support to 9.2.x
8+
79
Fully compatible with `.hie` files natively produced by versions of GHC that support
810
them.
911

1012
**THIS DOES NOT LET YOU READ HIE FILES WITH MISMATCHED VERSIONS OF GHC**
1113

1214
Backports included:
1315

16+
https://gitlab.haskell.org/ghc/ghc/-/merge_requests/8589
17+
1418
https://gitlab.haskell.org/ghc/ghc/-/merge_requests/4037
1519

1620
https://gitlab.haskell.org/ghc/ghc/-/merge_requests/4068

hie-compat/hie-compat.cabal

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@ library
4747
if (impl(ghc > 8.9) && impl(ghc < 8.11))
4848
hs-source-dirs: src-ghc810 src-reexport
4949
if (impl(ghc >= 9.0) && impl(ghc < 9.1) || flag(ghc-lib))
50-
hs-source-dirs: src-reexport-ghc9
50+
hs-source-dirs: src-ghc90 src-reexport-ghc9
5151
if (impl(ghc >= 9.2) && impl(ghc < 9.3))
52-
hs-source-dirs: src-reexport-ghc9
52+
hs-source-dirs: src-ghc92 src-reexport-ghc9

0 commit comments

Comments
 (0)