================
@@ -5411,7 +5411,115 @@ TEST(Hover, HLSLInvalidVectorSwizzleNoCrash) {
auto H = getHover(AST, T.point(), format::getLLVMStyle(), nullptr);
EXPECT_FALSE(H);
}
+TEST(Hover, HLSLControlFlowAndLoopHints) {
+ struct {
+ const char *const Code;
+ const std::function<void(HoverInfo &)> ExpectedBuilder;
+ } Cases[] = {{
+ R"hlsl(
+ [numthreads(1, 1, 1)]
+ void main() {
+ [^unroll]
+ for (int i = 0; i < 4; i++) {}
+ }
+ )hlsl",
+ [](HoverInfo &HI) { HI.Name = "unroll"; }},
+ {
+ R"hlsl(
+ [numthreads(1, 1, 1)]
+ void main() {
+ [l^oop]
+ for (int i = 0; i < 4; i++) {}
+ }
+ )hlsl",
+ [](HoverInfo &HI) { HI.Name = "loop"; }},
+ {
+ R"hlsl(
+ [numthreads(1, 1, 1)]
+ void main() {
+ [b^ranch]
+ if (true) {}
+ }
+ )hlsl",
+ [](HoverInfo &HI) { HI.Name = "branch"; }},
+ {
+ R"hlsl(
+ [numthreads(1, 1, 1)]
+ void main() {
+ [f^latten]
+ if (true) {}
+ }
+ )hlsl",
+ [](HoverInfo &HI) { HI.Name = "flatten"; }}};
+
+ for (const auto &Case : Cases) {
+ SCOPED_TRACE(Case.Code);
+ Annotations T(Case.Code);
+ TestTU TU = TestTU::withCode(T.code());
+ configureHLSL(TU);
+ auto AST = TU.build();
+
+ auto H = getHover(AST, T.point(), format::getLLVMStyle(), nullptr);
+ ASSERT_TRUE(H);
+ HoverInfo Expected;
+ Case.ExpectedBuilder(Expected);
+
+ EXPECT_EQ(H->Name, Expected.Name);
+
+ if (Expected.Name == "unroll" || Expected.Name == "loop") {
+ EXPECT_FALSE(H->Documentation.empty());
+ }
+ }
+}
+
+TEST(Hover, CXXStatementAttributes) {
+ struct {
+ const char *const Code;
+ const char *const Target;
+ const char *const ExpectedName;
+ } Cases[] = {{
+ R"cpp(
+ void foo() {
+ [[likely]] if (true) {}
+ }
+ )cpp",
+ "likely", "likely"},
+ {
+ R"cpp(
+ void foo() {
+ [[unlikely]] if (true) {}
+ }
+ )cpp",
+ "unlikely", "unlikely"},
+ {
+ R"cpp(
+ void foo() {
+ switch (1) {
+ case 1:
+ [[fallthrough]];
+ case 2:
+ break;
+ }
+ }
+ )cpp",
+ "fallthrough", "fallthrough"}};
+
+ for (const auto &Case : Cases) {
+ SCOPED_TRACE(Case.Code);
+ TestTU TU = TestTU::withCode(Case.Code);
+ TU.ExtraArgs.push_back("-std=c++20");
+ auto AST = TU.build();
+
+ llvm::StringRef Code = Case.Code;
+ size_t Offset = Code.find(Case.Target);
+ Position P = offsetToPosition(Code, Offset);
----------------
ArcsinX wrote:
Can you please clarify, why don't we use `Annotations` with `^` to get hover
position?
P.S.
If this is because of `[[` in the code, then you can use custom markers.
Something like this
```cpp
Annotations Code(
Case.Code,
Annotations::Markers().setRangeBegin("{{").setRangeEnd("}}"));
```
https://github.com/llvm/llvm-project/pull/214318
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits