diff --git a/src/Control/Abstract/Analysis.hs b/src/Control/Abstract/Analysis.hs index 33affe7c1..05033991f 100644 --- a/src/Control/Abstract/Analysis.hs +++ b/src/Control/Abstract/Analysis.hs @@ -65,7 +65,7 @@ withModules = localModuleTable . const . ModuleTable.fromList -- | Run an action with the passed ('Blob', @term@) pairs available for imports. withModulesForBlobs :: MonadAnalysis term value m => Blob -> [(Blob, term)] -> m a -> m a -withModulesForBlobs blob = withModules . map (uncurry (moduleForBlob rootDir)) +withModulesForBlobs blob = withModules . map (uncurry (moduleForBlob (Just rootDir))) where rootDir = dropFileName (blobPath blob) diff --git a/src/Data/Abstract/Module.hs b/src/Data/Abstract/Module.hs index dda8f35db..077eadf87 100644 --- a/src/Data/Abstract/Module.hs +++ b/src/Data/Abstract/Module.hs @@ -18,12 +18,12 @@ data Module term = Module { moduleName :: ModuleName, modulePath :: FilePath, mo -- | Construct a 'Module' for a 'Blob' and @term@, relative to some root 'FilePath'. -moduleForBlob :: FilePath -- ^ The root directory relative to which the module will be resolved. - -> 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'. +moduleForBlob :: Maybe FilePath -- ^ The root directory relative to which the module will be resolved, if any. + -> 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 term = Module (moduleName blob) (blobPath blob) term - where moduleName Blob{..} = let path = dropExtensions (makeRelative rootDir blobPath) + where moduleName Blob{..} = let path = dropExtensions (maybe takeFileName makeRelative rootDir blobPath) in case blobLanguage of -- TODO: Need a better way to handle module registration and resolution Just Go -> toName (takeDirectory path) -- Go allows defining modules across multiple files in the same directory.