[PATCH] D128621: [clangd] Do not try to use $0 as a placeholder in completion snippets

Kadir Cetinkaya via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 18 06:12:29 PDT 2022


kadircet accepted this revision.
kadircet added a comment.
This revision is now accepted and ready to land.

thanks, LG, just some extra precautions.



================
Comment at: clang-tools-extra/clangd/CodeCompletionStrings.cpp:195
       ++SnippetArg;
-      *Snippet +=
-          "${" +
-          std::to_string(SnippetArg == CursorSnippetArg ? 0 : SnippetArg) + ':';
-      appendEscapeSnippet(Chunk.Text, Snippet);
+      *Snippet += "${" + std::to_string(
+                             SnippetArg == CursorSnippetArg ? 0 : SnippetArg);
----------------
i think we shouldn't even have braces for `$0` (just to be safe). so what about:
```
if (SnippetArg == CursorSnippetArg) {
  *Snippet = "$0";
} else {
  *Snippet = "${" + std::to_string(SnippetArg) + ":";
  appendEscapeSnippet(Chunk.Text, Snippet);
  *Snippet += "}";
}
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128621/new/

https://reviews.llvm.org/D128621



More information about the cfe-commits mailing list