Skip to content

Commit 1aee0af

Browse files
committed
[SymbolGraph] Output custom attributes
Custom attributes were being skipped as their attribute name started with a "_". Underscored attributes are typically unstable and thus shouldn't be printed, but "_" is not being used for that purpose in the case of "_custom". Rather than checking for "_" or "__", just use `UserInaccessible`. This property is used for attributes that shouldn't be shown to users in eg. completion/printing/etc. Resolves rdar://99029554.
1 parent 052a77e commit 1aee0af

File tree

3 files changed

+70
-3
lines changed

3 files changed

+70
-3
lines changed

lib/SymbolGraphGen/SymbolGraph.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@ PrintOptions SymbolGraph::getDeclarationFragmentsPrintOptions() const {
7272

7373
llvm::StringMap<AnyAttrKind> ExcludeAttrs;
7474

75-
#define DECL_ATTR(SPELLING, CLASS, OPTIONS, CODE) \
76-
if (StringRef(#SPELLING).startswith("_")) \
77-
ExcludeAttrs.insert(std::make_pair("DAK_" #CLASS, DAK_##CLASS));
7875
#define TYPE_ATTR(X) ExcludeAttrs.insert(std::make_pair("TAK_" #X, TAK_##X));
7976
#include "swift/AST/Attr.def"
8077

@@ -98,6 +95,7 @@ PrintOptions SymbolGraph::getDeclarationFragmentsPrintOptions() const {
9895
// In "emit modules separately" jobs, access modifiers show up as attributes,
9996
// but we don't want them to be printed in declarations
10097
ExcludeAttrs.insert(std::make_pair("DAK_AccessControl", DAK_AccessControl));
98+
ExcludeAttrs.insert(std::make_pair("DAK_SetterAccess", DAK_SetterAccess));
10199

102100
for (const auto &Entry : ExcludeAttrs) {
103101
Opts.ExcludeAttrList.push_back(Entry.getValue());

test/IDE/print_set_accessor.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
public struct SomeType {
2+
public private(set) var privateSetter: Int
3+
}
4+
// CHECK: public private(set) var privateSetter: Int
5+
6+
// RUN: %target-swift-ide-test -print-swift-file-interface -source-filename %s | %FileCheck %s
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift %s -module-name CustomAttr -emit-module -emit-module-path %t/
3+
// RUN: %target-swift-symbolgraph-extract -module-name CustomAttr -I %t -pretty-print -output-dir %t
4+
// RUN: %FileCheck %s --input-file %t/CustomAttr.symbols.json
5+
6+
@propertyWrapper
7+
public struct SomeWrapper {
8+
public var wrappedValue: Int { 0 }
9+
public init(wrappedValue: Int) {}
10+
}
11+
12+
public func wrapped(@SomeWrapper arg: Int) {}
13+
14+
// CHECK-LABEL: "precise": "s:10CustomAttr7wrapped3argySi_tF"
15+
// CHECK: "declarationFragments": [
16+
// CHECK: "declarationFragments": [
17+
// CHECK-NEXT: {
18+
// CHECK-NEXT: "kind": "keyword",
19+
// CHECK-NEXT: "spelling": "func"
20+
// CHECK-NEXT: },
21+
// CHECK-NEXT: {
22+
// CHECK-NEXT: "kind": "text",
23+
// CHECK-NEXT: "spelling": " "
24+
// CHECK-NEXT: },
25+
// CHECK-NEXT: {
26+
// CHECK-NEXT: "kind": "identifier",
27+
// CHECK-NEXT: "spelling": "wrapped"
28+
// CHECK-NEXT: },
29+
// CHECK-NEXT: {
30+
// CHECK-NEXT: "kind": "text",
31+
// CHECK-NEXT: "spelling": "("
32+
// CHECK-NEXT: },
33+
// CHECK-NEXT: {
34+
// CHECK-NEXT: "kind": "attribute",
35+
// CHECK-NEXT: "spelling": "@"
36+
// CHECK-NEXT: },
37+
// CHECK-NEXT: {
38+
// CHECK-NEXT: "kind": "typeIdentifier",
39+
// CHECK-NEXT: "spelling": "SomeWrapper",
40+
// CHECK-NEXT: "preciseIdentifier": "s:10CustomAttr11SomeWrapperV"
41+
// CHECK-NEXT: },
42+
// CHECK-NEXT: {
43+
// CHECK-NEXT: "kind": "text",
44+
// CHECK-NEXT: "spelling": " "
45+
// CHECK-NEXT: },
46+
// CHECK-NEXT: {
47+
// CHECK-NEXT: "kind": "externalParam",
48+
// CHECK-NEXT: "spelling": "arg"
49+
// CHECK-NEXT: },
50+
// CHECK-NEXT: {
51+
// CHECK-NEXT: "kind": "text",
52+
// CHECK-NEXT: "spelling": ": "
53+
// CHECK-NEXT: },
54+
// CHECK-NEXT: {
55+
// CHECK-NEXT: "kind": "typeIdentifier",
56+
// CHECK-NEXT: "spelling": "Int",
57+
// CHECK-NEXT: "preciseIdentifier": "s:Si"
58+
// CHECK-NEXT: },
59+
// CHECK-NEXT: {
60+
// CHECK-NEXT: "kind": "text",
61+
// CHECK-NEXT: "spelling": ")"
62+
// CHECK-NEXT: }
63+
// CHECK-NEXT:]

0 commit comments

Comments
 (0)