1
1
mirror of https://github.com/github/semantic.git synced 2025-01-05 05:58:34 +03:00

Dry up Ruby resolving

This commit is contained in:
Timothy Clem 2018-04-03 09:00:07 -07:00
parent f98f7a403d
commit 55cd6e4549

View File

@ -17,17 +17,18 @@ import System.FilePath.Posix
--
-- require "json"
resolveRubyName :: MonadEvaluatable location term value m => ByteString -> m M.ModuleName
resolveRubyName n = resolve [name <.> "rb"] >>= maybeFail notFound
where name = toName n
notFound = "Unable to resolve: " <> name
toName = BC.unpack . dropRelativePrefix . stripQuotes
resolveRubyName name = let n = cleanNameOrPath name in resolve [n <.> "rb"] >>= maybeFailNotFound n
-- load "/root/src/file.rb"
resolveRubyPath :: MonadEvaluatable location term value m => ByteString -> m M.ModuleName
resolveRubyPath n = resolve [name] >>= maybeFail notFound
where name = toName n
notFound = "Unable to resolve: " <> name
toName = BC.unpack . dropRelativePrefix . stripQuotes
resolveRubyPath path = let n = cleanNameOrPath path in resolve [n] >>= maybeFailNotFound n
maybeFailNotFound :: MonadFail m => String -> Maybe a -> m a
maybeFailNotFound name = maybeFail notFound
where notFound = "Unable to resolve: " <> name
cleanNameOrPath :: ByteString -> String
cleanNameOrPath = BC.unpack . dropRelativePrefix . stripQuotes
data Require a = Require { requireRelative :: Bool, requirePath :: !a }
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable, FreeVariables1)