@@ -834,7 +834,7 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
834
834
return true ;
835
835
836
836
IndexSymbol Info;
837
- std::tie (Info.line , Info.column , Info. offset ) = getLineColAndOffset (Loc);
837
+ std::tie (Info.line , Info.column ) = getLineCol (Loc);
838
838
Info.roles |= (unsigned )SymbolRole::Reference;
839
839
Info.symInfo = getSymbolInfoForModule (Mod);
840
840
getModuleNameAndUSR (Mod, Info.name , Info.USR );
@@ -949,13 +949,10 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
949
949
950
950
bool indexComment (const Decl *D);
951
951
952
- std::tuple<unsigned , unsigned , Optional<unsigned >>
953
- getLineColAndOffset (SourceLoc Loc) {
952
+ std::pair<unsigned , unsigned > getLineCol (SourceLoc Loc) {
954
953
if (Loc.isInvalid ())
955
- return std::make_tuple (0 , 0 , None);
956
- auto lineAndColumn = SrcMgr.getLineAndColumnInBuffer (Loc, BufferID);
957
- unsigned offset = SrcMgr.getLocOffsetInBuffer (Loc, BufferID);
958
- return std::make_tuple (lineAndColumn.first , lineAndColumn.second , offset);
954
+ return std::make_pair (0 , 0 );
955
+ return SrcMgr.getLineAndColumnInBuffer (Loc, BufferID);
959
956
}
960
957
961
958
bool shouldIndex (ValueDecl *D, bool IsRef) const {
@@ -1604,8 +1601,13 @@ bool IndexSwiftASTWalker::reportImplicitConformance(ValueDecl *witness, ValueDec
1604
1601
bool IndexSwiftASTWalker::initIndexSymbol (ValueDecl *D, SourceLoc Loc,
1605
1602
bool IsRef, IndexSymbol &Info) {
1606
1603
assert (D);
1604
+
1605
+ if (Loc.isInvalid () && !IsModuleFile)
1606
+ return true ;
1607
+
1607
1608
if (Loc.isValid () && SrcMgr.findBufferContainingLoc (Loc) != BufferID)
1608
1609
return true ;
1610
+
1609
1611
if (auto *VD = dyn_cast<VarDecl>(D)) {
1610
1612
// Always base the symbol information on the canonical VarDecl
1611
1613
D = VD->getCanonicalVarDecl ();
@@ -1618,23 +1620,21 @@ bool IndexSwiftASTWalker::initIndexSymbol(ValueDecl *D, SourceLoc Loc,
1618
1620
1619
1621
// Cannot be extension, which is not a ValueDecl.
1620
1622
1623
+ if (getNameAndUSR (D, /* ExtD=*/ nullptr , Info.name , Info.USR ))
1624
+ return true ;
1625
+ std::tie (Info.line , Info.column ) = getLineCol (Loc);
1626
+
1621
1627
if (IsRef) {
1622
1628
Info.roles |= (unsigned )SymbolRole::Reference;
1623
1629
addContainedByRelationIfContained (Info);
1624
1630
} else {
1625
1631
Info.roles |= (unsigned )SymbolRole::Definition;
1626
1632
if (D->isImplicit ())
1627
1633
Info.roles |= (unsigned )SymbolRole::Implicit;
1628
- }
1629
-
1630
- if (getNameAndUSR (D, /* ExtD=*/ nullptr , Info.name , Info.USR ))
1631
- return true ;
1632
-
1633
- std::tie (Info.line , Info.column , Info.offset ) = getLineColAndOffset (Loc);
1634
- if (!IsRef) {
1635
1634
if (auto Group = D->getGroupName ())
1636
1635
Info.group = Group.getValue ();
1637
1636
}
1637
+
1638
1638
return false ;
1639
1639
}
1640
1640
@@ -1651,7 +1651,7 @@ bool IndexSwiftASTWalker::initIndexSymbol(ExtensionDecl *ExtD, ValueDecl *Extend
1651
1651
if (getNameAndUSR (ExtendedD, ExtD, Info.name , Info.USR ))
1652
1652
return true ;
1653
1653
1654
- std::tie (Info.line , Info.column , Info. offset ) = getLineColAndOffset (Loc);
1654
+ std::tie (Info.line , Info.column ) = getLineCol (Loc);
1655
1655
if (auto Group = ExtD->getGroupName ())
1656
1656
Info.group = Group.getValue ();
1657
1657
return false ;
@@ -1786,7 +1786,7 @@ bool IndexSwiftASTWalker::indexComment(const Decl *D) {
1786
1786
OS << " t:" << tagName;
1787
1787
Info.USR = stringStorage.copyString (OS.str ());
1788
1788
}
1789
- std::tie (Info.line , Info.column , Info. offset ) = getLineColAndOffset (loc);
1789
+ std::tie (Info.line , Info.column ) = getLineCol (loc);
1790
1790
if (!IdxConsumer.startSourceEntity (Info) || !IdxConsumer.finishSourceEntity (Info.symInfo , Info.roles )) {
1791
1791
Cancelled = true ;
1792
1792
break ;
0 commit comments