[SourceKit][SymbolGraph] Add a 'ParentContexts' field the CursorInfo response

When the SymbolGraph json is requested via (key.retrieve_symbol_graph: 1) this adds
a new field in the response that lists all the parent contexts of the symbol under
the cursor with their symbol graph kind and name, and their USR:

key.parent_contexts: [
    {
      key.kind: "swift.struct",
      key.name: "Parent",
      key.usr: "s:27cursor_symbol_graph_parents6ParentV"
    },
    ...
  ]
}

Resolves rdar://problem/73904365
This commit is contained in:
Nathan Hawes
2021-02-10 14:36:30 +10:00
parent e2bac38348
commit 6d940951ca
11 changed files with 356 additions and 71 deletions

View File

@@ -104,7 +104,8 @@ int symbolgraphgen::
printSymbolGraphForDecl(const ValueDecl *D, Type BaseTy,
bool InSynthesizedExtension,
const SymbolGraphOptions &Options,
llvm::raw_ostream &OS) {
llvm::raw_ostream &OS,
SmallVectorImpl<PathComponent> &ParentContexts) {
if (!Symbol::supportsKind(D->getKind()))
return EXIT_FAILURE;
@@ -119,6 +120,11 @@ printSymbolGraphForDecl(const ValueDecl *D, Type BaseTy,
: nullptr;
Symbol MySym(&Graph, D, NTD, BaseTy);
MySym.getPathComponents(ParentContexts);
assert(!ParentContexts.empty() && "doesn't have node for MySym?");
ParentContexts.pop_back();
Graph.recordNode(MySym);
Graph.serialize(JOS);
return EXIT_SUCCESS;