mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Merge pull request #6677 from nathawes/swift-indexing
Add roles and relations for Swift indexing
This commit is contained in:
@@ -71,16 +71,36 @@ private:
|
||||
return impl.finishDependency(getUIDForDependencyKind(kind));
|
||||
}
|
||||
|
||||
bool startSourceEntity(const IndexSymbol &symbol) override {
|
||||
return withEntityInfo(symbol, [this](const EntityInfo &info) {
|
||||
return impl.startSourceEntity(info);
|
||||
});
|
||||
}
|
||||
Action startSourceEntity(const IndexSymbol &symbol) override {
|
||||
|
||||
bool recordRelatedEntity(const IndexSymbol &symbol) override {
|
||||
return withEntityInfo(symbol, [this](const EntityInfo &info) {
|
||||
return impl.recordRelatedEntity(info);
|
||||
});
|
||||
// report any parent relations to this reference
|
||||
if (symbol.roles & (SymbolRoleSet)SymbolRole::RelationBaseOf) {
|
||||
withEntityInfo(symbol, [this](const EntityInfo &info) {
|
||||
return impl.recordRelatedEntity(info);
|
||||
});
|
||||
}
|
||||
|
||||
// filter out references with invalid locations
|
||||
if (symbol.roles & (SymbolRoleSet)SymbolRole::Reference &&
|
||||
(symbol.line == 0 || symbol.column == 0))
|
||||
return Skip;
|
||||
|
||||
|
||||
// start the entity (ref or def)
|
||||
if(!withEntityInfo(symbol, [this](const EntityInfo &info) {
|
||||
return impl.startSourceEntity(info);
|
||||
})) return Abort;
|
||||
|
||||
|
||||
// report relations this occurrence has
|
||||
for (auto Relation: symbol.Relations) {
|
||||
if (Relation.roles & (SymbolRoleSet)SymbolRole::RelationOverrideOf) {
|
||||
if (!withEntityInfo(Relation, [this](const EntityInfo &info) {
|
||||
return impl.recordRelatedEntity(info);
|
||||
})) return Abort;
|
||||
}
|
||||
}
|
||||
return Continue;
|
||||
}
|
||||
|
||||
bool finishSourceEntity(SymbolKind kind, SymbolSubKindSet subKinds,
|
||||
@@ -94,14 +114,16 @@ private:
|
||||
bool withEntityInfo(const IndexSymbol &symbol, F func) {
|
||||
EntityInfo info;
|
||||
bool isRef = symbol.roles & (unsigned)SymbolRole::Reference;
|
||||
bool isImplicit = symbol.roles & (unsigned)SymbolRole::Implicit;
|
||||
|
||||
info.Kind = SwiftLangSupport::getUIDForSymbol(symbol.kind, symbol.subKinds,
|
||||
isRef);
|
||||
info.Name = symbol.name;
|
||||
info.Name = isImplicit? "" : symbol.name;
|
||||
info.USR = symbol.USR;
|
||||
info.Group = symbol.group;
|
||||
info.Line = symbol.line;
|
||||
info.Column = symbol.column;
|
||||
info.ReceiverUSR = symbol.receiverUSR;
|
||||
info.ReceiverUSR = symbol.getReceiverUSR();
|
||||
info.IsDynamic = symbol.roles & (unsigned)SymbolRole::Dynamic;
|
||||
info.IsTestCandidate = symbol.subKinds & SymbolSubKind::UnitTest;
|
||||
std::vector<UIdent> uidAttrs;
|
||||
@@ -113,6 +135,27 @@ private:
|
||||
return func(info);
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
bool withEntityInfo(const IndexRelation &relation, F func) {
|
||||
EntityInfo info;
|
||||
bool isRef = (relation.roles & (unsigned)SymbolRole::Reference) ||
|
||||
(relation.roles & (unsigned)SymbolRole::RelationOverrideOf);
|
||||
info.Kind = SwiftLangSupport::getUIDForSymbol(relation.kind, relation.subKinds,
|
||||
isRef);
|
||||
info.Name = relation.name;
|
||||
info.USR = relation.USR;
|
||||
info.Group = relation.group;
|
||||
info.IsDynamic = relation.roles & (unsigned)SymbolRole::Dynamic;
|
||||
info.IsTestCandidate = relation.subKinds & SymbolSubKind::UnitTest;
|
||||
std::vector<UIdent> uidAttrs;
|
||||
if (!isRef) {
|
||||
uidAttrs =
|
||||
SwiftLangSupport::UIDsFromDeclAttributes(relation.decl->getAttrs());
|
||||
info.Attrs = uidAttrs;
|
||||
}
|
||||
return func(info);
|
||||
}
|
||||
|
||||
private:
|
||||
IndexingConsumer &impl;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user