diff --git a/clang-tools-extra/clangd/Hover.cpp b/clang-tools-extra/clangd/Hover.cpp --- a/clang-tools-extra/clangd/Hover.cpp +++ b/clang-tools-extra/clangd/Hover.cpp @@ -556,12 +556,7 @@ HoverInfo HI; if (const auto *D = T->getAsTagDecl()) { - HI.Name = printName(ASTCtx, *D); - HI.Kind = index::getSymbolInfo(D).Kind; - - const auto *CommentD = getDeclForComment(D); - HI.Documentation = getDeclComment(ASTCtx, *CommentD); - enhanceFromIndex(HI, *CommentD, Index); + return getHoverContents(D, Index); } else { // Builtin types auto Policy = printingPolicyForDecls(ASTCtx.getPrintingPolicy()); diff --git a/clang-tools-extra/clangd/XRefs.cpp b/clang-tools-extra/clangd/XRefs.cpp --- a/clang-tools-extra/clangd/XRefs.cpp +++ b/clang-tools-extra/clangd/XRefs.cpp @@ -667,21 +667,44 @@ return {}; } - const syntax::Token *TouchedIdentifier = - syntax::spelledIdentifierTouching(*CurLoc, AST.getTokens()); - if (TouchedIdentifier) - if (auto Macro = - locateMacroReferent(*TouchedIdentifier, AST, *MainFilePath)) - // Don't look at the AST or index if we have a macro result. - // (We'd just return declarations referenced from the macro's - // expansion.) - return {*std::move(Macro)}; - - ASTNodeKind NodeKind; - auto ASTResults = locateASTReferent(*CurLoc, TouchedIdentifier, AST, - *MainFilePath, Index, &NodeKind); - if (!ASTResults.empty()) - return ASTResults; + auto TokensTouchingCursor = + syntax::spelledTokensTouching(*CurLoc, AST.getTokens()); + for (const auto &Tok : TokensTouchingCursor) { + if (Tok.kind() == tok::identifier) { + if (auto Macro = locateMacroReferent(Tok, AST, *MainFilePath)) + // Don't look at the AST or index if we have a macro result. + // (We'd just return declarations referenced from the macro's + // expansion.) + return {*std::move(Macro)}; + + ASTNodeKind NodeKind; + auto ASTResults = locateASTReferent(*CurLoc, &Tok, AST, *MainFilePath, + Index, &NodeKind); + if (!ASTResults.empty()) + return ASTResults; + } else if (Tok.kind() == tok::kw_auto || Tok.kind() == tok::kw_decltype) { + if (auto Deduced = getDeducedType(AST.getASTContext(), Tok.location())) { + const NamedDecl *D = Deduced->getTypePtr()->getAsTagDecl(); + if (!D) + continue; + + D = getPreferredDecl(D); + auto Loc = makeLocation(AST.getASTContext(), nameLocation(*D, SM), + *MainFilePath); + if (!Loc) + continue; + + LocatedSymbol LocSym; + LocSym.Name = printName(AST.getASTContext(), *D); + LocSym.PreferredDeclaration = *Loc; + if (const NamedDecl *Def = getDefinition(D)) + LocSym.Definition = makeLocation( + AST.getASTContext(), nameLocation(*Def, SM), *MainFilePath); + + return {std::move(LocSym)}; + } + } + } // If the cursor can't be resolved directly, try fallback strategies. auto Word = @@ -695,7 +718,7 @@ Word->Text); return {*std::move(Macro)}; } - ASTResults = + auto ASTResults = locateASTReferent(NearbyIdent->location(), NearbyIdent, AST, *MainFilePath, Index, /*NodeKind=*/nullptr); if (!ASTResults.empty()) { @@ -708,6 +731,7 @@ } } // No nearby word, or it didn't refer to anything either. Try the index. + ASTNodeKind NodeKind; auto TextualResults = locateSymbolTextually(*Word, AST, Index, *MainFilePath, NodeKind); if (!TextualResults.empty())