Skip to content

Commit 0f80619

Browse files
[SymbolGraphGen] allow SourceKit to print declarations for private stdlib symbols (#64556)
Resolves rdar://103112656 Resolves #62457
1 parent bb8470f commit 0f80619

File tree

4 files changed

+57
-2
lines changed

4 files changed

+57
-2
lines changed

include/swift/SymbolGraphGen/SymbolGraphOptions.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ struct SymbolGraphOptions {
5757
/// along with "extensionTo" relationships instead of directly associating
5858
/// members and conformances with the extended nominal.
5959
bool EmitExtensionBlockSymbols = false;
60+
61+
/// Whether to print information for private symbols in the standard library.
62+
/// This should be left as `false` when printing a full-module symbol graph,
63+
/// but SourceKit should be able to load the information when pulling symbol
64+
/// information for individual queries.
65+
bool PrintPrivateStdlibSymbols = false;
6066
};
6167

6268
} // end namespace symbolgraphgen

lib/SymbolGraphGen/SymbolGraph.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ PrintOptions SymbolGraph::getDeclarationFragmentsPrintOptions() const {
6363
Opts.PrintFunctionRepresentationAttrs =
6464
PrintOptions::FunctionRepresentationMode::None;
6565
Opts.PrintUserInaccessibleAttrs = false;
66-
Opts.SkipPrivateStdlibDecls = true;
67-
Opts.SkipUnderscoredStdlibProtocols = true;
66+
Opts.SkipPrivateStdlibDecls = !Walker.Options.PrintPrivateStdlibSymbols;
67+
Opts.SkipUnderscoredStdlibProtocols = !Walker.Options.PrintPrivateStdlibSymbols;
6868
Opts.PrintGenericRequirements = true;
6969
Opts.PrintInherited = false;
7070
Opts.ExplodeEnumCaseDecls = true;
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
struct AnyError: Swift.Error {
2+
let error: Swift.Error
3+
}
4+
5+
func test(lhs: AnyError) {
6+
// RUN: %sourcekitd-test -req=cursor -req-opts=retrieve_symbol_graph=1 -pos=%(line + 1):13 %s -- %s | %FileCheck %s
7+
lhs.error._code
8+
}
9+
10+
// CHECK: SYMBOL GRAPH BEGIN
11+
12+
// CHECK: "declarationFragments": [
13+
// CHECK-NEXT: {
14+
// CHECK-NEXT: "kind": "keyword",
15+
// CHECK-NEXT: "spelling": "var"
16+
// CHECK-NEXT: },
17+
// CHECK-NEXT: {
18+
// CHECK-NEXT: "kind": "text",
19+
// CHECK-NEXT: "spelling": " "
20+
// CHECK-NEXT: },
21+
// CHECK-NEXT: {
22+
// CHECK-NEXT: "kind": "identifier",
23+
// CHECK-NEXT: "spelling": "_code"
24+
// CHECK-NEXT: },
25+
// CHECK-NEXT: {
26+
// CHECK-NEXT: "kind": "text",
27+
// CHECK-NEXT: "spelling": ": "
28+
// CHECK-NEXT: },
29+
// CHECK-NEXT: {
30+
// CHECK-NEXT: "kind": "typeIdentifier",
31+
// CHECK-NEXT: "preciseIdentifier": "s:Si",
32+
// CHECK-NEXT: "spelling": "Int"
33+
// CHECK-NEXT: },
34+
// CHECK-NEXT: {
35+
// CHECK-NEXT: "kind": "text",
36+
// CHECK-NEXT: "spelling": " { "
37+
// CHECK-NEXT: },
38+
// CHECK-NEXT: {
39+
// CHECK-NEXT: "kind": "keyword",
40+
// CHECK-NEXT: "spelling": "get"
41+
// CHECK-NEXT: },
42+
// CHECK-NEXT: {
43+
// CHECK-NEXT: "kind": "text",
44+
// CHECK-NEXT: "spelling": " }"
45+
// CHECK-NEXT: }
46+
// CHECK-NEXT: ]
47+
48+
// CHECK: SYMBOL GRAPH END

tools/SourceKit/lib/SwiftLang/SwiftSourceDocInfo.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,6 +1020,7 @@ fillSymbolInfo(CursorSymbolInfo &Symbol, const DeclInfo &DInfo,
10201020
Options.MinimumAccessLevel = AccessLevel::Private;
10211021
Options.IncludeSPISymbols = true;
10221022
Options.IncludeClangDocs = true;
1023+
Options.PrintPrivateStdlibSymbols = true;
10231024

10241025
symbolgraphgen::printSymbolGraphForDecl(DInfo.VD, DInfo.BaseType,
10251026
DInfo.InSynthesizedExtension,

0 commit comments

Comments
 (0)