llvm / llvm/llvm-project

[clangd][HLSL] Code Completion Inside [...] Mixes Statement and Declaration Attributes

Open
#214,792 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
Inside a function body, `[` should suggest only statement attributes (`unroll`, `loop`, `branch`, `flatten`). Outside a function, `[` should suggest only declaration attributes (`numthreads`, `shader`, `RootSignature`, `WaveSize`).

## Observed behavior
Completion showed all Microsoft-syntax attributes indiscriminately, mixing statement and declaration contexts.

## Reproduction
```hlsl
[...]
```

```hlsl
[numthreads(1, 1, 1)]
void CS_LoopAttrs(uint3 tid : SV_DispatchThreadID) {
float result = 0.0;

[...]
for (int i = 0; i < 4; i++) {
}
```

## Root cause
`ParseMicrosoftAttributes` called `CodeCompleteAttribute(AS_Microsoft)`, which returns all attributes with `AS_Microsoft` spelling, with no distinction between contexts.

## Proposed fix
Add a defaulted `bool IsStmtContext = false` parameter to `MaybeParseMicrosoftAttributes`/`ParseMicrosoftAttributes`. Only `ParseStmt.cpp` passes true, so the other five call sites are unchanged. `CodeCompleteHLSLAttributes` filters `ParsedAttrInfo::getAllBuiltin()` by accepted syntax values, an optional kind restriction, a `bool RequireStmt` flag, and an optional `ExcludeKind` (needed to exclude `AT_HLSLParsedSemantic` from bracket-attribute contexts).

Contributor guide

Open the contributing guide

Research direction

Start with MaybeParseMicrosoftAttributes and ParseMicrosoftAttributes, then inspect the five unchanged call sites and the ParseStmt.cpp call that supplies statement context. Read CodeCompleteHLSLAttributes and ParsedAttrInfo::getAllBuiltin() to understand the existing filters. Done means statement and declaration HLSL attributes are suggested only in their respective contexts, with semantic attributes excluded where required.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.