[clang-tools-extra] [clangd][HLSL] Add hover support for vector swizzle and matrix element access (PR #212741)

Maria Fernanda GuimarĂ£es via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 31 18:07:52 PDT 2026


================
@@ -5311,6 +5311,109 @@ TEST(Hover, FunctionParameters) {
   }
 }
 
+TEST(Hover, HLSLVectorAndMatrixSwizzle) {
+  struct {
+    const char *const Code;
+    const std::function<void(HoverInfo &)> ExpectedBuilder;
+  } Cases[] = {
+      {
+          R"cpp(
+            typedef float float3 __attribute__((ext_vector_type(3)));
+            void main() {
+              float3 v;
+              float3 s = v.^[[xyz]];
+            }
+          )cpp",
+          [](HoverInfo &HI) {
+            HI.Name = "xyz";
+            HI.Type = "float3";
+          }},
+      {
+          R"cpp(
+            typedef float float3 __attribute__((ext_vector_type(3)));
+            typedef float float2 __attribute__((ext_vector_type(2)));
+            void main() {
+              float3 v;
+              float2 s = v.^[[xy]];
+            }
+          )cpp",
+          [](HoverInfo &HI) {
+            HI.Name = "xy";
+            HI.Type = "float2";
+          }},
+      {
+          R"cpp(
+            typedef float float4x4 __attribute__((matrix_type(4, 4)));
+            void main() {
+              float4x4 m;
+              float e = m.^[[_m00]];
+            }
+          )cpp",
+          [](HoverInfo &HI) {
+            HI.Name = "_m00";
+            HI.Type = "float";
+          }},
+  };
+
+  for (const auto &Case : Cases) {
+    SCOPED_TRACE(Case.Code);
+    Annotations T(Case.Code);
+    TestTU TU = TestTU::withCode(T.code());
+    TU.Filename = "TestTU.hlsl";
+    TU.ExtraArgs.push_back("-x");
+    TU.ExtraArgs.push_back("hlsl");
+    TU.ExtraArgs.push_back("-fenable-matrix");
+    TU.ExtraArgs.push_back("--target=dxil-pc-shadermodel6.3-library");
----------------
mafeguimaraes wrote:

Grepped around and didn't find a shared-args pattern anywhere in clangd/unittests, even the ObjC tests just repeat -xobjective-c++ inline in a few different files.

Added a small local helper (configureHLSL) in HoverTests.cpp for now, just to keep the HLSL tests from repeating those 4 lines each. Can move it somewhere more shared later if we end up with HLSL tests in other files too.

https://github.com/llvm/llvm-project/pull/212741


More information about the cfe-commits mailing list