+-- | Finds the enclosing top level function name
+findEnclosingDecl :: HscEnv -> Module -> SrcSpan -> Name
+findEnclosingDecl hsc_env mod span =
+ case lookupUFM (hsc_HPT hsc_env) (moduleName mod) of
+ Nothing -> panic "findEnclosingDecl"
+ Just hmi -> let
+ globals = typeEnvIds (md_types (hm_details hmi))
+ Just decl = find (\n -> nameSrcSpan n < span)
+ (reverse $ map idName globals)
+ -- ^^ assumes md_types is sorted
+ in decl
+
+-- | Finds the span of the (smallest) function containing this BreakIndex
+findEnclosingDeclSpanByTick :: HscEnv -> Module -> BreakIndex -> SrcSpan
+findEnclosingDeclSpanByTick hsc_env mod tick =
+ case lookupUFM (hsc_HPT hsc_env) (moduleName mod) of
+ Nothing -> panic "findEnclosingDecl"
+ Just hmi -> let
+ modbreaks = md_modBreaks (hm_details hmi)
+ in ASSERT (inRange (bounds (modBreaks_decls modbreaks)) tick)
+ modBreaks_decls modbreaks ! tick
+
+-- | Find the Module corresponding to a FilePath
+findModuleFromFile :: HscEnv -> FilePath -> Maybe Module
+findModuleFromFile hsc_env fp =
+ listToMaybe $ [ms_mod ms | ms <- hsc_mod_graph hsc_env
+ , ml_hs_file(ms_location ms) == Just (read fp)]
+
+