Skip to content

Commit ec04246

Browse files
committed
[SourceKit] Report attributes of decls for the indexing request.
1 parent c78f169 commit ec04246

File tree

6 files changed

+61
-3
lines changed

6 files changed

+61
-3
lines changed

include/swift/Index/IndexSymbol.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
namespace swift {
2121
class Decl;
22+
class ValueDecl;
2223

2324
namespace index {
2425

@@ -92,6 +93,7 @@ using SymbolRole = clang::index::SymbolRole;
9293
using SymbolRoleSet = clang::index::SymbolRoleSet;
9394

9495
struct IndexSymbol {
96+
const ValueDecl *decl;
9597
SymbolKind kind;
9698
SymbolSubKindSet subKinds = SymbolSubKindSet(0);
9799
SymbolRoleSet roles = SymbolRoleSet(0);

lib/Index/Index.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,7 @@ bool IndexSwiftASTWalker::reportRef(ValueDecl *D, SourceLoc Loc) {
761761
bool IndexSwiftASTWalker::initIndexSymbol(ValueDecl *D, SourceLoc Loc,
762762
bool IsRef, IndexSymbol &Info) {
763763
assert(D);
764+
Info.decl = D;
764765
Info.kind = getSymbolKindForDecl(D);
765766
if (Info.kind == SymbolKind::Unknown)
766767
return true;

test/SourceKit/Indexing/index.swift.response

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,11 @@
676676
key.line: 77,
677677
key.column: 31
678678
}
679+
],
680+
key.attributes: [
681+
{
682+
key.attribute: source.decl.attribute.override
683+
}
679684
]
680685
}
681686
]
@@ -1052,6 +1057,11 @@
10521057
key.column: 11,
10531058
key.receiver_usr: "s:C5index2B1"
10541059
}
1060+
],
1061+
key.attributes: [
1062+
{
1063+
key.attribute: source.decl.attribute.override
1064+
}
10551065
]
10561066
}
10571067
]
@@ -1228,6 +1238,11 @@
12281238
key.receiver_usr: "s:C5index3CC4",
12291239
key.is_dynamic: 1
12301240
}
1241+
],
1242+
key.attributes: [
1243+
{
1244+
key.attribute: source.decl.attribute.convenience
1245+
}
12311246
]
12321247
}
12331248
]
@@ -1323,6 +1338,11 @@
13231338
key.line: 169,
13241339
key.column: 7
13251340
}
1341+
],
1342+
key.attributes: [
1343+
{
1344+
key.attribute: source.decl.attribute.final
1345+
}
13261346
]
13271347
},
13281348
{
@@ -1338,6 +1358,11 @@
13381358
key.line: 172,
13391359
key.column: 7
13401360
}
1361+
],
1362+
key.attributes: [
1363+
{
1364+
key.attribute: source.decl.attribute.final
1365+
}
13411366
]
13421367
}
13431368
]
@@ -1370,7 +1395,12 @@
13701395
key.kind: source.lang.swift.decl.function.accessor.didset,
13711396
key.usr: "s:FC5index12rdar18640140W2S1Si",
13721397
key.line: 186,
1373-
key.column: 5
1398+
key.column: 5,
1399+
key.attributes: [
1400+
{
1401+
key.attribute: source.decl.attribute.final
1402+
}
1403+
]
13741404
}
13751405
]
13761406
},
@@ -1427,14 +1457,24 @@
14271457
key.name: "ConditionalUnavailableClass1",
14281458
key.usr: "s:C5index28ConditionalUnavailableClass1",
14291459
key.line: 204,
1430-
key.column: 7
1460+
key.column: 7,
1461+
key.attributes: [
1462+
{
1463+
key.attribute: source.decl.attribute.available
1464+
}
1465+
]
14311466
},
14321467
{
14331468
key.kind: source.lang.swift.decl.class,
14341469
key.name: "ConditionalUnavailableClass2",
14351470
key.usr: "s:C5index28ConditionalUnavailableClass2",
14361471
key.line: 208,
1437-
key.column: 7
1472+
key.column: 7,
1473+
key.attributes: [
1474+
{
1475+
key.attribute: source.decl.attribute.available
1476+
}
1477+
]
14381478
}
14391479
]
14401480
}

tools/SourceKit/include/SourceKit/Core/LangSupport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ struct EntityInfo {
3939
bool IsTestCandidate = false;
4040
unsigned Line = 0;
4141
unsigned Column = 0;
42+
ArrayRef<UIdent> Attrs;
4243

4344
EntityInfo() = default;
4445
};

tools/SourceKit/lib/SwiftLang/SwiftIndexing.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ class SKIndexDataConsumer : public IndexDataConsumer {
104104
info.ReceiverUSR = symbol.receiverUSR;
105105
info.IsDynamic = symbol.roles & (unsigned)SymbolRole::Dynamic;
106106
info.IsTestCandidate = symbol.subKinds & SymbolSubKind::UnitTest;
107+
std::vector<UIdent> uidAttrs;
108+
if (!isRef) {
109+
uidAttrs =
110+
SwiftLangSupport::UIDsFromDeclAttributes(symbol.decl->getAttrs());
111+
info.Attrs = uidAttrs;
112+
}
107113
return func(info);
108114
}
109115

tools/SourceKit/tools/sourcekitd/lib/API/Requests.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,14 @@ bool SKIndexingConsumer::startSourceEntity(const EntityInfo &Info) {
889889
if (Info.IsTestCandidate)
890890
Elem.setBool(KeyIsTestCandidate, true);
891891

892+
if (!Info.Attrs.empty()) {
893+
auto AttrArray = Elem.setArray(KeyAttributes);
894+
for (auto Attr : Info.Attrs) {
895+
auto AttrDict = AttrArray.appendDictionary();
896+
AttrDict.set(KeyAttribute, Attr);
897+
}
898+
}
899+
892900
EntitiesStack.push_back({ Info.Kind, Elem, ResponseBuilder::Array(),
893901
ResponseBuilder::Array()});
894902
return true;

0 commit comments

Comments
 (0)