[clang-tools-extra] 4fb62e1 - [clangd] Mark completions as plain-text when there's no snippet part
Sam McCall via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 12 09:44:30 PST 2021
Author: Sam McCall
Date: 2021-11-12T18:44:20+01:00
New Revision: 4fb62e138398263dbefaa499c712929562bdf3bd
URL: https://github.com/llvm/llvm-project/commit/4fb62e138398263dbefaa499c712929562bdf3bd
DIFF: https://github.com/llvm/llvm-project/commit/4fb62e138398263dbefaa499c712929562bdf3bd.diff
LOG: [clangd] Mark completions as plain-text when there's no snippet part
This helps nvim support the "repeat" action
Fixes https://github.com/clangd/clangd/issues/922
Added:
Modified:
clang-tools-extra/clangd/CodeComplete.cpp
clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/CodeComplete.cpp b/clang-tools-extra/clangd/CodeComplete.cpp
index 8c88884b292d..f1f1cae690bc 100644
--- a/clang-tools-extra/clangd/CodeComplete.cpp
+++ b/clang-tools-extra/clangd/CodeComplete.cpp
@@ -2113,8 +2113,12 @@ CompletionItem CodeCompletion::render(const CodeCompleteOptions &Opts) const {
// FIXME(kadircet): Do not even fill insertText after making sure textEdit is
// compatible with most of the editors.
LSP.insertText = LSP.textEdit->newText;
- LSP.insertTextFormat = Opts.EnableSnippets ? InsertTextFormat::Snippet
- : InsertTextFormat::PlainText;
+ // Some clients support snippets but work better with plaintext.
+ // So if the snippet is trivial, let the client know.
+ // https://github.com/clangd/clangd/issues/922
+ LSP.insertTextFormat = (Opts.EnableSnippets && !SnippetSuffix.empty())
+ ? InsertTextFormat::Snippet
+ : InsertTextFormat::PlainText;
if (InsertInclude && InsertInclude->Insertion)
LSP.additionalTextEdits.push_back(*InsertInclude->Insertion);
diff --git a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
index c63eecbe5091..aff6f6cf25ff 100644
--- a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -1887,6 +1887,11 @@ TEST(CompletionTest, Render) {
EXPECT_EQ(R.insertText, "Foo::x(${0:bool})");
EXPECT_EQ(R.insertTextFormat, InsertTextFormat::Snippet);
+ C.SnippetSuffix = "";
+ R = C.render(Opts);
+ EXPECT_EQ(R.insertText, "Foo::x");
+ EXPECT_EQ(R.insertTextFormat, InsertTextFormat::PlainText);
+
Include.Insertion.emplace();
R = C.render(Opts);
EXPECT_EQ(R.label, "^Foo::x(bool) const");
More information about the cfe-commits
mailing list