@@ -1183,23 +1183,24 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const LocatedSymbol &S) {
1183
1183
1184
1184
// FIXME(nridge): Reduce duplication between this function and declToSym().
1185
1185
static llvm::Optional<TypeHierarchyItem>
1186
- declToTypeHierarchyItem (ASTContext &Ctx, const NamedDecl &ND,
1187
- const syntax::TokenBuffer &TB) {
1186
+ declToTypeHierarchyItem (ASTContext &Ctx, const NamedDecl &ND) {
1188
1187
auto &SM = Ctx.getSourceManager ();
1189
1188
SourceLocation NameLoc = nameLocation (ND, Ctx.getSourceManager ());
1189
+ SourceLocation BeginLoc = SM.getSpellingLoc (SM.getFileLoc (ND.getBeginLoc ()));
1190
+ SourceLocation EndLoc = SM.getSpellingLoc (SM.getFileLoc (ND.getEndLoc ()));
1191
+ const auto DeclRange =
1192
+ toHalfOpenFileRange (SM, Ctx.getLangOpts (), {BeginLoc, EndLoc});
1193
+ if (!DeclRange)
1194
+ return llvm::None;
1190
1195
auto FilePath =
1191
1196
getCanonicalPath (SM.getFileEntryForID (SM.getFileID (NameLoc)), SM);
1192
1197
auto TUPath = getCanonicalPath (SM.getFileEntryForID (SM.getMainFileID ()), SM);
1193
1198
if (!FilePath || !TUPath)
1194
1199
return llvm::None; // Not useful without a uri.
1195
1200
1196
- auto DeclToks = TB.spelledForExpanded (TB.expandedTokens (ND.getSourceRange ()));
1197
- if (!DeclToks || DeclToks->empty ())
1198
- return llvm::None;
1199
-
1200
- auto NameToks = TB.spelledForExpanded (TB.expandedTokens (NameLoc));
1201
- if (!NameToks || NameToks->empty ())
1202
- return llvm::None;
1201
+ Position NameBegin = sourceLocToPosition (SM, NameLoc);
1202
+ Position NameEnd = sourceLocToPosition (
1203
+ SM, Lexer::getLocForEndOfToken (NameLoc, 0 , SM, Ctx.getLangOpts ()));
1203
1204
1204
1205
index ::SymbolInfo SymInfo = index ::getSymbolInfo (&ND);
1205
1206
// FIXME: this is not classifying constructors, destructors and operators
@@ -1210,12 +1211,9 @@ declToTypeHierarchyItem(ASTContext &Ctx, const NamedDecl &ND,
1210
1211
THI.name = printName (Ctx, ND);
1211
1212
THI.kind = SK;
1212
1213
THI.deprecated = ND.isDeprecated ();
1213
- THI.range = halfOpenToRange (
1214
- SM, syntax::Token::range (SM, DeclToks->front (), DeclToks->back ())
1215
- .toCharRange (SM));
1216
- THI.selectionRange = halfOpenToRange (
1217
- SM, syntax::Token::range (SM, NameToks->front (), NameToks->back ())
1218
- .toCharRange (SM));
1214
+ THI.range = Range{sourceLocToPosition (SM, DeclRange->getBegin ()),
1215
+ sourceLocToPosition (SM, DeclRange->getEnd ())};
1216
+ THI.selectionRange = Range{NameBegin, NameEnd};
1219
1217
if (!THI.range .contains (THI.selectionRange )) {
1220
1218
// 'selectionRange' must be contained in 'range', so in cases where clang
1221
1219
// reports unrelated ranges we need to reconcile somehow.
@@ -1282,8 +1280,7 @@ using RecursionProtectionSet = llvm::SmallSet<const CXXRecordDecl *, 4>;
1282
1280
1283
1281
static void fillSuperTypes (const CXXRecordDecl &CXXRD, ASTContext &ASTCtx,
1284
1282
std::vector<TypeHierarchyItem> &SuperTypes,
1285
- RecursionProtectionSet &RPSet,
1286
- const syntax::TokenBuffer &TB) {
1283
+ RecursionProtectionSet &RPSet) {
1287
1284
// typeParents() will replace dependent template specializations
1288
1285
// with their class template, so to avoid infinite recursion for
1289
1286
// certain types of hierarchies, keep the templates encountered
@@ -1298,9 +1295,9 @@ static void fillSuperTypes(const CXXRecordDecl &CXXRD, ASTContext &ASTCtx,
1298
1295
1299
1296
for (const CXXRecordDecl *ParentDecl : typeParents (&CXXRD)) {
1300
1297
if (Optional<TypeHierarchyItem> ParentSym =
1301
- declToTypeHierarchyItem (ASTCtx, *ParentDecl, TB )) {
1298
+ declToTypeHierarchyItem (ASTCtx, *ParentDecl)) {
1302
1299
ParentSym->parents .emplace ();
1303
- fillSuperTypes (*ParentDecl, ASTCtx, *ParentSym->parents , RPSet, TB );
1300
+ fillSuperTypes (*ParentDecl, ASTCtx, *ParentSym->parents , RPSet);
1304
1301
SuperTypes.emplace_back (std::move (*ParentSym));
1305
1302
}
1306
1303
}
@@ -1404,7 +1401,7 @@ getTypeHierarchy(ParsedAST &AST, Position Pos, int ResolveLevels,
1404
1401
return llvm::None;
1405
1402
1406
1403
Optional<TypeHierarchyItem> Result =
1407
- declToTypeHierarchyItem (AST.getASTContext (), *CXXRD, AST. getTokens () );
1404
+ declToTypeHierarchyItem (AST.getASTContext (), *CXXRD);
1408
1405
if (!Result)
1409
1406
return Result;
1410
1407
@@ -1413,8 +1410,7 @@ getTypeHierarchy(ParsedAST &AST, Position Pos, int ResolveLevels,
1413
1410
Result->parents .emplace ();
1414
1411
1415
1412
RecursionProtectionSet RPSet;
1416
- fillSuperTypes (*CXXRD, AST.getASTContext (), *Result->parents , RPSet,
1417
- AST.getTokens ());
1413
+ fillSuperTypes (*CXXRD, AST.getASTContext (), *Result->parents , RPSet);
1418
1414
}
1419
1415
1420
1416
if ((Direction == TypeHierarchyDirection::Children ||
0 commit comments