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

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 18 06:12:32 PDT 2022


sammccall accepted this revision.
sammccall added a comment.

Thank you!



================
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);
----------------
kadircet wrote:
> 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 += "}";
> }
> ```
nit: at this point it might be clearer to unfold the two cases (not longer or shorter)
up to you which is more readable

```
if (SnippetArg == CursorSnippetArg) {
  // we'd like to make...
  *Snippet += "${0}";
} else {
  *Snippet += "${" + to_string(SnippetArg) + ":";
  appendEscapeSnippet(...);
  *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