1
1
mirror of https://github.com/github/semantic.git synced 2024-12-23 23:11:50 +03:00

Make the root directory relative.

This commit is contained in:
Rob Rix 2018-03-21 20:11:44 -04:00
parent 7436f9605f
commit 2902b9c2a3
2 changed files with 6 additions and 6 deletions

View File

@ -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)

View File

@ -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.