================
@@ -5992,6 +5992,64 @@ Expr *unwrapParenList(Expr *Base) {
} // namespace
+static void AddHLSLVectorSwizzleCompletions(Sema &SemaRef,
+ ResultBuilder &Results,
+ const ExtVectorType *VT) {
+
+ unsigned NumElts = VT->getNumElements();
+ if (NumElts > 4)
+ NumElts = 4;
+
+ StringRef Filter = SemaRef.PP.getCodeCompletionFilter();
+
+ bool UseXYZW = true;
+ bool UseRGBA = true;
+ if (!Filter.empty()) {
+ bool HasXYZW = Filter.find_first_of("xyzw") != StringRef::npos;
+ bool HasRGBA = Filter.find_first_of("rgba") != StringRef::npos;
+ if (HasXYZW && !HasRGBA)
+ UseRGBA = false;
+ if (HasRGBA && !HasXYZW)
+ UseXYZW = false;
+ if (HasXYZW && HasRGBA)
+ return;
+ if (Filter.size() >= 4)
+ return;
+ }
+
+ static const char *const XYZWNames[] = {"x", "y", "z", "w"};
+ static const char *const RGBANames[] = {"r", "g", "b", "a"};
+
+ for (unsigned I = 0; I < NumElts; ++I) {
+ if (UseRGBA) {
+ CodeCompletionBuilder CCB(Results.getAllocator(),
+ Results.getCodeCompletionTUInfo());
+ if (!Filter.empty()) {
+ llvm::SmallString<8> FullText(Filter);
+ FullText += RGBANames[I];
+ CCB.AddTypedTextChunk(Results.getAllocator().CopyString(FullText));
+ } else {
+ CCB.AddTypedTextChunk(RGBANames[I]);
+ }
----------------
V-FEXrt wrote:
I think you can simplify this since it'll still do the right thing with then
filter is empty
```suggestion
llvm::SmallString<8> FullText(Filter);
FullText += RGBANames[I];
CCB.AddTypedTextChunk(Results.getAllocator().CopyString(FullText));
```
https://github.com/llvm/llvm-project/pull/217381
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits