-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Update symbol id encoding for pp.angle things to be more precise. Then implement symbol lookup. This is sufficient to give us describe() , symbol pages and hover text. Reviewed By: mpark Differential Revision: D48059438 fbshipit-source-id: e476eb6d3548d61e4e7c202cbcd29e4e72b3fb99
- Loading branch information
1 parent
a045502
commit 60343a6
Showing
18 changed files
with
279 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
{- | ||
Copyright (c) Meta Platforms, Inc. and affiliates. | ||
All rights reserved. | ||
This source code is licensed under the BSD-style license found in the | ||
LICENSE file in the root directory of this source tree. | ||
-} | ||
|
||
{-# LANGUAGE TypeApplications, ApplicativeDo, PartialTypeSignatures #-} | ||
{-# LANGUAGE AllowAmbiguousTypes #-} | ||
{-# OPTIONS_GHC -Wno-orphans #-} | ||
|
||
module Glean.Glass.Search.Pp | ||
( {- instances -} | ||
) where | ||
|
||
import Data.Text ( Text ) | ||
|
||
import Glean.Glass.Search.Class | ||
import Glean.Angle as Angle | ||
import Glean.Glass.Query ( entityLocation ) | ||
import Glean.Glass.Utils ( joinFragments ) | ||
|
||
import qualified Glean.Schema.CodePp.Types as Pp | ||
import qualified Glean.Schema.CodemarkupTypes.Types as Code | ||
import qualified Glean.Schema.Pp1.Types as Pp | ||
import qualified Glean.Schema.Src.Types as Src | ||
|
||
breakPathAndName :: [Text] -> Maybe (Path, Name) | ||
breakPathAndName [] = Nothing | ||
breakPathAndName [_name] = Nothing -- has to be a file and a name | ||
breakPathAndName toks@(_:_) = Just (Path path, Name name) | ||
where | ||
path = joinFragments (init toks) | ||
name = last toks | ||
|
||
data Query | ||
= Define !Path !Name | ||
| Undef !Path !Name | ||
| Include !Path | ||
|
||
newtype Path = Path Text | ||
newtype Name = Name Text | ||
|
||
instance Search Pp.Entity where | ||
symbolSearch toks = case toks of | ||
[] -> return $ None "PP.symbolSearch: empty" | ||
[_] -> return $ None "PP.symbolSearch: singleton: not a symbolid" | ||
base:rest -> case base of | ||
"define" -> case breakPathAndName rest of | ||
Nothing -> return $ None "Pp.symbolSearch: define: missing name" | ||
Just (path, name) -> searchSymbolId toks $ runQuery (Define path name) | ||
"undef" -> case breakPathAndName rest of | ||
Nothing -> return $ None "Pp.symbolSearch: undef: missing name" | ||
Just (path, name) -> searchSymbolId toks $ runQuery (Undef path name) | ||
_ -> searchSymbolId toks $ runQuery (Include (Path (joinFragments toks))) | ||
|
||
runQuery :: Query -> Angle (ResultLocation Pp.Entity) | ||
runQuery (Define path name) = searchDefine path name | ||
runQuery (Undef path name) = searchUndef path name | ||
runQuery (Include path) = searchInclude path | ||
|
||
searchDefine :: Path -> Name -> Angle (ResultLocation Pp.Entity) | ||
searchDefine (Path path) (Name name) = | ||
vars $ \(entity :: Angle Pp.Entity) (file :: Angle Src.File) | ||
(decl :: Angle Pp.Define) (rangespan :: Angle Code.RangeSpan) | ||
(lname :: Angle Text) -> | ||
tuple (entity,file,rangespan,lname) `where_` [ | ||
file .= predicate @Src.File (string path), | ||
decl .= predicate @Pp.Define ( | ||
rec $ | ||
field @"macro" (string name) $ | ||
field @"source" (rec $ field @"file" (asPredicate file) end) | ||
end), | ||
alt @"define" (asPredicate decl) .= sig entity, | ||
entityLocation (alt @"pp" entity) file rangespan lname | ||
] | ||
|
||
searchUndef :: Path -> Name -> Angle (ResultLocation Pp.Entity) | ||
searchUndef (Path path) (Name name) = | ||
vars $ \(entity :: Angle Pp.Entity) (file :: Angle Src.File) | ||
(decl :: Angle Pp.Undef) (rangespan :: Angle Code.RangeSpan) | ||
(lname :: Angle Text) -> | ||
tuple (entity,file,rangespan,lname) `where_` [ | ||
file .= predicate @Src.File (string path), | ||
decl .= predicate @Pp.Undef ( | ||
rec $ | ||
field @"macro" (string name) $ | ||
field @"source" (rec $ field @"file" (asPredicate file) end) | ||
end), | ||
alt @"undef" (asPredicate decl) .= sig entity, | ||
entityLocation (alt @"pp" entity) file rangespan lname | ||
] | ||
|
||
searchInclude :: Path -> Angle (ResultLocation Pp.Entity) | ||
searchInclude (Path path) = | ||
vars $ \(entity :: Angle Pp.Entity) (file :: Angle Src.File) | ||
(rangespan :: Angle Code.RangeSpan) (lname :: Angle Text) -> | ||
tuple (entity,file,rangespan,lname) `where_` [ | ||
file .= predicate @Src.File (string path), | ||
wild .= predicate @Pp.Include ( -- asserts it is a member of pp.Include | ||
rec $ field @"file" (asPredicate file) end), | ||
alt @"include_" (asPredicate file) .= sig entity, | ||
entityLocation (alt @"pp" entity) file rangespan lname | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
glean/glass/test/regression/tests/cpp/describe_symbol_macro.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
[ | ||
"@generated", | ||
{ | ||
"comments": [], | ||
"contains_relation": { | ||
"firstChild": "nondeterministic", | ||
"firstParent": "nondeterministic", | ||
"hasMoreChildren": false, | ||
"hasMoreParents": false | ||
}, | ||
"extends_relation": { | ||
"firstChild": "nondeterministic", | ||
"firstParent": "nondeterministic", | ||
"hasMoreChildren": false, | ||
"hasMoreParents": false | ||
}, | ||
"kind": 30, | ||
"language": 8, | ||
"location": { | ||
"filepath": "test2.h", | ||
"range": { | ||
"columnBegin": 9, | ||
"columnEnd": 12, | ||
"lineBegin": 10, | ||
"lineEnd": 10 | ||
}, | ||
"repository": "test" | ||
}, | ||
"modifiers": [], | ||
"name": { | ||
"container": "test2.h", | ||
"localName": "FOO" | ||
}, | ||
"pretty_comments": [], | ||
"repo_hash": "testhash", | ||
"sym": "test/pp/define/test2.h/FOO", | ||
"sym_location": { | ||
"filepath": "test2.h", | ||
"range": { | ||
"columnBegin": 9, | ||
"columnEnd": 12, | ||
"lineBegin": 10, | ||
"lineEnd": 10 | ||
}, | ||
"repository": "test" | ||
}, | ||
"sym_other_locations": [], | ||
"type_xrefs": [] | ||
} | ||
] |
2 changes: 2 additions & 0 deletions
2
glean/glass/test/regression/tests/cpp/describe_symbol_macro.query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
action: describeSymbol | ||
args: "test/pp/define/test2.h/FOO" |
50 changes: 50 additions & 0 deletions
50
glean/glass/test/regression/tests/cpp/describe_symbol_macro_2.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
[ | ||
"@generated", | ||
{ | ||
"comments": [], | ||
"contains_relation": { | ||
"firstChild": "nondeterministic", | ||
"firstParent": "nondeterministic", | ||
"hasMoreChildren": false, | ||
"hasMoreParents": false | ||
}, | ||
"extends_relation": { | ||
"firstChild": "nondeterministic", | ||
"firstParent": "nondeterministic", | ||
"hasMoreChildren": false, | ||
"hasMoreParents": false | ||
}, | ||
"kind": 30, | ||
"language": 8, | ||
"location": { | ||
"filepath": "test.cpp", | ||
"range": { | ||
"columnBegin": 9, | ||
"columnEnd": 10, | ||
"lineBegin": 87, | ||
"lineEnd": 87 | ||
}, | ||
"repository": "test" | ||
}, | ||
"modifiers": [], | ||
"name": { | ||
"container": "test.cpp", | ||
"localName": "A" | ||
}, | ||
"pretty_comments": [], | ||
"repo_hash": "testhash", | ||
"sym": "test/pp/define/test.cpp/A", | ||
"sym_location": { | ||
"filepath": "test.cpp", | ||
"range": { | ||
"columnBegin": 9, | ||
"columnEnd": 10, | ||
"lineBegin": 87, | ||
"lineEnd": 87 | ||
}, | ||
"repository": "test" | ||
}, | ||
"sym_other_locations": [], | ||
"type_xrefs": [] | ||
} | ||
] |
2 changes: 2 additions & 0 deletions
2
glean/glass/test/regression/tests/cpp/describe_symbol_macro_2.query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
action: describeSymbol | ||
args: "test/pp/define/test.cpp/A" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.