Consider unqualified function calls.
This commit is contained in:
parent
cb26e1727b
commit
f84f91327c
|
@ -13,7 +13,6 @@ module Rubyhs.References
|
|||
) where
|
||||
|
||||
import Frelude
|
||||
-- import Data.Language.Ruby hiding (context)
|
||||
import qualified Data.Language.Ruby as Ruby
|
||||
import Data.HashMap.Strict (HashMap)
|
||||
import qualified Data.HashMap.Strict as HashMap
|
||||
|
@ -160,14 +159,29 @@ instance MyMonad (State Env) where
|
|||
application n = do
|
||||
Context c <- getContext
|
||||
let
|
||||
n' = case n of
|
||||
-- TODO: Maybe check if there is `a` is a function in the
|
||||
-- current closure.
|
||||
(NodeDef (FQN [] a)) -> NodeDef $ FQN (nodeNs c) a
|
||||
-- Look for the closest enclosing scope that has a reference
|
||||
-- to `c`. For now we'll just guess that it is a fully
|
||||
-- qualified reference.
|
||||
NodeDef{} -> n
|
||||
-- Ditto as above.
|
||||
NodeModule{} -> n
|
||||
go env@Env{applications}
|
||||
= env { applications = HashMap.insertWith mappend c (Set.singleton n) applications }
|
||||
= env { applications = HashMap.insertWith mappend c (Set.singleton n') applications }
|
||||
modify go
|
||||
getContext = gets Rubyhs.References.context
|
||||
writeContext q = modify go
|
||||
where
|
||||
go env = env { Rubyhs.References.context = q }
|
||||
|
||||
nodeNs :: Node -> Namespace
|
||||
nodeNs = \case
|
||||
(NodeDef (FQN a _)) -> a
|
||||
NodeModule n -> n
|
||||
|
||||
locally :: MyMonad m => m a -> m a
|
||||
locally act = do
|
||||
old <- getContext
|
||||
|
|
|
@ -32,7 +32,7 @@ tests = go <$> ["mod", "simple"]
|
|||
let (Ruby.Result refs) = Ruby.references begin
|
||||
when (refs /= json)
|
||||
$ assertFailure
|
||||
$ "Expected " <> convertString (Aeson.encode refs) <> " but got " <> convertString (Aeson.encode json)
|
||||
$ "Expected " <> convertString (Aeson.encode json) <> " but got " <> convertString (Aeson.encode refs)
|
||||
|
||||
decodeFile :: FromJSON a => FilePath -> IO a
|
||||
decodeFile p = Aeson.eitherDecodeFileStrict' p >>= \case
|
||||
|
|
Loading…
Reference in a new issue