Skip to content

Commit 78f33f4

Browse files
jjuliamolinfacebook-github-bot
authored andcommitted
add go-to-def for angle
Summary: * Creating symbol ids for angle * adding the fbsource.fbcode.angle db for glass to query **Symbol ids:** ```fbsource/angle/fbcode/glean/schema/source/hack.angle/hack.Signature.6``` <path>/<qualified_name> All current symbols will have namespace "schema name", and it's already in the qualified name. If we add other entities we might add other namespaces too, e.g., a variable X would exist in a predicates derive clause. ```<path>/<qname_pred>/var_X``` or something? No need to decide this now, but as reviewer please have a look so we're not blocking future changes with other namespaces Reviewed By: pepeiborra Differential Revision: D74875860 fbshipit-source-id: df5028aeb058a76964099710abffaa29442a9a02
1 parent 6c8f2a4 commit 78f33f4

File tree

3 files changed

+94
-1
lines changed

3 files changed

+94
-1
lines changed

glean.cabal.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,6 +1255,7 @@ library glass-lib
12551255
Glean.Glass.SnapshotBackend
12561256
Glean.Glass.SourceControl
12571257
Glean.Glass.SymbolId
1258+
Glean.Glass.SymbolId.Angle
12581259
Glean.Glass.SymbolId.Buck
12591260
Glean.Glass.SymbolId.Class
12601261
Glean.Glass.SymbolId.CSharp

glean/glass/Glean/Glass/SymbolId.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ import Glean.Glass.SymbolId.Class
7474
ToStrobelightFrame(..),
7575
ToSymbolParent(..),
7676
ToNativeSymbol(..) )
77-
77+
import Glean.Glass.SymbolId.Angle ({- instances -})
7878
import Glean.Glass.SymbolId.Buck ({- instances -})
7979
import Glean.Glass.SymbolId.Cxx ({- instances -})
8080
import Glean.Glass.SymbolId.Erlang ({- instances -})
@@ -298,6 +298,7 @@ instance Symbol Code.Entity where
298298
toSymbol _ = throwM $ SymbolError "Code.Entity: use toSymbolWithPath"
299299

300300
toSymbolWithPath e p = case e of
301+
Code.Entity_angle x -> toSymbolWithPath x p
301302
Code.Entity_hack (Hack.Entity_decl x) -> toSymbolWithPath x p
302303
Code.Entity_python (Python.Entity_decl x) -> toSymbolWithPath x p
303304
Code.Entity_flow x -> toSymbolWithPath x p
@@ -397,6 +398,7 @@ entityToAngle e = case e of
397398

398399
instance ToQName Code.Entity where
399400
toQName e = case e of
401+
Code.Entity_angle x -> toQName x
400402
Code.Entity_buck x -> toQName x
401403
Code.Entity_csharp x -> toQName x
402404
Code.Entity_cxx x -> toQName x
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
{-
2+
Copyright (c) Meta Platforms, Inc. and affiliates.
3+
All rights reserved.
4+
5+
This source code is licensed under the BSD-style license found in the
6+
LICENSE file in the root directory of this source tree.
7+
-}
8+
9+
{-# OPTIONS_GHC -Wno-orphans #-}
10+
11+
module Glean.Glass.SymbolId.Angle (
12+
{- instances and -}
13+
) where
14+
15+
import qualified Glean
16+
17+
import Glean.Glass.SymbolId.Class
18+
import Control.Monad.Catch ( throwM )
19+
import Glean.Glass.Types (Path(..), Name(..))
20+
import qualified Glean.Haxl.Repos as Glean
21+
import qualified Glean.Schema.Anglelang.Types as A
22+
import qualified Glean.Schema.CodeAnglelang.Types as A
23+
import Data.Text (Text)
24+
import qualified Data.Text as Text
25+
26+
instance Symbol A.Entity where
27+
toSymbol _ = throwM $ SymbolError "Angle.Entity: use toSymbolWithPath"
28+
toSymbolWithPath e (Path p) = do
29+
syms <- toSymbol $ A.entity_decl e
30+
return $ case syms of
31+
[] -> []
32+
(x:xs) -> Text.splitOn "/" p <> (x:xs)
33+
34+
instance Symbol A.Declaration where
35+
toSymbol d = case d of
36+
A.Declaration_pred x -> toSymbolPredicate x
37+
A.Declaration_ty x -> toSymbolPredicate x
38+
A.Declaration_schema x -> toSymbolPredicate x
39+
A.Declaration_imp x -> toSymbol x
40+
A.Declaration_derive_ x -> toSymbolPredicate x
41+
A.Declaration_evolve _ -> return []
42+
A.Declaration_EMPTY -> return []
43+
44+
instance Symbol A.PredicateDecl_key where
45+
toSymbol A.PredicateDecl_key{..} = toSymbol predicateDecl_key_name
46+
47+
instance Symbol A.TypeDecl_key where
48+
toSymbol A.TypeDecl_key{..} = toSymbol typeDecl_key_name
49+
50+
instance Symbol A.SchemaDecl_key where
51+
toSymbol A.SchemaDecl_key{..} = toSymbol schemaDecl_key_name
52+
53+
instance Symbol A.DerivingDecl_key where
54+
toSymbol (A.DerivingDecl_key n d) = do
55+
n' <- toSymbol n
56+
return $ n' ++ [Text.pack $ "_" ++ show d]
57+
58+
instance Symbol A.Name where
59+
toSymbol k = do
60+
v <- Glean.keyOf k
61+
return [v]
62+
63+
64+
-- Searching for Angle Entities
65+
instance ToQName A.Entity where
66+
toQName e = toQName $ A.entity_decl e
67+
68+
instance ToQName A.Declaration where
69+
toQName d = case d of
70+
A.Declaration_pred x -> Glean.keyOf x >>= toQName
71+
A.Declaration_ty x -> Glean.keyOf x >>= toQName
72+
A.Declaration_schema x -> Glean.keyOf x >>= toQName
73+
A.Declaration_imp x -> toQNameEmptyNs x
74+
A.Declaration_evolve _ -> return $ Left "evolve toQName: not supported"
75+
A.Declaration_derive_ _ -> return $ Left "derive toQName: not supported"
76+
A.Declaration_EMPTY -> return $ Left "unknown Declaration"
77+
78+
instance ToQName A.PredicateDecl_key where
79+
toQName A.PredicateDecl_key{..} = toQNameEmptyNs predicateDecl_key_name
80+
81+
instance ToQName A.TypeDecl_key where
82+
toQName A.TypeDecl_key{..} = toQNameEmptyNs typeDecl_key_name
83+
84+
instance ToQName A.SchemaDecl_key where
85+
toQName A.SchemaDecl_key{..} = toQNameEmptyNs schemaDecl_key_name
86+
87+
toQNameEmptyNs :: A.Name -> Glean.RepoHaxl u w (Either Text (Name, Name))
88+
toQNameEmptyNs name = do
89+
nameStr <- Glean.keyOf name
90+
return $ Right (Name nameStr, Name mempty)

0 commit comments

Comments
 (0)