[PATCH] D44251: [clangd] Early return for #include goto definition.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 8 05:36:17 PST 2018


hokein created this revision.
hokein added a reviewer: ilya-biryukov.
Herald added subscribers: ioeric, jkorous-apple, klimek.

This would save cost of unnecessary parsing, NFC.


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;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44251.137559.patch
Type: text/x-patch
Size: 1492 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180308/6a1b2853/attachment.bin>


More information about the cfe-commits mailing list