30
30
#include " llvm/ADT/SmallVector.h"
31
31
#include " llvm/Support/ErrorHandling.h"
32
32
#include " llvm/Support/FileSystem.h"
33
+ #include < tuple>
33
34
34
35
using namespace swift ;
35
36
using namespace swift ::index;
@@ -475,7 +476,7 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
475
476
return true ;
476
477
477
478
IndexSymbol Info;
478
- std::tie (Info.line , Info.column ) = getLineCol (Loc);
479
+ std::tie (Info.line , Info.column , Info. offset ) = getLineColAndOffset (Loc);
479
480
Info.roles |= (unsigned )SymbolRole::Reference;
480
481
Info.symInfo = getSymbolInfoForModule (Mod);
481
482
getModuleNameAndUSR (Mod, Info.name , Info.USR );
@@ -587,10 +588,13 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
587
588
588
589
bool indexComment (const Decl *D);
589
590
590
- std::pair<unsigned , unsigned > getLineCol (SourceLoc Loc) {
591
+ std::tuple<unsigned , unsigned , Optional<unsigned >>
592
+ getLineColAndOffset (SourceLoc Loc) {
591
593
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);
594
598
}
595
599
596
600
bool shouldIndex (ValueDecl *D, bool IsRef) const {
@@ -1082,7 +1086,7 @@ bool IndexSwiftASTWalker::report(ValueDecl *D) {
1082
1086
return false ;
1083
1087
if (!reportPseudoSetterDecl (VarD))
1084
1088
return false ;
1085
- }
1089
+ }
1086
1090
1087
1091
for (auto accessor : StoreD->getAllAccessors ()) {
1088
1092
// Don't include the implicit getter and setter if we added pseudo
@@ -1227,7 +1231,7 @@ bool IndexSwiftASTWalker::initIndexSymbol(ValueDecl *D, SourceLoc Loc,
1227
1231
if (getNameAndUSR (D, /* ExtD=*/ nullptr , Info.name , Info.USR ))
1228
1232
return true ;
1229
1233
1230
- std::tie (Info.line , Info.column ) = getLineCol (Loc);
1234
+ std::tie (Info.line , Info.column , Info. offset ) = getLineColAndOffset (Loc);
1231
1235
if (!IsRef) {
1232
1236
if (auto Group = D->getGroupName ())
1233
1237
Info.group = Group.getValue ();
@@ -1248,7 +1252,7 @@ bool IndexSwiftASTWalker::initIndexSymbol(ExtensionDecl *ExtD, ValueDecl *Extend
1248
1252
if (getNameAndUSR (ExtendedD, ExtD, Info.name , Info.USR ))
1249
1253
return true ;
1250
1254
1251
- std::tie (Info.line , Info.column ) = getLineCol (Loc);
1255
+ std::tie (Info.line , Info.column , Info. offset ) = getLineColAndOffset (Loc);
1252
1256
if (auto Group = ExtD->getGroupName ())
1253
1257
Info.group = Group.getValue ();
1254
1258
return false ;
@@ -1404,7 +1408,7 @@ bool IndexSwiftASTWalker::initVarRefIndexSymbols(Expr *CurrentE, ValueDecl *D,
1404
1408
case swift::AccessKind::Write:
1405
1409
Info.roles |= (unsigned )SymbolRole::Write;
1406
1410
}
1407
-
1411
+
1408
1412
return false ;
1409
1413
}
1410
1414
@@ -1455,7 +1459,7 @@ bool IndexSwiftASTWalker::indexComment(const Decl *D) {
1455
1459
OS << " t:" << tagName;
1456
1460
Info.USR = stringStorage.copyString (OS.str ());
1457
1461
}
1458
- std::tie (Info.line , Info.column ) = getLineCol (loc);
1462
+ std::tie (Info.line , Info.column , Info. offset ) = getLineColAndOffset (loc);
1459
1463
if (!IdxConsumer.startSourceEntity (Info) || !IdxConsumer.finishSourceEntity (Info.symInfo , Info.roles )) {
1460
1464
Cancelled = true ;
1461
1465
break ;
0 commit comments