diff --git a/clang-tools-extra/clangd/CodeCompletionStrings.cpp b/clang-tools-extra/clangd/CodeCompletionStrings.cpp --- a/clang-tools-extra/clangd/CodeCompletionStrings.cpp +++ b/clang-tools-extra/clangd/CodeCompletionStrings.cpp @@ -192,11 +192,15 @@ case CodeCompletionString::CK_Placeholder: *Signature += Chunk.Text; ++SnippetArg; - *Snippet += - "${" + - std::to_string(SnippetArg == CursorSnippetArg ? 0 : SnippetArg) + ':'; - appendEscapeSnippet(Chunk.Text, Snippet); - *Snippet += '}'; + if (SnippetArg == CursorSnippetArg) { + // We'd like to make $0 a placeholder too, but vscode does not support + // this (https://github.com/microsoft/vscode/issues/152837). + *Snippet += "$0"; + } else { + *Snippet += "${" + std::to_string(SnippetArg) + ':'; + appendEscapeSnippet(Chunk.Text, Snippet); + *Snippet += '}'; + } break; case CodeCompletionString::CK_Informative: HadInformativeChunks = true; diff --git a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp --- a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp +++ b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp @@ -3231,9 +3231,8 @@ // Last placeholder in code patterns should be $0 to put the cursor there. EXPECT_THAT(Results.Completions, - Contains(AllOf( - named("while"), - snippetSuffix(" (${1:condition}) {\n${0:statements}\n}")))); + Contains(AllOf(named("while"), + snippetSuffix(" (${1:condition}) {\n$0\n}")))); // However, snippets for functions must *not* end with $0. EXPECT_THAT(Results.Completions, Contains(AllOf(named("while_foo"), diff --git a/clang-tools-extra/clangd/unittests/CodeCompletionStringsTests.cpp b/clang-tools-extra/clangd/unittests/CodeCompletionStringsTests.cpp --- a/clang-tools-extra/clangd/unittests/CodeCompletionStringsTests.cpp +++ b/clang-tools-extra/clangd/unittests/CodeCompletionStringsTests.cpp @@ -150,7 +150,7 @@ // When completing a pattern, the last placeholder holds the cursor position. computeSignature(MakeCCS(), /*CompletingPattern=*/true); - EXPECT_EQ(Snippet, " ${1:name} = ${0:target};"); + EXPECT_EQ(Snippet, " ${1:name} = $0;"); } TEST_F(CompletionStringTest, IgnoreInformativeQualifier) {