[PATCH] D65866: Code completion should not ignore default parameters in functions.
UTKARSH SAXENA via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 7 07:01:34 PDT 2019
usaxena95 updated this revision to Diff 213871.
usaxena95 added a comment.
Removed unused include of logger.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D65866/new/
https://reviews.llvm.org/D65866
Files:
clang-tools-extra/clangd/CodeCompletionStrings.cpp
clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -939,6 +939,25 @@
EXPECT_TRUE(Results.Completions.empty());
}
+
+TEST(CompletionTest, DefaultArgs) {
+ clangd::CodeCompleteOptions Opts;
+ std::string Context = R"cpp(
+ int X(int A = 0);
+ int Y(int A, int B = 0);
+ int Z(int A, int B = 0, int C = 0, int D = 0);
+ )cpp";
+ EXPECT_THAT(completions(Context + "int y = X^", {}, Opts).Completions,
+ UnorderedElementsAre(Labeled("X(int A = 0)")));
+ EXPECT_THAT(completions(Context + "int y = Y^", {}, Opts).Completions,
+ UnorderedElementsAre(AllOf(Labeled("Y(int A, int B = 0)"),
+ SnippetSuffix("(${1:int A})"))));
+ EXPECT_THAT(completions(Context + "int y = Z^", {}, Opts).Completions,
+ UnorderedElementsAre(
+ AllOf(Labeled("Z(int A, int B = 0, int C = 0, int D = 0)"),
+ SnippetSuffix("(${1:int A})"))));
+}
+
SignatureHelp signatures(llvm::StringRef Text, Position Point,
std::vector<Symbol> IndexSymbols = {}) {
std::unique_ptr<SymbolIndex> Index;
Index: clang-tools-extra/clangd/CodeCompletionStrings.cpp
===================================================================
--- clang-tools-extra/clangd/CodeCompletionStrings.cpp
+++ clang-tools-extra/clangd/CodeCompletionStrings.cpp
@@ -32,6 +32,21 @@
}
}
+void appendCodeCompletionString(const CodeCompletionString &CCS, std::string *Out) {
+ for (const CodeCompletionString::Chunk &C : CCS) {
+ switch (C.Kind) {
+ case CodeCompletionString::CK_Optional:
+ assert(C.Optional &&
+ "Expected the optional code completion string to be non-null.");
+ appendCodeCompletionString(*C.Optional, Out);
+ break;
+ default:
+ *Out += C.Text;
+ break;
+ }
+ }
+}
+
bool looksLikeDocComment(llvm::StringRef CommentText) {
// We don't report comments that only contain "special" chars.
// This avoids reporting various delimiters, like:
@@ -138,6 +153,10 @@
*Snippet += Chunk.Text;
break;
case CodeCompletionString::CK_Optional:
+ assert(Chunk.Optional &&
+ "Expected the optional code completion string to be non-null.");
+ // No need to create placeholders for default arguments in Snippet.
+ appendCodeCompletionString(*Chunk.Optional, Signature);
break;
case CodeCompletionString::CK_Placeholder:
*Signature += Chunk.Text;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65866.213871.patch
Type: text/x-patch
Size: 2686 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190807/dc066e6b/attachment.bin>
More information about the cfe-commits
mailing list