diff --git a/clang-tools-extra/clangd/CodeComplete.cpp b/clang-tools-extra/clangd/CodeComplete.cpp --- a/clang-tools-extra/clangd/CodeComplete.cpp +++ b/clang-tools-extra/clangd/CodeComplete.cpp @@ -399,9 +399,8 @@ Bundled.emplace_back(); BundledEntry &S = Bundled.back(); if (C.SemaResult) { - bool IsPattern = C.SemaResult->Kind == CodeCompletionResult::RK_Pattern; getSignature(*SemaCCS, &S.Signature, &S.SnippetSuffix, - &Completion.RequiredQualifier, IsPattern); + &Completion.RequiredQualifier); S.ReturnType = getReturnType(*SemaCCS); } else if (C.IndexResult) { S.Signature = std::string(C.IndexResult->Signature); diff --git a/clang-tools-extra/clangd/CodeCompletionStrings.h b/clang-tools-extra/clangd/CodeCompletionStrings.h --- a/clang-tools-extra/clangd/CodeCompletionStrings.h +++ b/clang-tools-extra/clangd/CodeCompletionStrings.h @@ -41,13 +41,9 @@ /// *Snippet = "(${1:size_type})" /// If set, RequiredQualifiers is the text that must be typed before the name. /// e.g "Base::" when calling a base class member function that's hidden. -/// -/// When \p CompletingPattern is true, the last placeholder will be of the form -/// ${0:…}, indicating the cursor should stay there. void getSignature(const CodeCompletionString &CCS, std::string *Signature, std::string *Snippet, - std::string *RequiredQualifiers = nullptr, - bool CompletingPattern = false); + std::string *RequiredQualifiers = nullptr); /// Assembles formatted documentation for a completion result. This includes /// documentation comments and other relevant information like annotations. 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 @@ -95,22 +95,7 @@ } void getSignature(const CodeCompletionString &CCS, std::string *Signature, - std::string *Snippet, std::string *RequiredQualifiers, - bool CompletingPattern) { - // Placeholder with this index will be ${0:…} to mark final cursor position. - // Usually we do not add $0, so the cursor is placed at end of completed text. - unsigned CursorSnippetArg = std::numeric_limits::max(); - if (CompletingPattern) { - // In patterns, it's best to place the cursor at the last placeholder, to - // handle cases like - // namespace ${1:name} { - // ${0:decls} - // } - CursorSnippetArg = - llvm::count_if(CCS, [](const CodeCompletionString::Chunk &C) { - return C.Kind == CodeCompletionString::CK_Placeholder; - }); - } + std::string *Snippet, std::string *RequiredQualifiers) { unsigned SnippetArg = 0; bool HadObjCArguments = false; bool HadInformativeChunks = false; @@ -192,9 +177,7 @@ case CodeCompletionString::CK_Placeholder: *Signature += Chunk.Text; ++SnippetArg; - *Snippet += - "${" + - std::to_string(SnippetArg == CursorSnippetArg ? 0 : SnippetArg) + ':'; + *Snippet += "${" + std::to_string(SnippetArg) + ':'; appendEscapeSnippet(Chunk.Text, Snippet); *Snippet += '}'; break; 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 @@ -3135,12 +3135,10 @@ })cpp", /*IndexSymbols=*/{}, Options); - // 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}")))); - // However, snippets for functions must *not* end with $0. + snippetSuffix(" (${1:condition}) {\n${2:statements}\n}")))); EXPECT_THAT(Results.Completions, Contains(AllOf(named("while_foo"), snippetSuffix("(${1:int a}, ${2:int b})")))); 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 @@ -23,12 +23,10 @@ CCTUInfo(Allocator), Builder(*Allocator, CCTUInfo) {} protected: - void computeSignature(const CodeCompletionString &CCS, - bool CompletingPattern = false) { + void computeSignature(const CodeCompletionString &CCS) { Signature.clear(); Snippet.clear(); - getSignature(CCS, &Signature, &Snippet, /*RequiredQualifier=*/nullptr, - CompletingPattern); + getSignature(CCS, &Signature, &Snippet, /*RequiredQualifier=*/nullptr); } std::shared_ptr Allocator; @@ -145,12 +143,8 @@ Builder.AddChunk(CodeCompletionString::CK_SemiColon); return *Builder.TakeString(); }; - computeSignature(MakeCCS(), /*CompletingPattern=*/false); + computeSignature(MakeCCS()); EXPECT_EQ(Snippet, " ${1:name} = ${2:target};"); - - // When completing a pattern, the last placeholder holds the cursor position. - computeSignature(MakeCCS(), /*CompletingPattern=*/true); - EXPECT_EQ(Snippet, " ${1:name} = ${0:target};"); } TEST_F(CompletionStringTest, IgnoreInformativeQualifier) {