@@ -844,7 +844,7 @@ std::vector<DocumentLink> getDocumentLinks(ParsedAST &AST) {
844844 if (Inc.Resolved .empty ())
845845 continue ;
846846 auto HashLoc = SM.getComposedLoc (SM.getMainFileID (), Inc.HashOffset );
847- const auto *HashTok = AST.getTokens ().spelledTokenAt (HashLoc);
847+ const auto *HashTok = AST.getTokens ().spelledTokenContaining (HashLoc);
848848 assert (HashTok && " got inclusion at wrong offset" );
849849 const auto *IncludeTok = std::next (HashTok);
850850 const auto *FileTok = std::next (IncludeTok);
@@ -938,7 +938,7 @@ class ReferenceFinder : public index::IndexDataConsumer {
938938 CollectorOpts.CollectMainFileSymbols = true ;
939939 for (SourceLocation L : Locs) {
940940 L = SM.getFileLoc (L);
941- if (const auto *Tok = TB.spelledTokenAt (L))
941+ if (const auto *Tok = TB.spelledTokenContaining (L))
942942 References.push_back (
943943 {*Tok, Roles,
944944 SymbolCollector::getRefContainer (ASTNode.Parent , CollectorOpts)});
@@ -1216,7 +1216,7 @@ DocumentHighlight toHighlight(const ReferenceFinder::Reference &Ref,
12161216std::optional<DocumentHighlight> toHighlight (SourceLocation Loc,
12171217 const syntax::TokenBuffer &TB) {
12181218 Loc = TB.sourceManager ().getFileLoc (Loc);
1219- if (const auto *Tok = TB.spelledTokenAt (Loc)) {
1219+ if (const auto *Tok = TB.spelledTokenContaining (Loc)) {
12201220 DocumentHighlight Result;
12211221 Result.range = halfOpenToRange (
12221222 TB.sourceManager (),
@@ -1353,7 +1353,8 @@ maybeFindIncludeReferences(ParsedAST &AST, Position Pos,
13531353 Loc = SM.getIncludeLoc (SM.getFileID (Loc));
13541354
13551355 ReferencesResult::Reference Result;
1356- const auto *Token = AST.getTokens ().spelledTokenAt (Loc);
1356+ const auto *Token = AST.getTokens ().spelledTokenContaining (Loc);
1357+ assert (Token && " references expected token here" );
13571358 Result.Loc .range = Range{sourceLocToPosition (SM, Token->location ()),
13581359 sourceLocToPosition (SM, Token->endLocation ())};
13591360 Result.Loc .uri = URIMainFile;
0 commit comments