Skip to content

Commit c073e62

Browse files
authored
Merge pull request #26858 from mwyman/master
2 parents 8fcc94f + 70e3893 commit c073e62

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

include/swift/Index/IndexSymbol.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ struct IndexSymbol : IndexRelation {
6666
SmallVector<IndexRelation, 3> Relations;
6767
unsigned line = 0;
6868
unsigned column = 0;
69+
Optional<unsigned> offset;
6970

7071
IndexSymbol() = default;
7172

lib/Index/Index.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "llvm/ADT/SmallVector.h"
3131
#include "llvm/Support/ErrorHandling.h"
3232
#include "llvm/Support/FileSystem.h"
33+
#include <tuple>
3334

3435
using namespace swift;
3536
using namespace swift::index;
@@ -475,7 +476,7 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
475476
return true;
476477

477478
IndexSymbol Info;
478-
std::tie(Info.line, Info.column) = getLineCol(Loc);
479+
std::tie(Info.line, Info.column, Info.offset) = getLineColAndOffset(Loc);
479480
Info.roles |= (unsigned)SymbolRole::Reference;
480481
Info.symInfo = getSymbolInfoForModule(Mod);
481482
getModuleNameAndUSR(Mod, Info.name, Info.USR);
@@ -587,10 +588,13 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
587588

588589
bool indexComment(const Decl *D);
589590

590-
std::pair<unsigned, unsigned> getLineCol(SourceLoc Loc) {
591+
std::tuple<unsigned, unsigned, Optional<unsigned>>
592+
getLineColAndOffset(SourceLoc Loc) {
591593
if (Loc.isInvalid())
592-
return std::make_pair(0, 0);
593-
return SrcMgr.getLineAndColumn(Loc, BufferID);
594+
return std::make_tuple(0, 0, None);
595+
auto lineAndColumn = SrcMgr.getLineAndColumn(Loc, BufferID);
596+
unsigned offset = SrcMgr.getLocOffsetInBuffer(Loc, BufferID);
597+
return std::make_tuple(lineAndColumn.first, lineAndColumn.second, offset);
594598
}
595599

596600
bool shouldIndex(ValueDecl *D, bool IsRef) const {
@@ -1082,7 +1086,7 @@ bool IndexSwiftASTWalker::report(ValueDecl *D) {
10821086
return false;
10831087
if (!reportPseudoSetterDecl(VarD))
10841088
return false;
1085-
}
1089+
}
10861090

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

1230-
std::tie(Info.line, Info.column) = getLineCol(Loc);
1234+
std::tie(Info.line, Info.column, Info.offset) = getLineColAndOffset(Loc);
12311235
if (!IsRef) {
12321236
if (auto Group = D->getGroupName())
12331237
Info.group = Group.getValue();
@@ -1248,7 +1252,7 @@ bool IndexSwiftASTWalker::initIndexSymbol(ExtensionDecl *ExtD, ValueDecl *Extend
12481252
if (getNameAndUSR(ExtendedD, ExtD, Info.name, Info.USR))
12491253
return true;
12501254

1251-
std::tie(Info.line, Info.column) = getLineCol(Loc);
1255+
std::tie(Info.line, Info.column, Info.offset) = getLineColAndOffset(Loc);
12521256
if (auto Group = ExtD->getGroupName())
12531257
Info.group = Group.getValue();
12541258
return false;
@@ -1404,7 +1408,7 @@ bool IndexSwiftASTWalker::initVarRefIndexSymbols(Expr *CurrentE, ValueDecl *D,
14041408
case swift::AccessKind::Write:
14051409
Info.roles |= (unsigned)SymbolRole::Write;
14061410
}
1407-
1411+
14081412
return false;
14091413
}
14101414

@@ -1455,7 +1459,7 @@ bool IndexSwiftASTWalker::indexComment(const Decl *D) {
14551459
OS << "t:" << tagName;
14561460
Info.USR = stringStorage.copyString(OS.str());
14571461
}
1458-
std::tie(Info.line, Info.column) = getLineCol(loc);
1462+
std::tie(Info.line, Info.column, Info.offset) = getLineColAndOffset(loc);
14591463
if (!IdxConsumer.startSourceEntity(Info) || !IdxConsumer.finishSourceEntity(Info.symInfo, Info.roles)) {
14601464
Cancelled = true;
14611465
break;

0 commit comments

Comments
 (0)