llvm / llvm/llvm-project

[clangd][HLSL] Code Completion for HLSL Annotations After :

Open
#214,801 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 `:` after a variable or parameter declaration should suggest valid annotations for that context: parsed semantics (`SV_Target`, `SV_Position`, etc.), `register(slot, space)` with the correct slot pre-filled based on the declared resource type, and `packoffset(c0)`. Both `register` and `packoffset` should be inserted as Tab-navigable snippets.

## Observed behavior
Typing `:` produced no completion results.

## Reproduction
```hlsl
StructuredBuffer inputData :
```

## Root cause
`ParseHLSLAnnotations` had no `tok::code_completion` hook. The token fell into the `if (!II)` error branch and was discarded. The `Declarator*` was not threaded through to Sema, making type-aware slot filtering impossible.

## Proposed fix
Add `const Declarator *D` parameter to `ParseHLSLAnnotations` and `MaybeParseHLSLAnnotations(Declarator &D)`. `CodeCompleteHLSLAnnotation(D)` iterates `ParsedAttrInfo::getAllBuiltin()` and emits candidates for `AS_HLSLAnnotation` (`register`, `packoffset`) and `AS_Microsoft` + `AT_HLSLParsedSemantic` (`SV_Target`, etc.). The slot is resolved by `CXXRecordDecl` name since `HLSLAttributedResourceType` is not yet built at parse time. `register` and `packoffset` use `CCP_CodePattern` with `CXCursor_Constructor` to preserve both Tab stops.

Contributor guide

Open the contributing guide

Research direction

Start by tracing ParseHLSLAnnotations and MaybeParseHLSLAnnotations(Declarator &D), then inspect CodeCompleteHLSLAnnotation(D), ParsedAttrInfo::getAllBuiltin(), and the relevant completion patterns. Reproduce the issue with the StructuredBuffer declaration; done means semantic, register, and packoffset candidates appear, with register and packoffset preserving Tab stops and type-aware slot filtering.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.