Author: Nathan Ridge Date: 2021-04-25T16:43:58-04:00 New Revision: ddfe13e757cb72c056cba8d889d6cb8ee69f1afa
URL: https://github.com/llvm/llvm-project/commit/ddfe13e757cb72c056cba8d889d6cb8ee69f1afa DIFF: https://github.com/llvm/llvm-project/commit/ddfe13e757cb72c056cba8d889d6cb8ee69f1afa.diff LOG: [clangd] Produce semantic token for name referring to UnresolvedUsingValueDecl For now, use the token kind Unknown. We may be able to improve on this using HeuristicResolver. Differential Revision: https://reviews.llvm.org/D99052 Added: Modified: clang-tools-extra/clangd/SemanticHighlighting.cpp 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 cf06eac01a34..c4cb57e3f32b 100644 --- a/clang-tools-extra/clangd/SemanticHighlighting.cpp +++ b/clang-tools-extra/clangd/SemanticHighlighting.cpp @@ -133,6 +133,10 @@ llvm::Optional<HighlightingKind> kindForDecl(const NamedDecl *D) { return HighlightingKind::TemplateParameter; if (isa<ConceptDecl>(D)) return HighlightingKind::Concept; + if (isa<UnresolvedUsingValueDecl>(D)) { + // FIXME: We may be able to do better using HeuristicResolver. + return HighlightingKind::Unknown; + } return llvm::None; } llvm::Optional<HighlightingKind> kindForType(const Type *TP) { @@ -228,6 +232,12 @@ bool isAbstract(const Decl *D) { return false; } +bool isDependent(const Decl *D) { + if (isa<UnresolvedUsingValueDecl>(D)) + return true; + return false; +} + // For a macro usage `DUMP(foo)`, we want: // - DUMP --> "macro" // - foo --> "variable". @@ -619,9 +629,14 @@ std::vector<HighlightingToken> getSemanticHighlightings(ParsedAST &AST) { Tok.addModifier(HighlightingModifier::Static); if (isAbstract(Decl)) Tok.addModifier(HighlightingModifier::Abstract); + if (isDependent(Decl)) + Tok.addModifier(HighlightingModifier::DependentName); if (Decl->isDeprecated()) Tok.addModifier(HighlightingModifier::Deprecated); - if (R.IsDecl) + // Do not treat an UnresolvedUsingValueDecl as a declaration. + // It's more common to think of it as a reference to the + // underlying declaration. + if (R.IsDecl && !isa<UnresolvedUsingValueDecl>(Decl)) Tok.addModifier(HighlightingModifier::Declaration); } }, diff --git a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp index d8dc3b061df5..7e979ee4e75d 100644 --- a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp +++ b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp @@ -688,6 +688,20 @@ sizeof...($TemplateParameter[[Elements]]); @implementation $Class[[Foo]]($Namespace_decl[[Bar]]) @end )cpp", + // Member imported from dependent base + R"cpp( + template <typename> struct $Class_decl[[Base]] { + int $Field_decl[[member]]; + }; + template <typename $TemplateParameter_decl[[T]]> + struct $Class_decl[[Derived]] : $Class[[Base]]<$TemplateParameter[[T]]> { + using $Class[[Base]]<$TemplateParameter[[T]]>::$Unknown_dependentName[[member]]; + + void $Method_decl[[method]]() { + (void)$Unknown_dependentName[[member]]; + } + }; + )cpp", }; for (const auto &TestCase : TestCases) // Mask off scope modifiers to keep the tests manageable. _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits