1
1
mirror of https://github.com/github/semantic.git synced 2025-01-03 04:51:57 +03:00

Guard clauses.

This commit is contained in:
Rob Rix 2018-03-21 20:30:39 -04:00
parent 45dcfaad41
commit 36aa4e445c

View File

@ -23,9 +23,8 @@ moduleForBlob :: Maybe FilePath -- ^ The root directory relative to which the mo
-> term -- ^ The @term@ representing the body of 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. -> Module term -- ^ A 'Module' named appropriate for the 'Blob', holding the @term@, and constructed relative to the root 'FilePath', if any.
moduleForBlob rootDir blob term = Module (moduleName blob) (blobPath blob) term moduleForBlob rootDir blob term = Module (moduleName blob) (blobPath blob) term
where moduleName Blob{..} = let path = dropExtensions (maybe takeFileName makeRelative rootDir blobPath) where moduleName Blob{..} | Just Go <- blobLanguage = toName (takeDirectory (modulePath blobPath))
in toName $ case blobLanguage of | otherwise = toName (modulePath blobPath)
-- TODO: Need a better way to handle module registration and resolution -- TODO: Need a better way to handle module registration and resolution
Just Go -> takeDirectory path -- Go allows defining modules across multiple files in the same directory.
_ -> path
toName str = qualifiedName (BC.pack <$> splitWhen (== pathSeparator) str) toName str = qualifiedName (BC.pack <$> splitWhen (== pathSeparator) str)
modulePath = dropExtensions . maybe takeFileName makeRelative rootDir