Author: Christian Kandeler Date: 2021-08-03T19:53:01-07:00 New Revision: 159a26964840c456f92387c6705ffff57e7174d4
URL: https://github.com/llvm/llvm-project/commit/159a26964840c456f92387c6705ffff57e7174d4 DIFF: https://github.com/llvm/llvm-project/commit/159a26964840c456f92387c6705ffff57e7174d4.diff LOG: [clangd] Add new semantic token modifier "virtual" This is needed for clients that want to highlight virtual functions differently. Reviewed By: sammccall Differential Revision: https://reviews.llvm.org/D107145 Added: Modified: clang-tools-extra/clangd/SemanticHighlighting.cpp clang-tools-extra/clangd/SemanticHighlighting.h clang-tools-extra/clangd/test/initialize-params.test clang-tools-extra/clangd/test/semantic-tokens.test clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp Removed: ################################################################################ diff --git a/clang-tools-extra/clangd/SemanticHighlighting.cpp b/clang-tools-extra/clangd/SemanticHighlighting.cpp index b49eb785f2deb..67315f5b99e06 100644 --- a/clang-tools-extra/clangd/SemanticHighlighting.cpp +++ b/clang-tools-extra/clangd/SemanticHighlighting.cpp @@ -240,6 +240,12 @@ bool isAbstract(const Decl *D) { return false; } +bool isVirtual(const Decl *D) { + if (const auto *CMD = llvm::dyn_cast<CXXMethodDecl>(D)) + return CMD->isVirtual(); + return false; +} + bool isDependent(const Decl *D) { if (isa<UnresolvedUsingValueDecl>(D)) return true; @@ -712,6 +718,8 @@ std::vector<HighlightingToken> getSemanticHighlightings(ParsedAST &AST) { Tok.addModifier(HighlightingModifier::Static); if (isAbstract(Decl)) Tok.addModifier(HighlightingModifier::Abstract); + if (isVirtual(Decl)) + Tok.addModifier(HighlightingModifier::Virtual); if (isDependent(Decl)) Tok.addModifier(HighlightingModifier::DependentName); if (isDefaultLibrary(Decl)) @@ -898,6 +906,8 @@ llvm::StringRef toSemanticTokenModifier(HighlightingModifier Modifier) { return "deduced"; // nonstandard case HighlightingModifier::Abstract: return "abstract"; + case HighlightingModifier::Virtual: + return "virtual"; case HighlightingModifier::DependentName: return "dependentName"; // nonstandard case HighlightingModifier::DefaultLibrary: diff --git a/clang-tools-extra/clangd/SemanticHighlighting.h b/clang-tools-extra/clangd/SemanticHighlighting.h index 82d48f6bf37c3..10bcb47ef45b5 100644 --- a/clang-tools-extra/clangd/SemanticHighlighting.h +++ b/clang-tools-extra/clangd/SemanticHighlighting.h @@ -66,6 +66,7 @@ enum class HighlightingModifier { Readonly, Static, Abstract, + Virtual, DependentName, DefaultLibrary, diff --git a/clang-tools-extra/clangd/test/initialize-params.test b/clang-tools-extra/clangd/test/initialize-params.test index b243d0a43c25a..891ef2c3ad9a5 100644 --- a/clang-tools-extra/clangd/test/initialize-params.test +++ b/clang-tools-extra/clangd/test/initialize-params.test @@ -88,6 +88,7 @@ # CHECK-NEXT: "readonly", # CHECK-NEXT: "static", # CHECK-NEXT: "abstract", +# CHECK-NEXT: "virtual", # CHECK-NEXT: "dependentName", # CHECK-NEXT: "defaultLibrary", # CHECK-NEXT: "functionScope", diff --git a/clang-tools-extra/clangd/test/semantic-tokens.test b/clang-tools-extra/clangd/test/semantic-tokens.test index 06874a53d3509..6d3e324860edd 100644 --- a/clang-tools-extra/clangd/test/semantic-tokens.test +++ b/clang-tools-extra/clangd/test/semantic-tokens.test @@ -23,7 +23,7 @@ # CHECK-NEXT: 4, # CHECK-NEXT: 1, # CHECK-NEXT: 0, -# CHECK-NEXT: 2049 +# CHECK-NEXT: 4097 # CHECK-NEXT: ], # CHECK-NEXT: "resultId": "1" # CHECK-NEXT: } @@ -49,7 +49,7 @@ # CHECK-NEXT: 4, # CHECK-NEXT: 1, # CHECK-NEXT: 0, -# CHECK-NEXT: 2049 +# CHECK-NEXT: 4097 # CHECK-NEXT: ], # Inserted at position 1 # CHECK-NEXT: "deleteCount": 0, @@ -72,12 +72,12 @@ # CHECK-NEXT: 4, # CHECK-NEXT: 1, # CHECK-NEXT: 0, -# CHECK-NEXT: 2049, +# CHECK-NEXT: 4097, # CHECK-NEXT: 1, # CHECK-NEXT: 4, # CHECK-NEXT: 1, # CHECK-NEXT: 0, -# CHECK-NEXT: 2049 +# CHECK-NEXT: 4097 # CHECK-NEXT: ], # CHECK-NEXT: "resultId": "3" # CHECK-NEXT: } diff --git a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp index a0212856427d6..403f506824176 100644 --- a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp +++ b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp @@ -642,9 +642,14 @@ sizeof...($TemplateParameter[[Elements]]); )cpp", R"cpp( class $Class_decl_abstract[[Abstract]] { - virtual void $Method_decl_abstract[[pure]]() = 0; - virtual void $Method_decl[[impl]](); + public: + virtual void $Method_decl_abstract_virtual[[pure]]() = 0; + virtual void $Method_decl_virtual[[impl]](); }; + void $Function_decl[[foo]]($Class_abstract[[Abstract]]* $Parameter_decl[[A]]) { + $Parameter[[A]]->$Method_abstract_virtual[[pure]](); + $Parameter[[A]]->$Method_virtual[[impl]](); + } )cpp", R"cpp( <:[deprecated]:> int $Variable_decl_deprecated[[x]]; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits