Skip to content

Commit f63f18f

Browse files
committed
hls-class-plugin: Find methods even inside an EvidenceVarBind
1 parent 83c649e commit f63f18f

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

plugins/hls-class-plugin/src/Ide/Plugin/Class.hs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,13 +261,29 @@ codeAction recorder state plId (CodeActionParams _ _ docId _ context) = liftIO $
261261
$ pointCommand hf (fromJust (fromCurrentRange pmap range) ^. J.start & J.character -~ 1)
262262
$ map (T.pack . getOccString) . rights . findInstanceValBindIdentifiers
263263

264+
-- | Recurses through the given AST to find identifiers which are are
265+
-- 'InstanceValBind's. Two types of nodes are chosen look inside:
266+
--
267+
-- 1. The nodes which don't have any identifiers: these are the nodes which
268+
-- somehow wrap an expression, like the instance declaration itself, or a
269+
-- 'Match' which contains the 'InstanceValBind'.
270+
--
271+
-- 2. The nodes which have an 'EvidenceVarBind': if one of the implemented
272+
-- methods uses functions like 'undefined', the binding for the '?callstack'
273+
-- gets bound over the 'Match' which contains the 'InstanceValBind', so to
274+
-- find the 'InstanceValBind' this function must look inside any
275+
-- 'EvidenceVarBind's it finds.
264276
findInstanceValBindIdentifiers :: HieAST a -> [Identifier]
265277
findInstanceValBindIdentifiers ast
266-
| Map.null (getNodeIds ast) = concatMap findInstanceValBindIdentifiers (nodeChildren ast)
278+
| Map.null nodeIds
279+
|| hasEvidenceBind nodeIds = concatMap findInstanceValBindIdentifiers (nodeChildren ast)
267280
| otherwise = Map.keys
268281
. Map.filter (not . Set.null)
269282
. Map.map (Set.filter isInstanceValBind . identInfo)
270-
$ getNodeIds ast
283+
$ nodeIds
284+
where
285+
nodeIds = getNodeIds ast
286+
hasEvidenceBind = not . Map.null . Map.filter (any isEvidenceBind . identInfo)
271287

272288
ghostSpan :: RealSrcSpan
273289
ghostSpan = realSrcLocSpan $ mkRealSrcLoc (fsLit "<haskell-language-sever>") 1 1

plugins/hls-class-plugin/test/testdata/T6.1.expected.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ class Test a where
1111
h :: a -> a
1212
h = f
1313

14-
{-# MINIMAL f, g | g, h #-}
14+
i :: a
15+
16+
{-# MINIMAL f, g, i | g, h #-}
1517

1618
instance Test X where
1719
f X = X
1820
f Y = Y
21+
i = undefined
1922
g = _

plugins/hls-class-plugin/test/testdata/T6.2.expected.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ class Test a where
1111
h :: a -> a
1212
h = f
1313

14-
{-# MINIMAL f, g | g, h #-}
14+
i :: a
15+
16+
{-# MINIMAL f, g, i | g, h #-}
1517

1618
instance Test X where
1719
f X = X
1820
f Y = Y
21+
i = undefined
1922
g = _
2023
h = _

plugins/hls-class-plugin/test/testdata/T6.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ class Test a where
1111
h :: a -> a
1212
h = f
1313

14-
{-# MINIMAL f, g | g, h #-}
14+
i :: a
15+
16+
{-# MINIMAL f, g, i | g, h #-}
1517

1618
instance Test X where
1719
f X = X
1820
f Y = Y
21+
i = undefined

0 commit comments

Comments
 (0)