1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
9import Control.Monad.Except (liftIO)
10import qualified Data.Map as Map
11import qualified Data.Maybe as Maybe
12import qualified System.Directory as Dir
13import System.FilePath ((</>), (<.>))
15import qualified Elm.Compiler.Module as Module
16import qualified Elm.Name as N
17import qualified Elm.Package as Pkg
19import qualified Elm.Project.Json as Project
20import qualified Elm.Project.Summary as Summary
21import qualified Reporting.Exit.Crawl as E
22import qualified Reporting.Task as Task
31 | Kernel FilePath (Maybe FilePath)
39find :: Summary.Summary -> E.Origin -> Module.Raw -> Task.Task_ E.Problem Asset
40find (Summary.Summary root project exposed _ _) origin name =
43 do let srcDirs = map (root </>) (Project._app_source_dirs info)
44 findElm srcDirs exposed origin name
47 if N.startsWith "Elm.Kernel." name then
48 if Project.isPlatformPackage project then
49 findKernel (root </> "src") origin name
51 Task.throw $ E.ModuleNameReservedForKernel origin name
54 findElm [ root </> "src" ] exposed origin name
61findElm :: [FilePath] -> Summary.ExposedModules -> E.Origin -> Module.Raw -> Task.Task_ E.Problem Asset
62findElm srcDirs exposed origin name =
64 paths <- liftIO $ Maybe.catMaybes <$> mapM (elmExists name) srcDirs
66 case (paths, Map.lookup name exposed) of
74 Task.throw $ E.ModuleNotFound origin name
77 Task.throw $ E.ModuleAmbiguous origin name paths (maybe [] id maybePkgs)
80elmExists :: Module.Raw -> FilePath -> IO (Maybe FilePath)
81elmExists name srcDir =
82 do let path = srcDir </> Module.nameToSlashPath name <.> "elm"
83 exists <- Dir.doesFileExist path
84 return $ if exists then Just path else Nothing
91findKernel :: FilePath -> E.Origin -> Module.Raw -> Task.Task_ E.Problem Asset
92findKernel srcDir origin name =
93 do let clientPath = srcDir </> Module.nameToSlashPath name <.> "js"
94 let serverPath = srcDir </> Module.nameToSlashPath name <.> "server.js"
95 client <- liftIO $ Dir.doesFileExist clientPath
96 server <- liftIO $ Dir.doesFileExist serverPath
98 then return $ Kernel clientPath (if server then Just serverPath else Nothing)
99 else Task.throw $ E.ModuleNotFound origin name
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list