Skip to content

Commit 11c8f07

Browse files
committed
[SourceKit] Annotate dynamic Self type in protocol *extensions*
D'oh, forgot to resolve a FIXME in my protocol commit. Now working there too except that it's giving USRs on the original protocol instead of the extension. It's not clear how to get back to the extension from the archetype though. rdar://problem/25128561
1 parent 2ded9fe commit 11c8f07

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3855,10 +3855,18 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
38553855
if (T->getName().empty())
38563856
Printer << "<anonymous>";
38573857
else {
3858-
PrintNameContext context = PrintNameContext::Normal;
3859-
if (T->getSelfProtocol())
3860-
context = PrintNameContext::GenericParameter;
3861-
Printer.printName(T->getName(), context);
3858+
// Print protocol 'Self' as a generic parameter so that it gets
3859+
// annotated in cursor info.
3860+
// FIXME: in a protocol extension, we really want the extension, not the
3861+
// protocol.
3862+
if (auto *P = T->getSelfProtocol()) {
3863+
auto *GTD = P->getProtocolSelf();
3864+
assert(GTD && GTD->isProtocolSelf());
3865+
Printer.printTypeRef(T, GTD, T->getName());
3866+
return;
3867+
}
3868+
3869+
Printer.printName(T->getName());
38623870
}
38633871
}
38643872
}

test/SourceKit/SourceDocInfo/cursor_info.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -602,10 +602,10 @@ class C7 {
602602
// RUN: %sourcekitd-test -req=cursor -pos=165:8 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck %s -check-prefix=CHECK75
603603
// CHECK75: source.lang.swift.decl.function.method.instance (165:8-165:18)
604604
// CHECK75: <Self : P3> (Self) -> (Self) -> Self
605-
// CHECK75: <Declaration>func f(s: <Type usr="s:tE11cursor_infoPS_2P34SelfMx">Self</Type>) -&gt; Self</Declaration>
605+
// CHECK75: <Declaration>func f(s: <Type usr="s:tE11cursor_infoPS_2P34SelfMx">Self</Type>) -&gt; <Type usr="s:tP11cursor_info2P34SelfMx">Self</Type></Declaration>
606606
// CHECK75: <decl.var.parameter.type><ref.generic_type_param usr="s:tE11cursor_infoPS_2P34SelfMx">Self</ref.generic_type_param></decl.var.parameter.type>
607-
// CHECK75-SAME: <decl.function.returntype><decl.generic_type_param.name>Self</decl.generic_type_param.name></decl.function.returntype>
608-
// FIXME: Should be ref.generic_type_param
607+
// CHECK75-SAME: <decl.function.returntype><ref.generic_type_param usr="s:tP11cursor_info2P34SelfMx">Self</ref.generic_type_param></decl.function.returntype>
608+
// FIXME: the return type gets the USR for the original protocol, rather than the extension.
609609

610610
// RUN: %sourcekitd-test -req=cursor -pos=169:8 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck %s -check-prefix=CHECK76
611611
// CHECK76: source.lang.swift.decl.function.method.instance (169:8-169:11)

0 commit comments

Comments
 (0)