hokein created this revision. hokein added a reviewer: jvikstrom. Herald added subscribers: kadircet, arphaman, jkorous, MaskRay, ilya-biryukov. Herald added a project: clang.
That patch made the tweak always annotate the whole file by accident. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D65443 Files: clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp clang-tools-extra/clangd/unittests/TweakTests.cpp Index: clang-tools-extra/clangd/unittests/TweakTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/TweakTests.cpp +++ clang-tools-extra/clangd/unittests/TweakTests.cpp @@ -571,6 +571,17 @@ R"cpp( 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"); } Index: clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp =================================================================== --- clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp +++ clang-tools-extra/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). + // Now we hit the TUDecl case where commonAncestor() returns null intently. + // 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/clangd/unittests/TweakTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/TweakTests.cpp +++ clang-tools-extra/clangd/unittests/TweakTests.cpp @@ -571,6 +571,17 @@ R"cpp( 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"); } Index: clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp =================================================================== --- clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp +++ clang-tools-extra/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). + // Now we hit the TUDecl case where commonAncestor() returns null intently. + // 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.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits