Skip to content

Commit 0ac5dcd

Browse files
Amith Bhat Nekkarefacebook-github-bot
authored andcommitted
Added entityLocation and Chef.hs
Summary: Mimicking a recent addition - anglelang.angle by adding the entityLocation predicate (its probably required to list symbols? as per Developing API page in Glean docs) Chef.hs is required for Glass to synthesize a Symbol ID, which is required for proper functionality Implemented Symbol (CodeChef.Entity, Chef.Symbol), and ToQName to enable go-to-def Reviewed By: CatherineGasnier Differential Revision: D78604841 fbshipit-source-id: cac08af2995ced745bb1555c8a080c511245cb51
1 parent 70640c6 commit 0ac5dcd

5 files changed

Lines changed: 64 additions & 6 deletions

File tree

glean/glass/Glean/Glass/SymbolId.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ import Glean.Glass.SymbolId.Class
7474
import Glean.Glass.SymbolId.Angle ({- instances -})
7575
import Glean.Glass.SymbolId.Buck ({- instances -})
7676
import Glean.Glass.SymbolId.Cxx ({- instances -})
77+
import Glean.Glass.SymbolId.Chef ({- instances -})
7778
import Glean.Glass.SymbolId.Erlang ({- instances -})
7879
import Glean.Glass.SymbolId.Fbthrift ({- instances -})
7980
import Glean.Glass.SymbolId.Flow ({- instances -})
@@ -303,6 +304,7 @@ instance Symbol Code.Entity where
303304
Code.Entity_csharp x -> toSymbolWithPath x p
304305
Code.Entity_cxx x -> toSymbolWithPath x p
305306
Code.Entity_buck x -> toSymbolWithPath x p
307+
Code.Entity_chef x -> toSymbolWithPath x p
306308
Code.Entity_erlang x -> toSymbolWithPath x p
307309
Code.Entity_graphql x -> toSymbolWithPath x p
308310
Code.Entity_hs x -> toSymbolWithPath x p
@@ -400,6 +402,7 @@ instance ToQName Code.Entity where
400402
toQName e = case e of
401403
Code.Entity_angle x -> toQName x
402404
Code.Entity_buck x -> toQName x
405+
Code.Entity_chef x -> toQName x
403406
Code.Entity_csharp x -> toQName x
404407
Code.Entity_cxx x -> toQName x
405408
Code.Entity_erlang x -> toQName x
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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.Chef (
12+
{- instances and -}
13+
) where
14+
15+
import qualified Glean
16+
import Glean.Glass.SymbolId.Class
17+
import Glean.Glass.Types (Name(..))
18+
import qualified Data.Text as T
19+
20+
import qualified Glean.Schema.Chef.Types as Chef
21+
import Glean.Schema.CodeChef.Types as CodeChef
22+
( Entity(..) )
23+
24+
25+
instance Symbol CodeChef.Entity where
26+
toSymbol e = case e of
27+
CodeChef.Entity_symbol x -> toSymbolPredicate x
28+
CodeChef.Entity_EMPTY -> return []
29+
30+
instance Symbol Chef.Symbol_key where
31+
toSymbol (Chef.Symbol_key identifier qualifiedName) = do
32+
qNames <- mapM Glean.keyOf qualifiedName
33+
name <- Glean.keyOf identifier
34+
return $ qNames ++ [ name ]
35+
36+
instance ToQName CodeChef.Entity where
37+
toQName e = case e of
38+
CodeChef.Entity_symbol definition -> do
39+
Chef.Symbol_key identifier qNameList <- Glean.keyOf definition
40+
qNameText <- mapM Glean.keyOf qNameList
41+
let path = T.intercalate "::" qNameText
42+
name <- Glean.keyOf identifier
43+
return (Right (Name name, Name path))
44+
CodeChef.Entity_EMPTY -> pure $ Left "ToQName: Unknown Chef entity"

glean/schema/source/code.chef.angle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ schema code.chef.1 {
66

77
type Entity =
88
{
9-
symbol : chef.Symbol
9+
symbol : chef.Symbol |
1010
}
1111
}

glean/schema/source/codemarkup.angle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,9 @@ predicate EntityLocation:
208208
(codemarkup.graphql.GraphQLEntityLocation { E, Location };
209209
{ graphql = E } = Entity) |
210210
(codemarkup.anglelang.AngleEntityLocation { E, Location };
211-
{ angle = E } = Entity);
211+
{ angle = E } = Entity) |
212+
(codemarkup.chef.ChefEntityLocation { E, Location };
213+
{ chef = E } = Entity);
212214

213215
# Maps a generated entity to its source definition
214216
predicate GeneratedEntityToIdlEntity:

glean/schema/source/codemarkup.chef.angle

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import code.chef
66
import codemarkup.types
77

88

9-
# Entity -> usage
109
predicate ChefEntityUses:
1110
{
1211
target: code.chef.Entity,
@@ -16,6 +15,16 @@ predicate ChefEntityUses:
1615
{{ symbol = Symbol }, File, Span } where
1716
chef.ReferencedAt { Symbol, { File, Span } }
1817

18+
19+
predicate ChefEntityLocation:
20+
{
21+
entity: code.chef.Entity,
22+
location: codemarkup.types.Location,
23+
}
24+
{ { symbol = Symbol }, { EntityName, File, { span = Span }, nothing } } where
25+
chef.DefinedAt { Symbol,{File, Span} };
26+
Symbol.identifier = chef.Name EntityName;
27+
1928
predicate ChefResolveLocation:
2029
{
2130
location: codemarkup.types.Location,
@@ -27,9 +36,9 @@ predicate ChefResolveLocation:
2736

2837
predicate ChefFileEntityXRefLocations:
2938
{
30-
file: src.File, # file where the reference is located
31-
xref: codemarkup.types.XRefLocation, # XRefs from source to target declaration or definition
32-
entity: code.chef.Entity, # actual entity that is being referenced
39+
file: src.File,
40+
xref: codemarkup.types.XRefLocation,
41+
entity: code.chef.Entity,
3342
} { File, {Location, {span = Span}}, { symbol = Symbol } } where
3443
chef.ReferencedAt { Symbol, { File, Span } };
3544
Symbol.identifier = chef.Name EntityName;

0 commit comments

Comments
 (0)