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:
@@ -22,6 +22,8 @@ class IndexDataConsumer {
|
||||
virtual void anchor();
|
||||
|
||||
public:
|
||||
enum Action {Skip, Abort, Continue};
|
||||
|
||||
virtual ~IndexDataConsumer() {}
|
||||
|
||||
virtual void failed(StringRef error) = 0;
|
||||
@@ -32,8 +34,7 @@ public:
|
||||
virtual bool startDependency(SymbolKind kind, StringRef name, StringRef path,
|
||||
bool isSystem, StringRef hash) = 0;
|
||||
virtual bool finishDependency(SymbolKind kind) = 0;
|
||||
virtual bool startSourceEntity(const IndexSymbol &symbol) = 0;
|
||||
virtual bool recordRelatedEntity(const IndexSymbol &symbol) = 0;
|
||||
virtual Action startSourceEntity(const IndexSymbol &symbol) = 0;
|
||||
virtual bool finishSourceEntity(SymbolKind kind, SymbolSubKindSet subKinds,
|
||||
SymbolRoleSet roles) = 0;
|
||||
|
||||
|
||||
@@ -92,25 +92,48 @@ inline SymbolSubKindSet &operator|=(SymbolSubKindSet &SKSet, SymbolSubKind SK) {
|
||||
using SymbolRole = clang::index::SymbolRole;
|
||||
using SymbolRoleSet = clang::index::SymbolRoleSet;
|
||||
|
||||
struct IndexSymbol {
|
||||
struct IndexRelation {
|
||||
const ValueDecl *decl;
|
||||
SymbolKind kind;
|
||||
SymbolSubKindSet subKinds = SymbolSubKindSet(0);
|
||||
SymbolRoleSet roles = SymbolRoleSet(0);
|
||||
|
||||
// The following strings are guaranteed to live at least as long as the
|
||||
// current indexing action.
|
||||
StringRef name;
|
||||
StringRef USR; // USR may be safely compared by pointer.
|
||||
StringRef group;
|
||||
StringRef receiverUSR;
|
||||
|
||||
IndexRelation(SymbolRoleSet Roles, const ValueDecl *Sym, SymbolKind Kind, SymbolSubKindSet SubKinds, StringRef Name, StringRef USR)
|
||||
: decl(Sym), kind(Kind), subKinds(SubKinds), roles(Roles), name(Name), USR(USR) {}
|
||||
|
||||
IndexRelation() = default;
|
||||
};
|
||||
|
||||
struct IndexSymbol : IndexRelation {
|
||||
SmallVector<IndexRelation, 3> Relations;
|
||||
unsigned line = 0;
|
||||
unsigned column = 0;
|
||||
|
||||
IndexSymbol() = default;
|
||||
|
||||
StringRef getReceiverUSR() const {
|
||||
for(auto Relation: Relations) {
|
||||
if (Relation.roles & (SymbolRoleSet) SymbolRole::RelationReceivedBy)
|
||||
return Relation.USR;
|
||||
}
|
||||
return StringRef();
|
||||
}
|
||||
};
|
||||
|
||||
SymbolKind getSymbolKindForDecl(const Decl *D);
|
||||
|
||||
StringRef getSymbolKindString(SymbolKind K);
|
||||
|
||||
void applyForEachSymbolSubKind(SymbolSubKindSet SubKinds,
|
||||
llvm::function_ref<void(SymbolSubKind)> Fn);
|
||||
void printSymbolSubKinds(SymbolSubKindSet SubKinds, raw_ostream &OS);
|
||||
|
||||
} // end namespace index
|
||||
} // end namespace swift
|
||||
|
||||
|
||||
Reference in New Issue
Block a user