[SourceKit] Stub in a new "fully_annotated_decl" field to cursor info

This will eventually replace the existing annoteded_decl for cursor
info, and be added to doc info as well.  For now put in under a
different field name to not break existing clients.

For now, just reimplement the existing annotations but put in tag names
that are specific to the kind of type/decl. The goal is to fill in a
lot more substructure/detail over time.

Incidentally flesh out some cursor info tests.

rdar://problem/24292226
This commit is contained in:
Ben Langmuir
2016-02-12 11:05:31 -08:00
parent 1cd7a8611d
commit 29ce0fec1b
7 changed files with 108 additions and 0 deletions

View File

@@ -87,12 +87,15 @@ public class SubscriptCursorTest {
// CHECK2-NEXT: Swift{{$}} // CHECK2-NEXT: Swift{{$}}
// CHECK2-NEXT: SYSTEM // CHECK2-NEXT: SYSTEM
// CHECK2-NEXT: <Declaration>func +(lhs: <Type usr="s:Si">Int</Type>, rhs: <Type usr="s:Si">Int</Type>) -&gt; <Type usr="s:Si">Int</Type></Declaration> // CHECK2-NEXT: <Declaration>func +(lhs: <Type usr="s:Si">Int</Type>, rhs: <Type usr="s:Si">Int</Type>) -&gt; <Type usr="s:Si">Int</Type></Declaration>
// CHECK2-NEXT: <decl.function.operator.infix>func +(lhs: <ref.struct usr="s:Si">Int</ref.struct>, rhs: <ref.struct usr="s:Si">Int</ref.struct>) -&gt; <ref.struct usr="s:Si">Int</ref.struct></decl.function.operator.infix>
// RUN: %sourcekitd-test -req=cursor -pos=9:12 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck -check-prefix=CHECK3 %s // RUN: %sourcekitd-test -req=cursor -pos=9:12 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck -check-prefix=CHECK3 %s
// CHECK3: source.lang.swift.ref.var.local (8:10-8:11) // CHECK3: source.lang.swift.ref.var.local (8:10-8:11)
// CHECK3-NEXT: x{{$}} // CHECK3-NEXT: x{{$}}
// CHECK3-NEXT: s:vF11cursor_info3gooFSiT_L_1xSi{{$}} // CHECK3-NEXT: s:vF11cursor_info3gooFSiT_L_1xSi{{$}}
// CHECK3-NEXT: Int{{$}} // CHECK3-NEXT: Int{{$}}
// CHECK3-NEXT: <Declaration>let x: <Type usr="s:Si">Int</Type></Declaration>
// CHECK3-NEXT: <decl.var.local>let x: <ref.struct usr="s:Si">Int</ref.struct></decl.var.local>
// RUN: %sourcekitd-test -req=cursor -pos=9:18 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck -check-prefix=CHECK4 %s // RUN: %sourcekitd-test -req=cursor -pos=9:18 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck -check-prefix=CHECK4 %s
// CHECK4: source.lang.swift.ref.var.global ({{.*}}Foo.framework/Headers/Foo.h:62:12-62:21) // CHECK4: source.lang.swift.ref.var.global ({{.*}}Foo.framework/Headers/Foo.h:62:12-62:21)
@@ -101,6 +104,7 @@ public class SubscriptCursorTest {
// CHECK4-NEXT: Int32{{$}} // CHECK4-NEXT: Int32{{$}}
// CHECK4-NEXT: Foo{{$}} // CHECK4-NEXT: Foo{{$}}
// CHECK4-NEXT: <Declaration>var fooIntVar: <Type usr="s:Vs5Int32">Int32</Type></Declaration> // CHECK4-NEXT: <Declaration>var fooIntVar: <Type usr="s:Vs5Int32">Int32</Type></Declaration>
// CHECK4-NEXT: <decl.var.global>var fooIntVar: <ref.struct usr="s:Vs5Int32">Int32</ref.struct></decl.var.global>
// CHECK4-NEXT: <Variable file="{{[^"]+}}Foo.h" line="{{[0-9]+}}" column="{{[0-9]+}}"><Name>fooIntVar</Name><USR>c:@fooIntVar</USR><Declaration>var fooIntVar: Int32</Declaration><Abstract><Para> Aaa. fooIntVar. Bbb.</Para></Abstract></Variable> // CHECK4-NEXT: <Variable file="{{[^"]+}}Foo.h" line="{{[0-9]+}}" column="{{[0-9]+}}"><Name>fooIntVar</Name><USR>c:@fooIntVar</USR><Declaration>var fooIntVar: Int32</Declaration><Abstract><Para> Aaa. fooIntVar. Bbb.</Para></Abstract></Variable>
// RUN: %sourcekitd-test -req=cursor -pos=8:7 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck -check-prefix=CHECK5 %s // RUN: %sourcekitd-test -req=cursor -pos=8:7 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck -check-prefix=CHECK5 %s
@@ -116,6 +120,7 @@ public class SubscriptCursorTest {
// CHECK6-NEXT: () -> Int // CHECK6-NEXT: () -> Int
// CHECK6-NEXT: FooSwiftModule // CHECK6-NEXT: FooSwiftModule
// CHECK6-NEXT: <Declaration>func fooSwiftFunc() -&gt; <Type usr="s:Si">Int</Type></Declaration> // CHECK6-NEXT: <Declaration>func fooSwiftFunc() -&gt; <Type usr="s:Si">Int</Type></Declaration>
// CHECK6-NEXT: <decl.function.free>func fooSwiftFunc() -&gt; <ref.struct usr="s:Si">Int</ref.struct></decl.function.free>
// CHECK6-NEXT: {{^}}<Function><Name>fooSwiftFunc()</Name><USR>s:F14FooSwiftModule12fooSwiftFuncFT_Si</USR><Declaration>func fooSwiftFunc() -&gt; Int</Declaration><Abstract><Para>This is &apos;fooSwiftFunc&apos; from &apos;FooSwiftModule&apos;.</Para></Abstract></Function>{{$}} // CHECK6-NEXT: {{^}}<Function><Name>fooSwiftFunc()</Name><USR>s:F14FooSwiftModule12fooSwiftFuncFT_Si</USR><Declaration>func fooSwiftFunc() -&gt; Int</Declaration><Abstract><Para>This is &apos;fooSwiftFunc&apos; from &apos;FooSwiftModule&apos;.</Para></Abstract></Function>{{$}}
// RUN: %sourcekitd-test -req=cursor -pos=14:10 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck -check-prefix=CHECK7 %s // RUN: %sourcekitd-test -req=cursor -pos=14:10 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck -check-prefix=CHECK7 %s
@@ -124,6 +129,7 @@ public class SubscriptCursorTest {
// CHECK7-NEXT: s:V11cursor_info2S1 // CHECK7-NEXT: s:V11cursor_info2S1
// CHECK7-NEXT: S1.Type // CHECK7-NEXT: S1.Type
// CHECK7-NEXT: <Declaration>struct S1</Declaration> // CHECK7-NEXT: <Declaration>struct S1</Declaration>
// CHECK7-NEXT: <decl.struct>struct S1</decl.struct>
// CHECK7-NEXT: <Class file="{{[^"]+}}cursor_info.swift" line="13" column="8"><Name>S1</Name><USR>s:V11cursor_info2S1</USR><Declaration>struct S1</Declaration><Abstract><Para>Aaa. S1. Bbb.</Para></Abstract></Class> // CHECK7-NEXT: <Class file="{{[^"]+}}cursor_info.swift" line="13" column="8"><Name>S1</Name><USR>s:V11cursor_info2S1</USR><Declaration>struct S1</Declaration><Abstract><Para>Aaa. S1. Bbb.</Para></Abstract></Class>
// RUN: %sourcekitd-test -req=cursor -pos=19:12 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck -check-prefix=CHECK8 %s // RUN: %sourcekitd-test -req=cursor -pos=19:12 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck -check-prefix=CHECK8 %s
@@ -131,26 +137,33 @@ public class SubscriptCursorTest {
// CHECK8-NEXT: init // CHECK8-NEXT: init
// CHECK8-NEXT: s:FC11cursor_info2CCcFT1xSi_S0_ // CHECK8-NEXT: s:FC11cursor_info2CCcFT1xSi_S0_
// CHECK8-NEXT: CC.Type -> (x: Int) -> CC // CHECK8-NEXT: CC.Type -> (x: Int) -> CC
// CHECK8-NEXT: <Declaration>convenience init(x: <Type usr="s:Si">Int</Type>)</Declaration>
// CHECK8-NEXT: <decl.function.constructor>convenience init(x: <ref.struct usr="s:Si">Int</ref.struct>)</decl.function.constructor>
// RUN: %sourcekitd-test -req=cursor -pos=23:6 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck -check-prefix=CHECK9 %s // RUN: %sourcekitd-test -req=cursor -pos=23:6 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck -check-prefix=CHECK9 %s
// CHECK9: source.lang.swift.decl.var.global (23:5-23:15) // CHECK9: source.lang.swift.decl.var.global (23:5-23:15)
// CHECK9: <Declaration>var testString: <Type usr="s:SS">String</Type></Declaration> // CHECK9: <Declaration>var testString: <Type usr="s:SS">String</Type></Declaration>
// CHECK9: <decl.var.global>var testString: <ref.struct usr="s:SS">String</ref.struct></decl.var.global>
// RUN: %sourcekitd-test -req=cursor -pos=24:6 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck -check-prefix=CHECK10 %s // RUN: %sourcekitd-test -req=cursor -pos=24:6 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck -check-prefix=CHECK10 %s
// CHECK10: source.lang.swift.decl.var.global (24:5-24:18) // CHECK10: source.lang.swift.decl.var.global (24:5-24:18)
// CHECK10: <Declaration>let testLetString: <Type usr="s:SS">String</Type></Declaration> // CHECK10: <Declaration>let testLetString: <Type usr="s:SS">String</Type></Declaration>
// CHECK10: <decl.var.global>let testLetString: <ref.struct usr="s:SS">String</ref.struct></decl.var.global>
// RUN: %sourcekitd-test -req=cursor -pos=26:20 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck -check-prefix=CHECK11 %s // RUN: %sourcekitd-test -req=cursor -pos=26:20 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck -check-prefix=CHECK11 %s
// CHECK11: source.lang.swift.decl.var.local (26:19-26:23) // CHECK11: source.lang.swift.decl.var.local (26:19-26:23)
// CHECK11: <Declaration>let arg1: <Type usr="s:Si">Int</Type></Declaration> // CHECK11: <Declaration>let arg1: <Type usr="s:Si">Int</Type></Declaration>
// CHECK11: <decl.var.local>let arg1: <ref.struct usr="s:Si">Int</ref.struct></decl.var.local>
// RUN: %sourcekitd-test -req=cursor -pos=28:24 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck -check-prefix=CHECK12 %s // RUN: %sourcekitd-test -req=cursor -pos=28:24 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck -check-prefix=CHECK12 %s
// CHECK12: source.lang.swift.decl.var.local (28:23-28:27) // CHECK12: source.lang.swift.decl.var.local (28:23-28:27)
// CHECK12: <Declaration>var arg1: <Type usr="s:Si">Int</Type></Declaration> // CHECK12: <Declaration>var arg1: <Type usr="s:Si">Int</Type></Declaration>
// CHECK12: <decl.var.local>var arg1: <ref.struct usr="s:Si">Int</ref.struct></decl.var.local>
// RUN: %sourcekitd-test -req=cursor -pos=31:7 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck -check-prefix=CHECK13 %s // RUN: %sourcekitd-test -req=cursor -pos=31:7 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck -check-prefix=CHECK13 %s
// CHECK13: source.lang.swift.decl.function.free (31:6-31:37) // CHECK13: source.lang.swift.decl.function.free (31:6-31:37)
// CHECK13: <Declaration>func testDefaultParam(arg1: <Type usr="s:Si">Int</Type> = default)</Declaration> // CHECK13: <Declaration>func testDefaultParam(arg1: <Type usr="s:Si">Int</Type> = default)</Declaration>
// CHECK13: <decl.function.free>func testDefaultParam(arg1: <ref.struct usr="s:Si">Int</ref.struct> = default)</decl.function.free>
// RUN: %sourcekitd-test -req=cursor -pos=34:4 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck -check-prefix=CHECK14 %s // RUN: %sourcekitd-test -req=cursor -pos=34:4 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck -check-prefix=CHECK14 %s
// CHECK14: source.lang.swift.ref.function.free ({{.*}}Foo.framework/Frameworks/FooSub.framework/Headers/FooSub.h:4:5-4:16) // CHECK14: source.lang.swift.ref.function.free ({{.*}}Foo.framework/Frameworks/FooSub.framework/Headers/FooSub.h:4:5-4:16)
@@ -162,6 +175,7 @@ public class SubscriptCursorTest {
// CHECK15: source.lang.swift.decl.function.free (38:6-38:40) // CHECK15: source.lang.swift.decl.function.free (38:6-38:40)
// CHECK15: myFunc // CHECK15: myFunc
// CHECK15: <Declaration>func myFunc(arg1: <Type usr="s:SS">String</Type>, options: <Type usr="s:Si">Int</Type>)</Declaration> // CHECK15: <Declaration>func myFunc(arg1: <Type usr="s:SS">String</Type>, options: <Type usr="s:Si">Int</Type>)</Declaration>
// CHECK15: <decl.function.free>func myFunc(arg1: <ref.struct usr="s:SS">String</ref.struct>, options: <ref.struct usr="s:Si">Int</ref.struct>)</decl.function.free>
// CHECK15: RELATED BEGIN // CHECK15: RELATED BEGIN
// CHECK15-NEXT: <RelatedName usr="s:F11cursor_info6myFuncFSST_">myFunc(_:)</RelatedName> // CHECK15-NEXT: <RelatedName usr="s:F11cursor_info6myFuncFSST_">myFunc(_:)</RelatedName>
// CHECK15-NEXT: RELATED END // CHECK15-NEXT: RELATED END
@@ -170,6 +184,8 @@ public class SubscriptCursorTest {
// CHECK16: source.lang.swift.ref.class ({{.*}}Foo.framework/Headers/Foo.h:157:12-157:27) // CHECK16: source.lang.swift.ref.class ({{.*}}Foo.framework/Headers/Foo.h:157:12-157:27)
// CHECK16-NEXT: FooClassDerived // CHECK16-NEXT: FooClassDerived
// CHECK16-NEXT: c:objc(cs)FooClassDerived // CHECK16-NEXT: c:objc(cs)FooClassDerived
// CHECK16: <Declaration>class FooClassDerived : <Type usr="c:objc(cs)FooClassBase">FooClassBase</Type>, <Type usr="c:objc(pl)FooProtocolDerived">FooProtocolDerived</Type></Declaration>
// CHECK16-NEXT: <decl.class>class FooClassDerived : <ref.class usr="c:objc(cs)FooClassBase">FooClassBase</ref.class>, <ref.protocol usr="c:objc(pl)FooProtocolDerived">FooProtocolDerived</ref.protocol></decl.class>
// RUN: %sourcekitd-test -req=cursor -pos=1:10 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck -check-prefix=CHECK17 %s // RUN: %sourcekitd-test -req=cursor -pos=1:10 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck -check-prefix=CHECK17 %s
// CHECK17: source.lang.swift.ref.module () // CHECK17: source.lang.swift.ref.module ()
@@ -178,6 +194,7 @@ public class SubscriptCursorTest {
// RUN: %sourcekitd-test -req=cursor -pos=44:10 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck -check-prefix=CHECK18 %s // RUN: %sourcekitd-test -req=cursor -pos=44:10 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck -check-prefix=CHECK18 %s
// CHECK18: source.lang.swift.ref.typealias (43:11-43:16) // CHECK18: source.lang.swift.ref.typealias (43:11-43:16)
// CHECK18: <Declaration>typealias MyInt = <Type usr="s:Si">Int</Type></Declaration> // CHECK18: <Declaration>typealias MyInt = <Type usr="s:Si">Int</Type></Declaration>
// CHECK18: <decl.typealias>typealias MyInt = <ref.struct usr="s:Si">Int</ref.struct></decl.typealias>
// RUN: %sourcekitd-test -req=cursor -pos=46:10 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck -check-prefix=CHECK19 %s // RUN: %sourcekitd-test -req=cursor -pos=46:10 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck -check-prefix=CHECK19 %s
// CHECK19: source.lang.swift.ref.module () // CHECK19: source.lang.swift.ref.module ()
@@ -193,22 +210,29 @@ public class SubscriptCursorTest {
// RUN: %sourcekitd-test -req=cursor -pos=55:15 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck -check-prefix=CHECK22 %s // RUN: %sourcekitd-test -req=cursor -pos=55:15 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck -check-prefix=CHECK22 %s
// CHECK22: <Declaration>func availabilityIntroduced()</Declaration> // CHECK22: <Declaration>func availabilityIntroduced()</Declaration>
// CHECK22: <decl.function.method.instance>func availabilityIntroduced()</decl.function.method.instance>
// RUN: %sourcekitd-test -req=cursor -pos=56:15 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck -check-prefix=CHECK23 %s // RUN: %sourcekitd-test -req=cursor -pos=56:15 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck -check-prefix=CHECK23 %s
// CHECK23-NOT: <Declaration>func swiftUnavailable()</Declaration> // CHECK23-NOT: <Declaration>func swiftUnavailable()</Declaration>
// CHECK23-NOT: <decl.function.method.instance>func swiftUnavailable()</decl.function.method.instance>
// RUN: %sourcekitd-test -req=cursor -pos=57:15 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck -check-prefix=CHECK24 %s // RUN: %sourcekitd-test -req=cursor -pos=57:15 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck -check-prefix=CHECK24 %s
// CHECK24-NOT: <Declaration>func unavailable()</Declaration> // CHECK24-NOT: <Declaration>func unavailable()</Declaration>
// CHECK24-NOT: <decl.function.method.instance>func unavailable()</decl.function.method.instance>
// RUN: %sourcekitd-test -req=cursor -pos=58:15 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck -check-prefix=CHECK25 %s // RUN: %sourcekitd-test -req=cursor -pos=58:15 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck -check-prefix=CHECK25 %s
// CHECK25: <Declaration>func availabilityIntroducedMsg()</Declaration> // CHECK25: <Declaration>func availabilityIntroducedMsg()</Declaration>
// CHECK25: <decl.function.method.instance>func availabilityIntroducedMsg()</decl.function.method.instance>
// RUN: %sourcekitd-test -req=cursor -pos=59:15 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck -check-prefix=CHECK26 %s // RUN: %sourcekitd-test -req=cursor -pos=59:15 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck -check-prefix=CHECK26 %s
// CHECK26-NOT: <Declaration>func availabilityDeprecated()</Declaration> // CHECK26-NOT: <Declaration>func availabilityDeprecated()</Declaration>
// CHECK26-NOT: <decl.function.method.instance>func availabilityDeprecated()</decl.function.method.instance>
// RUN: %sourcekitd-test -req=cursor -pos=69:14 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck -check-prefix=CHECK27 %s // RUN: %sourcekitd-test -req=cursor -pos=69:14 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck -check-prefix=CHECK27 %s
// CHECK27: <Declaration>public subscript (i: <Type usr="s:Si">Int</Type>) -&gt; <Type usr="s:Si">Int</Type> { get }</Declaration> // CHECK27: <Declaration>public subscript (i: <Type usr="s:Si">Int</Type>) -&gt; <Type usr="s:Si">Int</Type> { get }</Declaration>
// CHECK27: <decl.function.subscript>public subscript (i: <ref.struct usr="s:Si">Int</ref.struct>) -&gt; <ref.struct usr="s:Si">Int</ref.struct> { get }</decl.function.subscript>
// RUN: %sourcekitd-test -req=cursor -pos=69:19 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck -check-prefix=CHECK28 %s // RUN: %sourcekitd-test -req=cursor -pos=69:19 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck -check-prefix=CHECK28 %s
// CHECK28: <Declaration>public subscript (i: <Type usr="s:Si">Int</Type>) -&gt; <Type usr="s:Si">Int</Type> { get }</Declaration> // CHECK28: <Declaration>public subscript (i: <Type usr="s:Si">Int</Type>) -&gt; <Type usr="s:Si">Int</Type> { get }</Declaration>
// CHECK28: <decl.function.subscript>public subscript (i: <ref.struct usr="s:Si">Int</ref.struct>) -&gt; <ref.struct usr="s:Si">Int</ref.struct> { get }</decl.function.subscript>

View File

@@ -277,6 +277,9 @@ struct CursorInfo {
StringRef GroupName; StringRef GroupName;
/// Annotated XML pretty printed declaration. /// Annotated XML pretty printed declaration.
StringRef AnnotatedDeclaration; StringRef AnnotatedDeclaration;
/// Fully annotated XML pretty printed declaration.
/// FIXME: this should eventually replace \c AnnotatedDeclaration.
StringRef FullyAnnotatedDeclaration;
/// Non-empty if the symbol was imported from a clang module. /// Non-empty if the symbol was imported from a clang module.
StringRef ModuleName; StringRef ModuleName;
/// Non-empty if a generated interface editor document has previously been /// Non-empty if a generated interface editor document has previously been

View File

@@ -55,6 +55,49 @@ private:
} }
}; };
static StringRef getTagForDecl(const Decl *D, bool isRef) {
auto UID = SwiftLangSupport::getUIDForDecl(D, isRef);
static const char *prefix = "source.lang.swift.";
assert(UID.getName().startswith(prefix));
return UID.getName().drop_front(strlen(prefix));
}
/// An ASTPrinter for annotating declarations with XML tags that describe the
/// key substructure of the declaration for CursorInfo/DocInfo.
///
/// Prints declarations with decl- and type-specific tags derived from the
/// UIDs used for decl/refs. For example,
/// <decl.function.free>func foo(x: <ref.struct usr="Si">Int</...>)</...>
class FullyAnnotatedDeclarationPrinter final : public XMLEscapingPrinter {
public:
FullyAnnotatedDeclarationPrinter(raw_ostream &OS) : XMLEscapingPrinter(OS) {}
private:
// MARK: The ASTPrinter callback interface.
void printDeclPre(const Decl *D) override {
openTag(getTagForDecl(D, /*isRef=*/false));
}
void printDeclPost(const Decl *D) override {
closeTag(getTagForDecl(D, /*isRef=*/false));
}
void printTypeRef(const TypeDecl *TD, Identifier name) override {
auto tag = getTagForDecl(TD, /*isRef=*/true);
OS << "<" << tag << " usr=\"";
SwiftLangSupport::printUSR(TD, OS);
OS << "\">";
XMLEscapingPrinter::printTypeRef(TD, name);
closeTag(tag);
}
// MARK: Convenience functions for printing.
void openTag(StringRef tag) { OS << "<" << tag << ">"; }
void closeTag(StringRef tag) { OS << "</" << tag << ">"; }
};
static Type findBaseTypeForReplacingArchetype(const ValueDecl *VD, const Type Ty) { static Type findBaseTypeForReplacingArchetype(const ValueDecl *VD, const Type Ty) {
if (Ty.isNull()) if (Ty.isNull())
return Type(); return Type();
@@ -98,6 +141,22 @@ static void printAnnotatedDeclaration(const ValueDecl *VD, const Type Ty,
OS<<"</Declaration>"; OS<<"</Declaration>";
} }
static void printFullyAnnotatedDeclaration(const ValueDecl *VD, const Type Ty,
const Type BaseTy, raw_ostream &OS) {
FullyAnnotatedDeclarationPrinter Printer(OS);
PrintOptions PO = PrintOptions::printQuickHelpDeclaration();
if (BaseTy)
PO.setArchetypeTransformForQuickHelp(BaseTy, VD->getDeclContext());
// If it's implicit, try to find an overridden ValueDecl that's not implicit.
// This will ensure we can properly annotate TypeRepr with a usr
// in AnnotatedDeclarationPrinter.
while (VD->isImplicit() && VD->getOverriddenDecl())
VD = VD->getOverriddenDecl();
VD->print(Printer, PO);
}
template <typename FnTy> template <typename FnTy>
void walkRelatedDecls(const ValueDecl *VD, const FnTy &Fn) { void walkRelatedDecls(const ValueDecl *VD, const FnTy &Fn) {
llvm::SmallDenseMap<DeclName, unsigned, 16> NamesSeen; llvm::SmallDenseMap<DeclName, unsigned, 16> NamesSeen;
@@ -299,6 +358,13 @@ static bool passCursorInfoForDecl(const ValueDecl *VD,
} }
unsigned DeclEnd = SS.size(); unsigned DeclEnd = SS.size();
unsigned FullDeclBegin = SS.size();
{
llvm::raw_svector_ostream OS(SS);
printFullyAnnotatedDeclaration(VD, Ty, BaseType, OS);
}
unsigned FullDeclEnd = SS.size();
unsigned GroupBegin = SS.size(); unsigned GroupBegin = SS.size();
{ {
llvm::raw_svector_ostream OS(SS); llvm::raw_svector_ostream OS(SS);
@@ -387,6 +453,8 @@ static bool passCursorInfoForDecl(const ValueDecl *VD,
DocCommentEnd-DocCommentBegin); DocCommentEnd-DocCommentBegin);
StringRef AnnotatedDecl = StringRef(SS.begin()+DeclBegin, StringRef AnnotatedDecl = StringRef(SS.begin()+DeclBegin,
DeclEnd-DeclBegin); DeclEnd-DeclBegin);
StringRef FullyAnnotatedDecl =
StringRef(SS.begin() + FullDeclBegin, FullDeclEnd - FullDeclBegin);
StringRef GroupName = StringRef(SS.begin() + GroupBegin, GroupEnd - GroupBegin); StringRef GroupName = StringRef(SS.begin() + GroupBegin, GroupEnd - GroupBegin);
llvm::Optional<std::pair<unsigned, unsigned>> DeclarationLoc; llvm::Optional<std::pair<unsigned, unsigned>> DeclarationLoc;
@@ -423,6 +491,7 @@ static bool passCursorInfoForDecl(const ValueDecl *VD,
Info.TypeName = TypeName; Info.TypeName = TypeName;
Info.DocComment = DocComment; Info.DocComment = DocComment;
Info.AnnotatedDeclaration = AnnotatedDecl; Info.AnnotatedDeclaration = AnnotatedDecl;
Info.FullyAnnotatedDeclaration = FullyAnnotatedDecl;
Info.ModuleName = ModuleName; Info.ModuleName = ModuleName;
Info.ModuleInterfaceName = ModuleInterfaceName; Info.ModuleInterfaceName = ModuleInterfaceName;
Info.DeclarationLoc = DeclarationLoc; Info.DeclarationLoc = DeclarationLoc;

View File

@@ -85,6 +85,7 @@ static sourcekitd_uid_t KeyTypename;
static sourcekitd_uid_t KeyOverrides; static sourcekitd_uid_t KeyOverrides;
static sourcekitd_uid_t KeyRelatedDecls; static sourcekitd_uid_t KeyRelatedDecls;
static sourcekitd_uid_t KeyAnnotatedDecl; static sourcekitd_uid_t KeyAnnotatedDecl;
static sourcekitd_uid_t KeyFullyAnnotatedDecl;
static sourcekitd_uid_t KeyDocFullAsXML; static sourcekitd_uid_t KeyDocFullAsXML;
static sourcekitd_uid_t KeyResults; static sourcekitd_uid_t KeyResults;
static sourcekitd_uid_t KeySyntaxMap; static sourcekitd_uid_t KeySyntaxMap;
@@ -171,6 +172,8 @@ static int skt_main(int argc, const char **argv) {
KeyOverrides = sourcekitd_uid_get_from_cstr("key.overrides"); KeyOverrides = sourcekitd_uid_get_from_cstr("key.overrides");
KeyRelatedDecls = sourcekitd_uid_get_from_cstr("key.related_decls"); KeyRelatedDecls = sourcekitd_uid_get_from_cstr("key.related_decls");
KeyAnnotatedDecl = sourcekitd_uid_get_from_cstr("key.annotated_decl"); KeyAnnotatedDecl = sourcekitd_uid_get_from_cstr("key.annotated_decl");
KeyFullyAnnotatedDecl =
sourcekitd_uid_get_from_cstr("key.fully_annotated_decl");
KeyDocFullAsXML = sourcekitd_uid_get_from_cstr("key.doc.full_as_xml"); KeyDocFullAsXML = sourcekitd_uid_get_from_cstr("key.doc.full_as_xml");
KeyResults = sourcekitd_uid_get_from_cstr("key.results"); KeyResults = sourcekitd_uid_get_from_cstr("key.results");
KeySyntaxMap = sourcekitd_uid_get_from_cstr("key.syntaxmap"); KeySyntaxMap = sourcekitd_uid_get_from_cstr("key.syntaxmap");
@@ -879,6 +882,8 @@ static void printCursorInfo(sourcekitd_variant_t Info, StringRef FilenameIn,
bool IsSystem = sourcekitd_variant_dictionary_get_bool(Info, KeyIsSystem); bool IsSystem = sourcekitd_variant_dictionary_get_bool(Info, KeyIsSystem);
const char *AnnotDecl = sourcekitd_variant_dictionary_get_string(Info, const char *AnnotDecl = sourcekitd_variant_dictionary_get_string(Info,
KeyAnnotatedDecl); KeyAnnotatedDecl);
const char *FullAnnotDecl =
sourcekitd_variant_dictionary_get_string(Info, KeyFullyAnnotatedDecl);
const char *DocFullAsXML = const char *DocFullAsXML =
sourcekitd_variant_dictionary_get_string(Info, KeyDocFullAsXML); sourcekitd_variant_dictionary_get_string(Info, KeyDocFullAsXML);
sourcekitd_variant_t OffsetObj = sourcekitd_variant_t OffsetObj =
@@ -937,6 +942,8 @@ static void printCursorInfo(sourcekitd_variant_t Info, StringRef FilenameIn,
OS << "SYSTEM\n"; OS << "SYSTEM\n";
if (AnnotDecl) if (AnnotDecl)
OS << AnnotDecl << '\n'; OS << AnnotDecl << '\n';
if (FullAnnotDecl)
OS << FullAnnotDecl << '\n';
if (DocFullAsXML) if (DocFullAsXML)
OS << DocFullAsXML << '\n'; OS << DocFullAsXML << '\n';
OS << "OVERRIDES BEGIN\n"; OS << "OVERRIDES BEGIN\n";

View File

@@ -56,6 +56,7 @@ extern SourceKit::UIdent KeyDocFullAsXML;
extern SourceKit::UIdent KeyGenericParams; extern SourceKit::UIdent KeyGenericParams;
extern SourceKit::UIdent KeyGenericRequirements; extern SourceKit::UIdent KeyGenericRequirements;
extern SourceKit::UIdent KeyAnnotatedDecl; extern SourceKit::UIdent KeyAnnotatedDecl;
extern SourceKit::UIdent KeyFullyAnnotatedDecl;
extern SourceKit::UIdent KeyRelatedDecls; extern SourceKit::UIdent KeyRelatedDecls;
extern SourceKit::UIdent KeyContext; extern SourceKit::UIdent KeyContext;
extern SourceKit::UIdent KeyModuleImportDepth; extern SourceKit::UIdent KeyModuleImportDepth;

View File

@@ -1123,6 +1123,8 @@ static void reportCursorInfo(StringRef Filename,
Elem.set(KeyDocFullAsXML, Info.DocComment); Elem.set(KeyDocFullAsXML, Info.DocComment);
if (!Info.AnnotatedDeclaration.empty()) if (!Info.AnnotatedDeclaration.empty())
Elem.set(KeyAnnotatedDecl, Info.AnnotatedDeclaration); Elem.set(KeyAnnotatedDecl, Info.AnnotatedDeclaration);
if (!Info.FullyAnnotatedDeclaration.empty())
Elem.set(KeyFullyAnnotatedDecl, Info.FullyAnnotatedDeclaration);
if (!Info.ModuleName.empty()) if (!Info.ModuleName.empty())
Elem.set(KeyModuleName, Info.ModuleName); Elem.set(KeyModuleName, Info.ModuleName);
if (!Info.GroupName.empty()) if (!Info.GroupName.empty())

View File

@@ -69,6 +69,7 @@ UIdent sourcekitd::KeyDocFullAsXML("key.doc.full_as_xml");
UIdent sourcekitd::KeyGenericParams("key.generic_params"); UIdent sourcekitd::KeyGenericParams("key.generic_params");
UIdent sourcekitd::KeyGenericRequirements("key.generic_requirements"); UIdent sourcekitd::KeyGenericRequirements("key.generic_requirements");
UIdent sourcekitd::KeyAnnotatedDecl("key.annotated_decl"); UIdent sourcekitd::KeyAnnotatedDecl("key.annotated_decl");
UIdent sourcekitd::KeyFullyAnnotatedDecl("key.fully_annotated_decl");
UIdent sourcekitd::KeyRelatedDecls("key.related_decls"); UIdent sourcekitd::KeyRelatedDecls("key.related_decls");
UIdent sourcekitd::KeyContext("key.context"); UIdent sourcekitd::KeyContext("key.context");
UIdent sourcekitd::KeyModuleImportDepth("key.moduleimportdepth"); UIdent sourcekitd::KeyModuleImportDepth("key.moduleimportdepth");
@@ -158,6 +159,7 @@ static UIdent *OrderedKeys[] = {
&KeyRuntimeName, &KeyRuntimeName,
&KeySelectorName, &KeySelectorName,
&KeyAnnotatedDecl, &KeyAnnotatedDecl,
&KeyFullyAnnotatedDecl,
&KeyDocBrief, &KeyDocBrief,
&KeyContext, &KeyContext,
&KeyModuleImportDepth, &KeyModuleImportDepth,