[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:06:40 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)));
----------------
mafeguimaraes wrote:

Real HLSL files pull float3/float4x4 etc from hlsl.h (included automatically via -finclude-default-header). TestTU builds against an in-memory filesystem though, so hlsl.h isn't reachable there, you can see "Dropped diagnostic: 'hlsl.h' file not found" in the test output even though the build still succeeds.

The typedef/attribute is a way around that missing header. It's not testing HLSL's real type sugar, just the ExtVectorElementExpr/MatrixElementExpr hover paths, so I used Clang's underlying vector/matrix extension attributes directly instead. Open to a better way to do this if you know one.

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


More information about the cfe-commits mailing list