Consider unqualified function calls.
This commit is contained in:
parent
cb26e1727b
commit
f84f91327c
|
@ -13,7 +13,6 @@ module Rubyhs.References
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Frelude
|
import Frelude
|
||||||
-- import Data.Language.Ruby hiding (context)
|
|
||||||
import qualified Data.Language.Ruby as Ruby
|
import qualified Data.Language.Ruby as Ruby
|
||||||
import Data.HashMap.Strict (HashMap)
|
import Data.HashMap.Strict (HashMap)
|
||||||
import qualified Data.HashMap.Strict as HashMap
|
import qualified Data.HashMap.Strict as HashMap
|
||||||
|
@ -160,14 +159,29 @@ instance MyMonad (State Env) where
|
||||||
application n = do
|
application n = do
|
||||||
Context c <- getContext
|
Context c <- getContext
|
||||||
let
|
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}
|
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
|
modify go
|
||||||
getContext = gets Rubyhs.References.context
|
getContext = gets Rubyhs.References.context
|
||||||
writeContext q = modify go
|
writeContext q = modify go
|
||||||
where
|
where
|
||||||
go env = env { Rubyhs.References.context = q }
|
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 :: MyMonad m => m a -> m a
|
||||||
locally act = do
|
locally act = do
|
||||||
old <- getContext
|
old <- getContext
|
||||||
|
|
|
@ -32,7 +32,7 @@ tests = go <$> ["mod", "simple"]
|
||||||
let (Ruby.Result refs) = Ruby.references begin
|
let (Ruby.Result refs) = Ruby.references begin
|
||||||
when (refs /= json)
|
when (refs /= json)
|
||||||
$ assertFailure
|
$ 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 :: FromJSON a => FilePath -> IO a
|
||||||
decodeFile p = Aeson.eitherDecodeFileStrict' p >>= \case
|
decodeFile p = Aeson.eitherDecodeFileStrict' p >>= \case
|
||||||
|
|
Loading…
Reference in a new issue