[PATCH] D65443: [clangd] Fix a regression in rL366996.

Haojian Wu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 30 07:21:17 PDT 2019


This revision was automatically updated to reflect the committed changes.
hokein marked an inline comment as done.
Closed by commit rL367313: [clangd] Fix a regression in rL366996. (authored by hokein, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D65443?vs=212329&id=212334#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65443/new/

https://reviews.llvm.org/D65443

Files:
  clang-tools-extra/trunk/clangd/refactor/tweaks/AnnotateHighlightings.cpp
  clang-tools-extra/trunk/clangd/unittests/TweakTests.cpp


Index: clang-tools-extra/trunk/clangd/refactor/tweaks/AnnotateHighlightings.cpp
===================================================================
--- clang-tools-extra/trunk/clangd/refactor/tweaks/AnnotateHighlightings.cpp
+++ clang-tools-extra/trunk/clangd/refactor/tweaks/AnnotateHighlightings.cpp
@@ -33,18 +33,16 @@
 REGISTER_TWEAK(AnnotateHighlightings)
 
 Expected<Tweak::Effect> AnnotateHighlightings::apply(const Selection &Inputs) {
-  // TUDecl is always the root ancestor.
-  const Decl *CommonDecl =
-      Inputs.ASTSelection.root().ASTNode.get<TranslationUnitDecl>();
+  const Decl *CommonDecl = nullptr;
   for (auto N = Inputs.ASTSelection.commonAncestor(); N && !CommonDecl;
        N = N->Parent)
     CommonDecl = N->ASTNode.get<Decl>();
 
   std::vector<HighlightingToken> HighlightingTokens;
-  if (llvm::isa<TranslationUnitDecl>(CommonDecl)) {
-    // We only annotate tokens in the main file, if CommonDecl is a TUDecl,
-    // we use the default traversal scope (which is the top level decls of the
-    // main file).
+  if (!CommonDecl) {
+    // Now we hit the TUDecl case where commonAncestor() returns null
+    // intendedly. We only annotate tokens in the main file, so use the default
+    // traversal scope (which is the top level decls of the main file).
     HighlightingTokens = getSemanticHighlightings(Inputs.AST);
   } else {
     // Store the existing scopes.
Index: clang-tools-extra/trunk/clangd/unittests/TweakTests.cpp
===================================================================
--- clang-tools-extra/trunk/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/trunk/clangd/unittests/TweakTests.cpp
@@ -572,6 +572,17 @@
 void /* entity.name.function.cpp */f1();
 void /* entity.name.function.cpp */f2();
 )cpp");
+
+   checkTransform(ID,
+  R"cpp(
+void f1();
+void f2() {^};
+)cpp",
+
+  R"cpp(
+void f1();
+void /* entity.name.function.cpp */f2() {};
+)cpp");
 }
 
 TEST(TweakTest, ExpandMacro) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65443.212334.patch
Type: text/x-patch
Size: 1954 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190730/0cb7a1f5/attachment.bin>


More information about the llvm-commits mailing list