Skip to content

Store symbol byte offset in IndexSymbol #26858

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 28, 2019
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/swift/Index/IndexSymbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ struct IndexSymbol : IndexRelation {
SmallVector<IndexRelation, 3> Relations;
unsigned line = 0;
unsigned column = 0;
llvm::Optional<unsigned> offset;

IndexSymbol() = default;

Expand Down
21 changes: 12 additions & 9 deletions lib/Index/Index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FileSystem.h"
#include <tuple>

using namespace swift;
using namespace swift::index;
Expand Down Expand Up @@ -472,7 +473,7 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
return true;

IndexSymbol Info;
std::tie(Info.line, Info.column) = getLineCol(Loc);
std::tie(Info.line, Info.column, Info.offset) = getLineColAndOffset(Loc);
Info.roles |= (unsigned)SymbolRole::Reference;
Info.symInfo = getSymbolInfoForModule(Mod);
getModuleNameAndUSR(Mod, Info.name, Info.USR);
Expand Down Expand Up @@ -584,10 +585,12 @@ class IndexSwiftASTWalker : public SourceEntityWalker {

bool indexComment(const Decl *D);

std::pair<unsigned, unsigned> getLineCol(SourceLoc Loc) {
std::tuple<unsigned, unsigned, unsigned> getLineColAndOffset(SourceLoc Loc) {
if (Loc.isInvalid())
return std::make_pair(0, 0);
return SrcMgr.getLineAndColumn(Loc, BufferID);
return std::make_tuple(0, 0, 0);
auto lineAndColumn = SrcMgr.getLineAndColumn(Loc, BufferID);
unsigned offset = SrcMgr.getLocOffsetInBuffer(Loc, BufferID);
return std::make_tuple(lineAndColumn.first, lineAndColumn.second, offset);
}

bool shouldIndex(ValueDecl *D, bool IsRef) const {
Expand Down Expand Up @@ -1079,7 +1082,7 @@ bool IndexSwiftASTWalker::report(ValueDecl *D) {
return false;
if (!reportPseudoSetterDecl(VarD))
return false;
}
}

for (auto accessor : StoreD->getAllAccessors()) {
// Don't include the implicit getter and setter if we added pseudo
Expand Down Expand Up @@ -1224,7 +1227,7 @@ bool IndexSwiftASTWalker::initIndexSymbol(ValueDecl *D, SourceLoc Loc,
if (getNameAndUSR(D, /*ExtD=*/nullptr, Info.name, Info.USR))
return true;

std::tie(Info.line, Info.column) = getLineCol(Loc);
std::tie(Info.line, Info.column, Info.offset) = getLineColAndOffset(Loc);
if (!IsRef) {
if (auto Group = D->getGroupName())
Info.group = Group.getValue();
Expand All @@ -1245,7 +1248,7 @@ bool IndexSwiftASTWalker::initIndexSymbol(ExtensionDecl *ExtD, ValueDecl *Extend
if (getNameAndUSR(ExtendedD, ExtD, Info.name, Info.USR))
return true;

std::tie(Info.line, Info.column) = getLineCol(Loc);
std::tie(Info.line, Info.column, Info.offset) = getLineColAndOffset(Loc);
if (auto Group = ExtD->getGroupName())
Info.group = Group.getValue();
return false;
Expand Down Expand Up @@ -1401,7 +1404,7 @@ bool IndexSwiftASTWalker::initVarRefIndexSymbols(Expr *CurrentE, ValueDecl *D,
case swift::AccessKind::Write:
Info.roles |= (unsigned)SymbolRole::Write;
}

return false;
}

Expand Down Expand Up @@ -1452,7 +1455,7 @@ bool IndexSwiftASTWalker::indexComment(const Decl *D) {
OS << "t:" << tagName;
Info.USR = stringStorage.copyString(OS.str());
}
std::tie(Info.line, Info.column) = getLineCol(loc);
std::tie(Info.line, Info.column, Info.offset) = getLineColAndOffset(loc);
if (!IdxConsumer.startSourceEntity(Info) || !IdxConsumer.finishSourceEntity(Info.symInfo, Info.roles)) {
Cancelled = true;
break;
Expand Down