massberg created this revision. massberg added a reviewer: sammccall. Herald added subscribers: kadircet, arphaman. Herald added a project: All. massberg requested review of this revision. Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov. Herald added a project: clang-tools-extra.
This enables support of hover on concepts with auto types. I'm not 100% sure if this is the correct fix, but it works for the exmaples and in vscode. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D154853 Files: clang-tools-extra/clangd/FindTarget.cpp clang-tools-extra/clangd/unittests/FindTargetTests.cpp clang-tools-extra/clangd/unittests/HoverTests.cpp Index: clang-tools-extra/clangd/unittests/HoverTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/HoverTests.cpp +++ clang-tools-extra/clangd/unittests/HoverTests.cpp @@ -487,6 +487,46 @@ HI.Kind = index::SymbolKind::TypeAlias; HI.Definition = "int"; }}, + // constraint of constrained auto + {R"cpp( + template <class T> concept Fooable = true; + [[Foo^able]] auto x = 1; + )cpp", + [](HoverInfo &HI) { + HI.NamespaceScope = ""; + HI.Name = "Fooable"; + HI.Kind = index::SymbolKind::Concept; + HI.Definition = "template <class T>\n" + "concept Fooable = true"; + }}, + {R"cpp( + template <class T> concept Fooable = true; + template<[[Fooa^ble]] auto x> void Foo() {} + )cpp", + [](HoverInfo &HI) { + HI.NamespaceScope = ""; + HI.Name = "Fooable"; + HI.Kind = index::SymbolKind::Concept; + HI.Definition = "template <class T>\n" + "concept Fooable = true"; + }}, + // concept + {R"cpp( + template <typename T> + concept Fooable = requires (T t) { t.foo(); }; + + template <typename T> requires [[Fo^oable]]<T> + void bar(T t) { + t.foo(); + } + )cpp", + [](HoverInfo &HI) { + HI.NamespaceScope = ""; + HI.Name = "Fooable"; + HI.Kind = index::SymbolKind::Concept; + HI.Definition = "template <typename T>\n" + "concept Fooable = requires(T t) { t.foo(); }"; + }}, // auto on lambda {R"cpp( void foo() { Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/FindTargetTests.cpp +++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp @@ -572,6 +572,27 @@ )cpp"; EXPECT_DECLS("ConceptSpecializationExpr", {"template <typename T, typename U> concept Fooable = true"}); + + // Constrained auto + Code = R"cpp( + template <typename T> + concept Fooable = true; + + [[Fooable]] auto i = 42; + )cpp"; + EXPECT_DECLS( + "AutoTypeLoc", + {"template <typename T> concept Fooable = true"}); + + Code = R"cpp( + template <typename T> + concept Fooable = true; + + template<[[Fooable]] auto x> void Foo() {} + )cpp"; + EXPECT_DECLS( + "AutoTypeLoc", + {"template <typename T> concept Fooable = true"}); } TEST_F(TargetDeclTest, Coroutine) { Index: clang-tools-extra/clangd/FindTarget.cpp =================================================================== --- clang-tools-extra/clangd/FindTarget.cpp +++ clang-tools-extra/clangd/FindTarget.cpp @@ -471,6 +471,12 @@ void VisitObjCInterfaceType(const ObjCInterfaceType *OIT) { Outer.add(OIT->getDecl(), Flags); } + void VisitAutoType(const AutoType *T) { + if (T->isConstrained()) { + Outer.add(T->getTypeConstraintConcept(), Flags); + } + TypeVisitor<Visitor>::VisitAutoType(T); + } }; Visitor(*this, Flags).Visit(T.getTypePtr()); }
Index: clang-tools-extra/clangd/unittests/HoverTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/HoverTests.cpp +++ clang-tools-extra/clangd/unittests/HoverTests.cpp @@ -487,6 +487,46 @@ HI.Kind = index::SymbolKind::TypeAlias; HI.Definition = "int"; }}, + // constraint of constrained auto + {R"cpp( + template <class T> concept Fooable = true; + [[Foo^able]] auto x = 1; + )cpp", + [](HoverInfo &HI) { + HI.NamespaceScope = ""; + HI.Name = "Fooable"; + HI.Kind = index::SymbolKind::Concept; + HI.Definition = "template <class T>\n" + "concept Fooable = true"; + }}, + {R"cpp( + template <class T> concept Fooable = true; + template<[[Fooa^ble]] auto x> void Foo() {} + )cpp", + [](HoverInfo &HI) { + HI.NamespaceScope = ""; + HI.Name = "Fooable"; + HI.Kind = index::SymbolKind::Concept; + HI.Definition = "template <class T>\n" + "concept Fooable = true"; + }}, + // concept + {R"cpp( + template <typename T> + concept Fooable = requires (T t) { t.foo(); }; + + template <typename T> requires [[Fo^oable]]<T> + void bar(T t) { + t.foo(); + } + )cpp", + [](HoverInfo &HI) { + HI.NamespaceScope = ""; + HI.Name = "Fooable"; + HI.Kind = index::SymbolKind::Concept; + HI.Definition = "template <typename T>\n" + "concept Fooable = requires(T t) { t.foo(); }"; + }}, // auto on lambda {R"cpp( void foo() { Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/FindTargetTests.cpp +++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp @@ -572,6 +572,27 @@ )cpp"; EXPECT_DECLS("ConceptSpecializationExpr", {"template <typename T, typename U> concept Fooable = true"}); + + // Constrained auto + Code = R"cpp( + template <typename T> + concept Fooable = true; + + [[Fooable]] auto i = 42; + )cpp"; + EXPECT_DECLS( + "AutoTypeLoc", + {"template <typename T> concept Fooable = true"}); + + Code = R"cpp( + template <typename T> + concept Fooable = true; + + template<[[Fooable]] auto x> void Foo() {} + )cpp"; + EXPECT_DECLS( + "AutoTypeLoc", + {"template <typename T> concept Fooable = true"}); } TEST_F(TargetDeclTest, Coroutine) { Index: clang-tools-extra/clangd/FindTarget.cpp =================================================================== --- clang-tools-extra/clangd/FindTarget.cpp +++ clang-tools-extra/clangd/FindTarget.cpp @@ -471,6 +471,12 @@ void VisitObjCInterfaceType(const ObjCInterfaceType *OIT) { Outer.add(OIT->getDecl(), Flags); } + void VisitAutoType(const AutoType *T) { + if (T->isConstrained()) { + Outer.add(T->getTypeConstraintConcept(), Flags); + } + TypeVisitor<Visitor>::VisitAutoType(T); + } }; Visitor(*this, Flags).Visit(T.getTypePtr()); }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits