Skip to content

Commit 7886b50

Browse files
author
Nathan Hawes
authored
Merge pull request swiftlang#36330 from nathawes/include-symbol-itself-in-parent-context-list
[SourceKit][CursorInfo] Also include the symbol itself in the "parent" contexts list
2 parents f2544aa + b8832f4 commit 7886b50

File tree

2 files changed

+45
-32
lines changed

2 files changed

+45
-32
lines changed

lib/SymbolGraphGen/SymbolGraphGen.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,7 @@ printSymbolGraphForDecl(const ValueDecl *D, Type BaseTy,
115115
: nullptr;
116116

117117
Symbol MySym(&Graph, D, NTD, BaseTy);
118-
119118
MySym.getPathComponents(ParentContexts);
120-
assert(!ParentContexts.empty() && "doesn't have node for MySym?");
121-
ParentContexts.pop_back();
122-
123119
Graph.recordNode(MySym);
124120
Graph.serialize(JOS);
125121
return EXIT_SUCCESS;

test/SourceKit/CursorInfo/cursor_symbol_graph_parents.swift

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -62,78 +62,92 @@ extension Parent.Inner.DeepNested<T> where T: Equatable {
6262
}
6363
}
6464

65-
// 1) Global symbols have no parents, but do have a symbol graph.
65+
// 1) Global symbols should include only themselves.
6666
//
67-
// RUN: %sourcekitd-test -req=cursor -pos=2:5 -req-opts=retrieve_symbol_graph=1 %s -- %s -target %target-triple | %FileCheck -check-prefix=GLOBAL %s
68-
// RUN: %sourcekitd-test -req=cursor -pos=5:8 -req-opts=retrieve_symbol_graph=1 %s -- %s -target %target-triple | %FileCheck -check-prefix=GLOBAL %s
69-
// RUN: %sourcekitd-test -req=cursor -pos=27:11 -req-opts=retrieve_symbol_graph=1 %s -- %s -target %target-triple | %FileCheck -check-prefix=GLOBAL %s
70-
// RUN: %sourcekitd-test -req=cursor -pos=39:11 -req-opts=retrieve_symbol_graph=1 %s -- %s -target %target-triple | %FileCheck -check-prefix=GLOBAL %s
71-
// RUN: %sourcekitd-test -req=cursor -pos=50:11 -req-opts=retrieve_symbol_graph=1 %s -- %s -target %target-triple | %FileCheck -check-prefix=GLOBAL %s
67+
// RUN: %sourcekitd-test -req=cursor -pos=2:5 -req-opts=retrieve_symbol_graph=1 %s -- %s -target %target-triple | %FileCheck -check-prefixes=GLOBAL,GLOBAL_VAR %s
68+
// RUN: %sourcekitd-test -req=cursor -pos=5:8 -req-opts=retrieve_symbol_graph=1 %s -- %s -target %target-triple | %FileCheck -check-prefixes=GLOBAL,PARENT_STRUCT %s
69+
// RUN: %sourcekitd-test -req=cursor -pos=27:11 -req-opts=retrieve_symbol_graph=1 %s -- %s -target %target-triple | %FileCheck -check-prefixes=GLOBAL,PARENT_STRUCT %s
70+
// RUN: %sourcekitd-test -req=cursor -pos=39:11 -req-opts=retrieve_symbol_graph=1 %s -- %s -target %target-triple | %FileCheck -check-prefixes=GLOBAL,PARENT_STRUCT %s
71+
// RUN: %sourcekitd-test -req=cursor -pos=50:11 -req-opts=retrieve_symbol_graph=1 %s -- %s -target %target-triple | %FileCheck -check-prefixes=GLOBAL,PARENT_STRUCT %s
7272
//
7373
//
74-
// GLOBAL-NOT: PARENT CONTEXTS BEGIN
7574
// GLOBAL: SYMBOL GRAPH BEGIN
76-
// GLOBAL-NOT: PARENT CONTEXTS BEGIN
75+
// GLOBAL: PARENT CONTEXTS BEGIN
76+
// GLOBAL_VAR-NEXT: global swift.var s:27cursor_symbol_graph_parents6globalSivp
77+
// PARENT_STRUCT-NEXT: Parent swift.struct s:27cursor_symbol_graph_parents6ParentV
78+
// GLOBAL-NEXT: PARENT CONTEXTS END
7779

7880

79-
// 2) Members within Parent and its extensions should list Parent as a parent
80-
// context, and have a symbol graph.
81+
// 2) Members within Parent and its extensions should list themselves and
82+
// Parent.
8183
//
82-
// RUN: %sourcekitd-test -req=cursor -pos=7:12 -req-opts=retrieve_symbol_graph=1 %s -- %s -target %target-triple | %FileCheck -check-prefix=PARENTMEMBER %s
83-
// RUN: %sourcekitd-test -req=cursor -pos=13:9 -req-opts=retrieve_symbol_graph=1 %s -- %s -target %target-triple | %FileCheck -check-prefix=PARENTMEMBER %s
84-
// RUN: %sourcekitd-test -req=cursor -pos=15:10 -req-opts=retrieve_symbol_graph=1 %s -- %s -target %target-triple | %FileCheck -check-prefix=PARENTMEMBER %s
85-
// RUN: %sourcekitd-test -req=cursor -pos=29:10 -req-opts=retrieve_symbol_graph=1 %s -- %s -target %target-triple | %FileCheck -check-prefix=PARENTMEMBER %s
86-
// RUN: %sourcekitd-test -req=cursor -pos=32:12 -req-opts=retrieve_symbol_graph=1 %s -- %s -target %target-triple | %FileCheck -check-prefix=PARENTMEMBER %s
87-
// RUN: %sourcekitd-test -req=cursor -pos=39:18 -req-opts=retrieve_symbol_graph=1 %s -- %s -target %target-triple | %FileCheck -check-prefix=PARENTMEMBER %s
88-
// RUN: %sourcekitd-test -req=cursor -pos=50:18 -req-opts=retrieve_symbol_graph=1 %s -- %s -target %target-triple | %FileCheck -check-prefix=PARENTMEMBER %s
84+
// RUN: %sourcekitd-test -req=cursor -pos=7:12 -req-opts=retrieve_symbol_graph=1 %s -- %s -target %target-triple | %FileCheck -check-prefixes=PARENTMEMBER,INNER_STRUCT %s
85+
// RUN: %sourcekitd-test -req=cursor -pos=13:9 -req-opts=retrieve_symbol_graph=1 %s -- %s -target %target-triple | %FileCheck -check-prefixes=PARENTMEMBER,MEMBER_VAR %s
86+
// RUN: %sourcekitd-test -req=cursor -pos=15:10 -req-opts=retrieve_symbol_graph=1 %s -- %s -target %target-triple | %FileCheck -check-prefixes=PARENTMEMBER,METHOD_FUNC %s
87+
// RUN: %sourcekitd-test -req=cursor -pos=29:10 -req-opts=retrieve_symbol_graph=1 %s -- %s -target %target-triple | %FileCheck -check-prefixes=PARENTMEMBER,EXTMETHOD_FUNC %s
88+
// RUN: %sourcekitd-test -req=cursor -pos=32:12 -req-opts=retrieve_symbol_graph=1 %s -- %s -target %target-triple | %FileCheck -check-prefixes=PARENTMEMBER,EXTINNER_STRUCT %s
89+
// RUN: %sourcekitd-test -req=cursor -pos=39:18 -req-opts=retrieve_symbol_graph=1 %s -- %s -target %target-triple | %FileCheck -check-prefixes=PARENTMEMBER,INNER_STRUCT %s
90+
// RUN: %sourcekitd-test -req=cursor -pos=50:18 -req-opts=retrieve_symbol_graph=1 %s -- %s -target %target-triple | %FileCheck -check-prefixes=PARENTMEMBER,INNER_STRUCT %s
8991
//
9092
//
9193
// PARENTMEMBER: SYMBOL GRAPH BEGIN
9294
// PARENTMEMBER: SYMBOL GRAPH END
9395
// PARENTMEMBER: PARENT CONTEXTS BEGIN
9496
// PARENTMEMBER-NEXT: Parent swift.struct s:27cursor_symbol_graph_parents6ParentV
97+
// INNER_STRUCT-NEXT: Inner swift.struct s:27cursor_symbol_graph_parents6ParentV5InnerV
98+
// MEMBER_VAR-NEXT: member swift.property s:27cursor_symbol_graph_parents6ParentV6memberSivp
99+
// METHOD_FUNC-NEXT: method() swift.method s:27cursor_symbol_graph_parents6ParentV6methodyyF
100+
// EXTMETHOD_FUNC-NEXT: extensionMethod() swift.method s:27cursor_symbol_graph_parents6ParentV15extensionMethodyyF
101+
// EXTINNER_STRUCT-NEXT: ExtInner swift.struct s:27cursor_symbol_graph_parents6ParentV8ExtInnerV
95102
// PARENTMEMBER-NEXT: PARENT CONTEXTS END
96103

97104

98-
// 3) Members within Parent.Inner and its extensions should list both Inner and
99-
// Parent as parent contexts, and have a symbol graph.
105+
// 3) Members within Parent.Inner and its extensions should list themselves,
106+
// Inner and Parent as parent contexts.
100107
//
101-
// RUN: %sourcekitd-test -req=cursor -pos=9:13 -req-opts=retrieve_symbol_graph=1 %s -- %s -target %target-triple | %FileCheck -check-prefix=INNERMEMBER %s
102-
// RUN: %sourcekitd-test -req=cursor -pos=41:10 -req-opts=retrieve_symbol_graph=1 %s -- %s -target %target-triple | %FileCheck -check-prefix=INNERMEMBER %s
103-
// RUN: %sourcekitd-test -req=cursor -pos=43:12 -req-opts=retrieve_symbol_graph=1 %s -- %s -target %target-triple | %FileCheck -check-prefix=INNERMEMBER %s
104-
// RUN: %sourcekitd-test -req=cursor -pos=50:24 -req-opts=retrieve_symbol_graph=1 %s -- %s -target %target-triple | %FileCheck -check-prefix=INNERMEMBER %s
108+
// RUN: %sourcekitd-test -req=cursor -pos=9:13 -req-opts=retrieve_symbol_graph=1 %s -- %s -target %target-triple | %FileCheck -check-prefixes=INNERMEMBER,INNERMEMBER_VAR %s
109+
// RUN: %sourcekitd-test -req=cursor -pos=41:10 -req-opts=retrieve_symbol_graph=1 %s -- %s -target %target-triple | %FileCheck -check-prefixes=INNERMEMBER,EXTINNERMETHOD_FUNC %s
110+
// RUN: %sourcekitd-test -req=cursor -pos=43:12 -req-opts=retrieve_symbol_graph=1 %s -- %s -target %target-triple | %FileCheck -check-prefixes=INNERMEMBER,DEEPNESTED_CLASS %s
111+
// RUN: %sourcekitd-test -req=cursor -pos=50:24 -req-opts=retrieve_symbol_graph=1 %s -- %s -target %target-triple | %FileCheck -check-prefixes=INNERMEMBER,DEEPNESTED_CLASS %s
105112
//
106113
// INNERMEMBER: SYMBOL GRAPH BEGIN
107114
// INNERMEMBER: SYMBOL GRAPH END
108115
// INNERMEMBER: PARENT CONTEXTS BEGIN
109116
// INNERMEMBER-NEXT: Parent swift.struct s:27cursor_symbol_graph_parents6ParentV
110117
// INNERMEMBER-NEXT: Inner swift.struct s:27cursor_symbol_graph_parents6ParentV5InnerV
118+
// INNERMEMBER_VAR-NEXT: innerMember swift.property s:27cursor_symbol_graph_parents6ParentV5InnerV11innerMemberSivp
119+
// EXTINNERMETHOD_FUNC-NEXT: extensionOfInnerMethod() swift.method s:27cursor_symbol_graph_parents6ParentV5InnerV011extensionOfF6MethodyyF
120+
// DEEPNESTED_CLASS-NEXT: DeepNested swift.class s:27cursor_symbol_graph_parents6ParentV5InnerV10DeepNestedC
111121
// INNERMEMBER-NEXT: PARENT CONTEXTS END
112122

113123

114124
// 4) Members within Parent.Inner.DeepNested and its extensions should list
115-
// DeepNested, Inner, and Parent as parent contexts and have a symbol graph.
125+
// themselves DeepNested, Inner, and Parent.
116126
//
117-
// RUN: %sourcekitd-test -req=cursor -pos=45:9 -req-opts=retrieve_symbol_graph=1 %s -- %s -target %target-triple | %FileCheck -check-prefix=DEEPNESTEDMEMBER %s
118-
// RUN: %sourcekitd-test -req=cursor -pos=52:10 -req-opts=retrieve_symbol_graph=1 %s -- %s -target %target-triple | %FileCheck -check-prefix=DEEPNESTEDMEMBER %s
127+
// RUN: %sourcekitd-test -req=cursor -pos=45:9 -req-opts=retrieve_symbol_graph=1 %s -- %s -target %target-triple | %FileCheck -check-prefixes=DEEPNESTEDMEMBER,DEEPNESTED_INIT %s
128+
// RUN: %sourcekitd-test -req=cursor -pos=52:10 -req-opts=retrieve_symbol_graph=1 %s -- %s -target %target-triple | %FileCheck -check-prefixes=DEEPNESTEDMEMBER,EXTDEEPNESTEDMETHOD_FUNC %s
119129
//
120130
// DEEPNESTEDMEMBER: SYMBOL GRAPH BEGIN
121131
// DEEPNESTEDMEMBER: SYMBOL GRAPH END
122132
// DEEPNESTEDMEMBER: PARENT CONTEXTS BEGIN
123133
// DEEPNESTEDMEMBER-NEXT: Parent swift.struct s:27cursor_symbol_graph_parents6ParentV
124134
// DEEPNESTEDMEMBER-NEXT: Inner swift.struct s:27cursor_symbol_graph_parents6ParentV5InnerV
125135
// DEEPNESTEDMEMBER-NEXT: DeepNested swift.class s:27cursor_symbol_graph_parents6ParentV5InnerV10DeepNestedC
136+
// DEEPNESTED_INIT-NEXT: init(deepNestedInit:) swift.init s:27cursor_symbol_graph_parents6ParentV5InnerV10DeepNestedC04deepH4InitAGy__xGx_tcfc
137+
// EXTDEEPNESTEDMETHOD_FUNC: extensionOfDeepNestedMethod() swift.method s:27cursor_symbol_graph_parents6ParentV5InnerV10DeepNestedCAASQRzlE011extensionOfgH6MethodyyF
126138
// DEEPNESTEDMEMBER-NEXT: PARENT
127139

128140

129-
// 5) Members directly or indirectly within local contexts should show the
130-
// local contexts as parents if they're representable in the symbol graph.
141+
// 5) Members directly or indirectly within local contexts should show
142+
// themselves and the local contexts as parents if they're representable in
143+
// the symbol graph.
131144
//
132145
// RUN: %sourcekitd-test -req=cursor -pos=19:16 -req-opts=retrieve_symbol_graph=1 %s -- %s -target %target-triple | %FileCheck -check-prefix=LOCAL %s
133146
//
134147
// LOCAL: PARENT CONTEXTS BEGIN
135148
// LOCAL-NEXT: Parent swift.struct s:27cursor_symbol_graph_parents6ParentV
136149
// LOCAL-NEXT: localContext() swift.method s:27cursor_symbol_graph_parents6ParentV12localContextyyF
150+
// LOCAL-NEXT: Local swift.struct s:27cursor_symbol_graph_parents6ParentV12localContextyyF5LocalL_V
137151
// LOCAL-NEXT: PARENT CONTEXTS END
138152
//
139153
// RUN: %sourcekitd-test -req=cursor -pos=21:17 -req-opts=retrieve_symbol_graph=1 %s -- %s -target %target-triple | %FileCheck -check-prefix=TRANSITIVELOCAL %s
@@ -142,6 +156,7 @@ extension Parent.Inner.DeepNested<T> where T: Equatable {
142156
// TRANSITIVELOCAL-NEXT: Parent swift.struct s:27cursor_symbol_graph_parents6ParentV
143157
// TRANSITIVELOCAL-NEXT: localContext() swift.method s:27cursor_symbol_graph_parents6ParentV12localContextyyF
144158
// TRANSITIVELOCAL-NEXT: Local swift.struct s:27cursor_symbol_graph_parents6ParentV12localContextyyF5LocalL_V
159+
// TRANSITIVELOCAL-NEXT: localMember swift.property s:27cursor_symbol_graph_parents6ParentV12localContextyyF5LocalL_V0F6MemberSivp
145160
// TRANSITIVELOCAL-NEXT: PARENT CONTEXTS END
146161
//
147162
// RUN: %sourcekitd-test -req=cursor -pos=56:20 -req-opts=retrieve_symbol_graph=1 %s -- %s -target %target-triple | %FileCheck -check-prefix=CLOSUREINLOCAL %s
@@ -160,6 +175,7 @@ extension Parent.Inner.DeepNested<T> where T: Equatable {
160175
// CLOSUREINLOCAL-NEXT: Inner swift.struct s:27cursor_symbol_graph_parents6ParentV5InnerV
161176
// CLOSUREINLOCAL-NEXT: DeepNested swift.class s:27cursor_symbol_graph_parents6ParentV5InnerV10DeepNestedC
162177
// CLOSUREINLOCAL-NEXT: extensionOfDeepNestedMethod() swift.method s:27cursor_symbol_graph_parents6ParentV5InnerV10DeepNestedCAASQRzlE011extensionOfgH6MethodyyF
178+
// CLOSUREINLOCAL-NEXT: InClosure swift.struct s:27cursor_symbol_graph_parents6ParentV5InnerV10DeepNestedCAASQRzlE011extensionOfgH6MethodyyFyycfU_9InClosureL_V
163179
// CLOSUREINLOCAL-NEXT: PARENT CONTEXTS END
164180
//
165181
// RUN: %sourcekitd-test -req=cursor -pos=60:20 -req-opts=retrieve_symbol_graph=1 %s -- %s -target %target-triple | %FileCheck -check-prefix=ACCESSORINLOCAL %s
@@ -177,4 +193,5 @@ extension Parent.Inner.DeepNested<T> where T: Equatable {
177193
// ACCESSORINLOCAL-NEXT: Inner swift.struct s:27cursor_symbol_graph_parents6ParentV5InnerV
178194
// ACCESSORINLOCAL-NEXT: DeepNested swift.class s:27cursor_symbol_graph_parents6ParentV5InnerV10DeepNestedC
179195
// ACCESSORINLOCAL-NEXT: extensionOfDeepNestedMethod() swift.method s:27cursor_symbol_graph_parents6ParentV5InnerV10DeepNestedCAASQRzlE011extensionOfgH6MethodyyF
196+
// ACCESSORINLOCAL-NEXT: InAccessor swift.struct s:27cursor_symbol_graph_parents6ParentV5InnerV10DeepNestedCAASQRzlE011extensionOfgH6MethodyyF04deepH8ComputedL_Sivg10InAccessorL_V
180197
// ACCESSORINLOCAL-NEXT: PARENT CONTEXTS END

0 commit comments

Comments
 (0)