Index: clang-tools-extra/trunk/clangd/XRefs.cpp =================================================================== --- clang-tools-extra/trunk/clangd/XRefs.cpp +++ clang-tools-extra/trunk/clangd/XRefs.cpp @@ -174,6 +174,18 @@ SourceLocation SourceLocationBeg = getBeginningOfIdentifier(AST, Pos, FE); + std::vector Result; + // Handle goto definition for #include. + for (auto &IncludeLoc : AST.getInclusionLocations()) { + Range R = IncludeLoc.first; + Position Pos = sourceLocToPosition(SourceMgr, SourceLocationBeg); + + if (R.contains(Pos)) + Result.push_back(Location{URIForFile{IncludeLoc.second}, {}}); + } + if (!Result.empty()) + return Result; + auto DeclMacrosFinder = std::make_shared( llvm::errs(), SourceLocationBeg, AST.getASTContext(), AST.getPreprocessor()); @@ -187,7 +199,6 @@ std::vector Decls = DeclMacrosFinder->takeDecls(); std::vector MacroInfos = DeclMacrosFinder->takeMacroInfos(); - std::vector Result; for (auto Item : Decls) { auto L = getDeclarationLocation(AST, Item->getSourceRange()); @@ -203,15 +214,6 @@ Result.push_back(*L); } - /// Process targets for paths inside #include directive. - for (auto &IncludeLoc : AST.getInclusionLocations()) { - Range R = IncludeLoc.first; - Position Pos = sourceLocToPosition(SourceMgr, SourceLocationBeg); - - if (R.contains(Pos)) - Result.push_back(Location{URIForFile{IncludeLoc.second}, {}}); - } - return Result; }