runCommand (CmdModuleFile moduleName) = do
    let status = respond . ClientLog "ModuleFile"
    status "Initialize cabal"
    liftP (view cabalFile) >>= traverse_ setAllCabalImportDirs
    status "Load target"
    target <- lift $ GHC.guessTarget moduleName Nothing
    lift $ GHC.setTargets [target]
    -- TODO: This currently fails, need to figure out why (when cabal support enabled)
    status "Build module graph"
    moduleGraph <- lift $ GHC.depanal [] False `GHC.gcatch` \(SomeException _) -> return []
    status "Find module"
    case find (moduleSummaryMatchesModuleName moduleName) moduleGraph of
        Nothing -> do
          respond $ ClientStderr "Module not found"
          return $ ExitFailure 1
        Just modSummary ->
            case GHC.ml_hs_file (GHC.ms_location modSummary) of
                Nothing -> do
                  respond $ ClientStderr "Module does not have a source file"
                  return $ ExitFailure 1
                Just file -> do
                  respond $ ClientStdout file
                  return ExitSuccess
    where moduleSummaryMatchesModuleName modName modSummary = modName == (GHC.moduleNameString . GHC.moduleName . GHC.ms_mod) modSummary
runCommand (CmdModuleFile moduleName) = do
    let status = respond . ClientLog "ModuleFile"
    status "Initialize cabal"
    liftP (view cabalFile) >>= traverse_ setAllCabalImportDirs
    status "Load target"
    target <- lift $ GHC.guessTarget moduleName Nothing
    lift $ GHC.setTargets [target]
    -- TODO: This currently fails, need to figure out why (when cabal support enabled)
    status "Build module graph"
    moduleGraph <- lift $ GHC.depanal [] False `GHC.gcatch` \(SomeException _) -> return []
    status "Find module"
    case find (moduleSummaryMatchesModuleName moduleName) moduleGraph of
        Nothing -> do
          respond $ ClientStderr "Module not found"
          return $ ExitFailure 1
        Just modSummary ->
            case GHC.ml_hs_file (GHC.ms_location modSummary) of
                Nothing -> do
                  respond $ ClientStderr "Module does not have a source file"
                  return $ ExitFailure 1
                Just file -> do
                  respond $ ClientStdout file
                  return ExitSuccess
    where moduleSummaryMatchesModuleName modName modSummary = modName == (GHC.moduleNameString . GHC.moduleName . GHC.ms_mod) modSummary
runCommand (CmdModuleFile moduleName) = do
    let status = respond . ClientLog "ModuleFile"
    status "Initialize cabal"
    liftP (view cabalFile) >>= traverse_ setAllCabalImportDirs
    status "Load target"
    target <- lift $ GHC.guessTarget moduleName Nothing
    lift $ GHC.setTargets [target]
    -- TODO: This currently fails, need to figure out why (when cabal support enabled)
    status "Build module graph"
    moduleGraph <- lift $ GHC.depanal [] False `GHC.gcatch` \(SomeException _) -> return []
    status "Find module"
    case find (moduleSummaryMatchesModuleName moduleName) moduleGraph of
        Nothing -> do
          respond $ ClientStderr "Module not found"
          return $ ExitFailure 1
        Just modSummary ->
            case GHC.ml_hs_file (GHC.ms_location modSummary) of
                Nothing -> do
                  respond $ ClientStderr "Module does not have a source file"
                  return $ ExitFailure 1
                Just file -> do
                  respond $ ClientStdout file
                  return ExitSuccess
    where moduleSummaryMatchesModuleName modName modSummary = modName == (GHC.moduleNameString . GHC.moduleName . GHC.ms_mod) modSummary