llvm / llvm/llvm-project

[clangd][HLSL] Code Completion for HLSL Matrix Swizzle Members

Open
#214,805 1 comment 0 reactions 0 assignees View on GitHub
clangd HLSL
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

## Expected behavior

Typing `m.` on a `float2x2` should suggest `_m00`, `_m01`, `_m10`, `_m11` and `_11`, `_12`, `_21`, `_22`. Typing `m._m00` should continue with `_m` notation only. Typing `m._m00_11` should suggest nothing (mixing notations is invalid).

## Observed behavior
Typing `m.` produced no suggestions.

## Reproduction

```hlsl
[numthreads(1,1,1)]
void main() {
float2x2 m = float2x2(1.0, 2.0, 3.0, 4.0);
float a = m.
}
```

## Root cause
`ConstantMatrixType` was not handled in `CodeCompleteMemberReferenceExpr`. HLSL supports two notation systems (`_m` zero-indexed and `_` one-indexed) that cannot be mixed, but this was not enforced.

## Proposed fix
Add a `ConstantMatrixType` branch in `DoCompletion`. `AddHLSLMatrixSwizzleCompletions` detects the notation from the filter prefix: `starts_with("_m")` locks to 0-indexed (4 chars/component, max 16 chars total), `starts_with("_")` locks to 1-indexed (3 chars/component, max 12 chars total). Mixing notations returns no suggestions.

Contributor guide

Open the contributing guide

Research direction

Start in clangd's CodeCompleteMemberReferenceExpr and follow DoCompletion to see how member-reference completions are dispatched. Inspect the proposed AddHLSLMatrixSwizzleCompletions logic and verify the float2x2 reproduction: both HLSL notations should appear initially, each notation should remain consistent after its prefix, and mixed notation should return no suggestions.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers, devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
67/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.