llvm / llvm/llvm-project

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

Open
#214,804 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 Behaviour

Typing `v.` on a `float3` should suggest `x`, `y`, `z`, `r`, `g`, `b`. Typing `v.x` should suggest only `x`, `y`, `z` (locking to the xyzw set). Typing `v.xr` should suggest nothing (mixing sets is semantically invalid). Typing `v.xyzw` should suggest nothing (4-component limit reached).

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

## Reproduction
```hlsl
[numthreads(1,1,1)]
void main() {
float3 v = float3(1.0, 2.0, 3.0);
float a = v.
}

```

## Root cause

`CodeCompleteMemberReferenceExpr` handled `RecordDecl` members but had no case for `ExtVectorType`. The already-typed prefix (e.g. `"x"` when typing `v.x`) was available via `getCodeCompletionFilter()` but not used, so semantically invalid combinations like `v.xr` were not filtered.

## Proposed fix
Add an `ExtVectorType` branch in `DoCompletion` inside `CodeCompleteMemberReferenceExpr`. `AddHLSLVectorSwizzleCompletions` reads `getCodeCompletionFilter()` and enforces three rules:
(1) no mixing xyzw/rgba sets: detected from filter characters;
(2) max 4 components;
(3) only valid components for the vector size.

Contributor guide

Open the contributing guide

Research direction

Start in DoCompletion inside CodeCompleteMemberReferenceExpr, where RecordDecl members are handled and the ExtVectorType case is missing. Review AddHLSLVectorSwizzleCompletions and getCodeCompletionFilter(); done means v. suggests valid swizzles, locks to one naming set, rejects mixed or over-four-component prefixes, and limits components to the vector size.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.