This revision was automatically updated to reflect the committed changes. Closed by commit rCTE327023: [clangd] Early return for #include goto definition. (authored by hokein, committed by ).
Changed prior to commit: https://reviews.llvm.org/D44251?vs=137559&id=137581#toc Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D44251 Files: clangd/XRefs.cpp Index: clangd/XRefs.cpp =================================================================== --- clangd/XRefs.cpp +++ clangd/XRefs.cpp @@ -174,6 +174,18 @@ SourceLocation SourceLocationBeg = getBeginningOfIdentifier(AST, Pos, FE); + std::vector<Location> 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<DeclarationAndMacrosFinder>( llvm::errs(), SourceLocationBeg, AST.getASTContext(), AST.getPreprocessor()); @@ -187,7 +199,6 @@ std::vector<const Decl *> Decls = DeclMacrosFinder->takeDecls(); std::vector<MacroDecl> MacroInfos = DeclMacrosFinder->takeMacroInfos(); - std::vector<Location> 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; }
Index: clangd/XRefs.cpp =================================================================== --- clangd/XRefs.cpp +++ clangd/XRefs.cpp @@ -174,6 +174,18 @@ SourceLocation SourceLocationBeg = getBeginningOfIdentifier(AST, Pos, FE); + std::vector<Location> 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<DeclarationAndMacrosFinder>( llvm::errs(), SourceLocationBeg, AST.getASTContext(), AST.getPreprocessor()); @@ -187,7 +199,6 @@ std::vector<const Decl *> Decls = DeclMacrosFinder->takeDecls(); std::vector<MacroDecl> MacroInfos = DeclMacrosFinder->takeMacroInfos(); - std::vector<Location> 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; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits