1
1
mirror of https://github.com/github/semantic.git synced 2025-01-06 23:46:21 +03:00

Split module name/path into a ModuleInfo type.

This commit is contained in:
Rob Rix 2018-03-30 19:42:31 -04:00
parent e6a63259fc
commit 11c584b6ff
4 changed files with 12 additions and 6 deletions

View File

@ -49,7 +49,7 @@ instance ( Effectful m
(\yield (LoadError name) -> insertVertexName name >> yield [])
analyzeModule recur m = do
insertVertexName (moduleName m)
insertVertexName (moduleName (moduleInfo m))
liftAnalyze analyzeModule recur m
insertVertexName :: forall m location term value effects
@ -62,7 +62,7 @@ insertVertexName :: forall m location term value effects
-> ImportGraphing m effects ()
insertVertexName name = do
o <- raise ask
let parent = maybe empty (vertex . moduleName) (originModule @term o)
let parent = maybe empty (vertex . moduleName . moduleInfo) (originModule @term o)
modifyImportGraph (parent >< vertex name <>)
(><) :: Graph a => a -> a -> a

View File

@ -1,5 +1,6 @@
module Data.Abstract.Module
( Module(..)
, ModuleInfo(..)
, ModuleName
, moduleForBlob
) where
@ -13,7 +14,10 @@ import System.FilePath.Posix
type ModuleName = Name
data Module term = Module { moduleName :: ModuleName, modulePath :: FilePath, moduleBody :: term }
data ModuleInfo = ModuleInfo { moduleName :: ModuleName, modulePath :: FilePath }
deriving (Eq, Ord, Show)
data Module term = Module { moduleInfo :: ModuleInfo, moduleBody :: term }
deriving (Eq, Foldable, Functor, Ord, Show, Traversable)
@ -22,11 +26,12 @@ moduleForBlob :: Maybe FilePath -- ^ The root directory relative to which the mo
-> Blob -- ^ The 'Blob' containing the module.
-> term -- ^ The @term@ representing the body of the module.
-> Module term -- ^ A 'Module' named appropriate for the 'Blob', holding the @term@, and constructed relative to the root 'FilePath', if any.
moduleForBlob rootDir blob = Module (moduleNameForPath (modulePathForBlob blob)) (blobPath blob)
moduleForBlob rootDir blob = Module info
where modulePathForBlob Blob{..} | Just Go <- blobLanguage = takeDirectory (modulePath blobPath)
| otherwise = modulePath blobPath
-- TODO: Need a better way to handle module registration and resolution
modulePath = dropExtensions . maybe takeFileName makeRelative rootDir
info = ModuleInfo (moduleNameForPath (modulePathForBlob blob)) (blobPath blob)
moduleNameForPath :: FilePath -> ModuleName
moduleNameForPath = qualifiedName . map BC.pack . splitWhen (== pathSeparator)

View File

@ -31,7 +31,7 @@ insert k v ModuleTable{..} = ModuleTable (Map.insert k v unModuleTable)
-- | Construct a 'ModuleTable' from a list of 'Module's.
fromModules :: [Module term] -> ModuleTable [Module term]
fromModules = ModuleTable . Map.fromListWith (<>) . map toEntry
where toEntry m = (moduleName m, [m])
where toEntry m = (moduleName (moduleInfo m), [m])
toPairs :: ModuleTable a -> [(ModuleName, a)]
toPairs = Map.toList . unModuleTable

View File

@ -20,4 +20,5 @@ newtype Version = Version { versionString :: String }
fromModules :: [Module term] -> Package term
fromModules [] = Package Nothing Nothing mempty mempty
fromModules (m:ms) = Package Nothing Nothing (ModuleTable.fromModules (m:ms)) (ModuleTable.singleton (moduleName m) Nothing)
fromModules (m:ms) = Package Nothing Nothing (ModuleTable.fromModules (m:ms)) entryPoints
where entryPoints = ModuleTable.singleton (moduleName (moduleInfo m)) Nothing