Skip to content

Commit 10d3554

Browse files
authored
Improve incoming call for typeclass and type family instance (#2162)
* Correct instance for incoming * Get rid of constant delay
1 parent 10a0edb commit 10d3554

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

plugins/hls-call-hierarchy-plugin/src/Ide/Plugin/CallHierarchy/Internal.hs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ module Ide.Plugin.CallHierarchy.Internal (
1212
, outgoingCalls
1313
) where
1414

15-
import Control.Concurrent
1615
import Control.Lens ((^.))
1716
import Control.Monad.Extra
1817
import Control.Monad.IO.Class
@@ -31,6 +30,7 @@ import Development.IDE.Core.Compile
3130
import Development.IDE.Core.Shake
3231
import Development.IDE.GHC.Compat as Compat
3332
import Development.IDE.Spans.AtPoint
33+
import GHC.Conc.Sync
3434
import HieDb (Symbol (Symbol))
3535
import qualified Ide.Plugin.CallHierarchy.Query as Q
3636
import Ide.Plugin.CallHierarchy.Types
@@ -318,7 +318,12 @@ refreshHieDb = do
318318
liftIO $ writeAndIndexHieFile hsc se msum f exports asts source
319319
pure ()
320320
)
321-
liftIO $ threadDelay 100000 -- delay 0.1 sec to make more exact results.
321+
ShakeExtras{hiedbWriter} <- getShakeExtras
322+
liftIO $ atomically $ check $ indexPending hiedbWriter
323+
where
324+
check p = do
325+
v <- readTVar p
326+
if HM.null v then pure () else retry
322327

323328
-- Copy unexport function form `ghcide/src/Development/IDE/Core/Rules.hs`
324329
getSourceFileSource :: NormalizedFilePath -> Action BS.ByteString

plugins/hls-call-hierarchy-plugin/src/Ide/Plugin/CallHierarchy/Query.hs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ incomingCalls (getConn -> conn) symbol = do
2121
let (o, m, u) = parseSymbol symbol
2222
query conn
2323
(Query $ T.pack $ concat
24-
[ "SELECT mods.mod, defs.occ, mods.hs_src, defs.sl, defs.sc, "
25-
, "defs.el, defs.ec, refs.sl, refs.sc, refs.el, refs.ec "
24+
[ "SELECT mods.mod, decls.occ, mods.hs_src, decls.sl, decls.sc, "
25+
, "decls.el, decls.ec, refs.sl, refs.sc, refs.el, refs.ec "
2626
, "FROM refs "
2727
, "JOIN decls ON decls.hieFile = refs.hieFile "
28-
, "JOIN defs ON defs.hieFile = decls.hieFile AND defs.occ = decls.occ "
2928
, "JOIN mods ON mods.hieFile = decls.hieFile "
3029
, "where "
3130
, "(refs.occ = ? AND refs.mod = ? AND refs.unit = ?) "

plugins/hls-call-hierarchy-plugin/test/Main.hs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,14 +254,24 @@ incomingCallsTests =
254254
positions = [(0, 6)]
255255
ranges = [mkRange 0 16 0 17]
256256
incomingCallTestCase contents 1 20 positions ranges
257+
, testCase "goto typeclass instance" $ do
258+
let contents = T.unlines
259+
[ "class F a where f :: a"
260+
, "instance F Bool where f = x"
261+
, "instance F Int where f = 3"
262+
, "x = True"
263+
]
264+
positions = [(1, 22)]
265+
ranges = [mkRange 1 26 1 27]
266+
incomingCallTestCase contents 3 0 positions ranges
257267
]
258268
, testCase "type family instance" $ do
259269
let contents = T.unlines
260270
[ "{-# LANGUAGE TypeFamilies #-}"
261271
, "type family A a"
262272
, "type instance A Int = Char"
263273
]
264-
positions = [(1, 12)]
274+
positions = [(2, 14)]
265275
ranges = [mkRange 2 22 2 26]
266276
incomingCallTestCase contents 2 22 positions ranges
267277
, testCase "GADT" $ do

0 commit comments

Comments
 (0)