Skip to content

Commit 5883176

Browse files
Saizanalt-romes
authored andcommitted
[Fix #237] Look for haskell-debugger-view in ModuleNodes too
1 parent 034c95a commit 5883176

1 file changed

Lines changed: 17 additions & 10 deletions

File tree

haskell-debugger/GHC/Debugger/Monad.hs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import Data.Function
2626
import Data.Functor.Contravariant
2727
import Data.IORef
2828
import Data.Maybe
29+
import qualified Data.Set as Set
2930
import Data.Version (makeVersion, showVersion)
3031
import Prelude hiding (mod)
3132
#ifdef MIN_VERSION_unix
@@ -599,14 +600,20 @@ findHsDebuggerViewUnitId mod_graph = do
599600
hsc_env <- getSession
600601
let unitState = hsc_units hsc_env
601602

602-
-- Only looks at unit-nodes, this is not robust!
603-
-- TODO: Better lookup of unit-id
604-
let hskl_dbgr_vws =
603+
-- Note: linear in the module graph but only happens once.
604+
let potential_units = (`mapMaybe` mg_mss mod_graph) $ \case
605+
UnitNode _deps uid -> Just uid
606+
ModuleNode _ modl -> Just $ mnkUnitId $ mnKey modl
607+
InstantiationNode uid _ -> Just uid
608+
LinkNode _ _ -> Nothing
609+
-- Note: the intermediate set is expected to be small (<= 2).
610+
let hskl_dbgr_vws = Set.toList . Set.fromList $
605611
[ uid
606-
| UnitNode _deps uid <- mg_mss mod_graph
607-
, "haskell-debugger-view" `L.isPrefixOf` unitIdString uid
608-
|| "hskll-dbggr-vw" `L.isPrefixOf` unitIdString uid
609-
|| "haskell-debug_" `L.isPrefixOf` unitIdString uid
612+
| uid <- potential_units
613+
, let uid_s = unitIdString uid
614+
, "haskell-debugger-view" `L.isPrefixOf` uid_s
615+
|| "hskll-dbggr-vw" `L.isPrefixOf` uid_s
616+
|| "haskell-debug_" `L.isPrefixOf` uid_s
610617
]
611618

612619
-- If the haskell-debugger-view is in the dependency graph, it must have
@@ -617,7 +624,7 @@ findHsDebuggerViewUnitId mod_graph = do
617624
case hskl_dbgr_vws of
618625
[hdv_uid] -> do
619626
-- In transitive closure, use that one.
620-
-- Check that the version is exactly 0.2.0.0
627+
-- Check that the version is in supported range.
621628
case lookupUnit unitState (RealUnit (Definite hdv_uid)) of
622629
Just unitInfo -> do
623630
let version = unitPackageVersion unitInfo
@@ -628,8 +635,8 @@ findHsDebuggerViewUnitId mod_graph = do
628635
error "Could not find unit info for haskell-debugger-view"
629636
[] -> do
630637
return Nothing
631-
_ ->
632-
error "Multiple unit-ids found for haskell-debugger-view in the transitive closure?!"
638+
_ -> do
639+
error $ "Multiple unit-ids found for haskell-debugger-view in the transitive closure?!" ++ showSDocUnsafe (withPprStyle (PprDump alwaysQualify) (ppr hskl_dbgr_vws))
633640

634641
--------------------------------------------------------------------------------
635642
-- Utilities

0 commit comments

Comments
 (0)