[clang-tools-extra] r367313 - [clangd] Fix a regression in rL366996.
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 30 07:17:45 PDT 2019
Author: hokein
Date: Tue Jul 30 07:17:45 2019
New Revision: 367313
URL: http://llvm.org/viewvc/llvm-project?rev=367313&view=rev
Log:
[clangd] Fix a regression in rL366996.
Summary: That patch made the tweak always annotate the whole file by accident.
Reviewers: jvikstrom
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D65443
Modified:
clang-tools-extra/trunk/clangd/refactor/tweaks/AnnotateHighlightings.cpp
clang-tools-extra/trunk/clangd/unittests/TweakTests.cpp
Modified: clang-tools-extra/trunk/clangd/refactor/tweaks/AnnotateHighlightings.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/refactor/tweaks/AnnotateHighlightings.cpp?rev=367313&r1=367312&r2=367313&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/refactor/tweaks/AnnotateHighlightings.cpp (original)
+++ clang-tools-extra/trunk/clangd/refactor/tweaks/AnnotateHighlightings.cpp Tue Jul 30 07:17:45 2019
@@ -33,18 +33,16 @@ public:
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.
Modified: clang-tools-extra/trunk/clangd/unittests/TweakTests.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/unittests/TweakTests.cpp?rev=367313&r1=367312&r2=367313&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/unittests/TweakTests.cpp (original)
+++ clang-tools-extra/trunk/clangd/unittests/TweakTests.cpp Tue Jul 30 07:17:45 2019
@@ -572,6 +572,17 @@ void f2();]]
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) {
More information about the cfe-commits
mailing list