Skip to content

Commit 264e91d

Browse files
committed
[SourceKit] Allow SourceEntityWalker to visit generic type parameters of type decls.
This unlocks SourceKit's "find related identifiers" request on generic type params. rdar://22356526
1 parent ac5d14a commit 264e91d

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

lib/AST/ASTWalker.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,13 @@ class Traversal : public ASTVisitor<Traversal, Expr*, Stmt*,
193193
}
194194

195195
bool visitNominalTypeDecl(NominalTypeDecl *NTD) {
196+
if(auto GPS = NTD->getGenericParams()) {
197+
for (auto GP : GPS->getParams()) {
198+
if (doIt(GP))
199+
return true;
200+
}
201+
}
202+
196203
for (auto &Inherit : NTD->getInherited()) {
197204
if (doIt(Inherit))
198205
return true;

test/IDE/annotation.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func bar(x: Int) -> (Int, Float) {
100100
class C2 {
101101
typealias WW = Int
102102
var p = 0
103-
103+
104104
func meth(x: Int) {}
105105
}
106106

@@ -109,7 +109,7 @@ func test2(x: C2) {
109109
x.meth(0)
110110
}
111111

112-
// CHECK: class <Class>GenCls</Class><T> {
112+
// CHECK: class <Class>GenCls</Class><<GenericTypeParam>T</GenericTypeParam>> {
113113
class GenCls<T> {
114114
// CHECK: <Constructor>init</Constructor>() {}
115115
init() {}

test/SourceKit/SourceDocInfo/related_idents.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ class C2 {
1919
}()
2020
}
2121

22+
class C2<Param> {
23+
func f(t : Param) -> Param {return t}
24+
}
25+
2226
// RUN: %sourcekitd-test -req=related-idents -pos=6:17 %s -- -module-name related_idents %s | FileCheck -check-prefix=CHECK1 %s
2327
// CHECK1: START RANGES
2428
// CHECK1-NEXT: 1:7 - 2
@@ -42,3 +46,10 @@ class C2 {
4246
// CHECK4-NEXT: 17:9 - 1
4347
// CHECK4-NEXT: 18:12 - 1
4448
// CHECK4-NEXT: END RANGES
49+
50+
// RUN: %sourcekitd-test -req=related-idents -pos=22:12 %s -- -module-name related_idents %s | FileCheck -check-prefix=CHECK5 %s
51+
// CHECK5: START RANGES
52+
// CHECK5-NEXT: 22:10 - 5
53+
// CHECK5-NEXT: 23:13 - 5
54+
// CHECK5-NEXT: 23:23 - 5
55+
// CHECK5-NEXT: END RANGES

0 commit comments

Comments
 (0)