diff --git a/glean/glass/Glean/Glass/SymbolId.hs b/glean/glass/Glean/Glass/SymbolId.hs index 99944d35a..3d3c1da53 100644 --- a/glean/glass/Glean/Glass/SymbolId.hs +++ b/glean/glass/Glean/Glass/SymbolId.hs @@ -387,6 +387,7 @@ instance ToQName Code.Entity where Code.Entity_flow x -> toQName x Code.Entity_graphql x -> toQName x Code.Entity_hack (Hack.Entity_decl x) -> toQName x + Code.Entity_hs x -> toQName x Code.Entity_java x -> toQName x Code.Entity_kotlin x -> toQName x Code.Entity_pp x -> toQName x diff --git a/glean/glass/Glean/Glass/SymbolId/Hs.hs b/glean/glass/Glean/Glass/SymbolId/Hs.hs index 57803ab81..3e5456208 100644 --- a/glean/glass/Glean/Glass/SymbolId/Hs.hs +++ b/glean/glass/Glean/Glass/SymbolId/Hs.hs @@ -9,16 +9,22 @@ {-# OPTIONS_GHC -Wno-orphans #-} module Glean.Glass.SymbolId.Hs ({- instances -}) where + +import Data.Text (Text) import qualified Data.Text as Text -import Glean.Glass.SymbolId.Class - ( toSymbolPredicate, Symbol(..) ) +import Glean.Glass.SymbolId.Class +import Glean.Glass.Types (Name(..)) +import Glean.Schema.CodeHs.Types as Hs (Entity (..)) import qualified Glean - import qualified Glean.Schema.Hs.Types as Hs import qualified Glean.Schema.Src.Types as Src -import Glean.Schema.CodeHs.Types as Hs (Entity (..)) +instance Symbol Hs.Entity where + toSymbol (Hs.Entity_definition d) = toSymbolPredicate d + toSymbol (Hs.Entity_function_ d) = toSymbolPredicate d + toSymbol (Hs.Entity_class_ d) = toSymbolPredicate d + toSymbol Hs.Entity_EMPTY = return [] instance Symbol Hs.Definition_key where toSymbol (Hs.Definition_key name _) = do @@ -37,8 +43,37 @@ instance Symbol Hs.Class_key where fname <- Glean.keyOf range_file return (fname : Text.splitOn "." name) -instance Symbol Hs.Entity where - toSymbol (Hs.Entity_definition d) = toSymbolPredicate d - toSymbol (Hs.Entity_function_ d) = toSymbolPredicate d - toSymbol (Hs.Entity_class_ d) = toSymbolPredicate d - toSymbol Hs.Entity_EMPTY = return [] +instance ToQName Hs.Entity where + toQName (Hs.Entity_definition d) = Glean.keyOf d >>= toQName + toQName (Hs.Entity_function_ d) = Glean.keyOf d >>= toQName + toQName (Hs.Entity_class_ d) = Glean.keyOf d >>= toQName + toQName Hs.Entity_EMPTY = + return $ Left "toQName: Haskell: empty qname" + +instance ToQName Hs.Definition_key where + toQName (Hs.Definition_key name _) = do + n <- Glean.keyOf name + return $ case reverse (Text.splitOn "." n) of + [] -> Left "toQName: Haskell: empty function qname" + [x] -> Right (Name x, Name "") + (x:xs) -> Right (Name x, joinDotted xs) + +instance ToQName Hs.FunctionDefinition_key where + toQName (Hs.FunctionDefinition_key fnName Src.Range{..}) = do + name <- Glean.keyOf fnName + return $ case reverse (Text.splitOn "." name) of + [] -> Left "toQName: Haskell: empty function qname" + [x] -> Right (Name x, Name "") + (x:xs) -> Right (Name x, joinDotted xs) + + +instance ToQName Hs.Class_key where + toQName (Hs.Class_key clsName Src.Range{..}) = do + name <- Glean.keyOf clsName + return $ case reverse (Text.splitOn "." name) of + [] -> Left "toQName: Haskell: empty class qname" + [x] -> Right (Name x, Name "") + (x:xs) -> Right (Name x, joinDotted xs) + +joinDotted :: [Text] -> Name +joinDotted = Name . Text.intercalate "." . reverse