nridge created this revision.
nridge added reviewers: hokein, ilya-biryukov, sammccall.
Herald added subscribers: usaxena95, kadircet, arphaman.
Herald added a project: All.
nridge requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang-tools-extra.
$0 can only be used as a tab stop, not as a placeholder (e.g.
`${0:expression}` is not valid)
Fixes https://github.com/clangd/clangd/issues/1190
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D128621
Files:
clang-tools-extra/clangd/CodeComplete.cpp
clang-tools-extra/clangd/CodeCompletionStrings.cpp
clang-tools-extra/clangd/CodeCompletionStrings.h
clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
clang-tools-extra/clangd/unittests/CodeCompletionStringsTests.cpp
Index: clang-tools-extra/clangd/unittests/CodeCompletionStringsTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/CodeCompletionStringsTests.cpp
+++ 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<clang::GlobalCodeCompletionAllocator> 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) {
Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ 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})"))));
Index: clang-tools-extra/clangd/CodeCompletionStrings.h
===================================================================
--- clang-tools-extra/clangd/CodeCompletionStrings.h
+++ 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.
Index: clang-tools-extra/clangd/CodeCompletionStrings.cpp
===================================================================
--- clang-tools-extra/clangd/CodeCompletionStrings.cpp
+++ 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<unsigned>::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;
Index: clang-tools-extra/clangd/CodeComplete.cpp
===================================================================
--- clang-tools-extra/clangd/CodeComplete.cpp
+++ 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);
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits