From 6c9f15c533811937b51be1e1f8975fc54e18f40b Mon Sep 17 00:00:00 2001 From: Kadir Cetinkaya Date: Fri, 17 Aug 2018 15:42:54 +0000 Subject: [clangd] Add parantheses while auto-completing functions. Summary: Currently we only add parantheses to the functions if snippets are enabled, which also inserts snippets for parameters into parantheses. Adding a new option to put only parantheses. Also it moves the cursor within parantheses or at the end of them by looking at whether completion item has any parameters or not. Still requires snippets support on the client side. Reviewers: ioeric, ilya-biryukov, hokein Reviewed By: ioeric Subscribers: MaskRay, jkorous, arphaman, cfe-commits Differential Revision: https://reviews.llvm.org/D50835 llvm-svn: 340040 --- clang-tools-extra/clangd/CodeComplete.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'clang-tools-extra/clangd/CodeComplete.cpp') diff --git a/clang-tools-extra/clangd/CodeComplete.cpp b/clang-tools-extra/clangd/CodeComplete.cpp index 36d0f21ed09..df438b4836d 100644 --- a/clang-tools-extra/clangd/CodeComplete.cpp +++ b/clang-tools-extra/clangd/CodeComplete.cpp @@ -1413,8 +1413,17 @@ CompletionItem CodeCompletion::render(const CodeCompleteOptions &Opts) const { LSP.additionalTextEdits.push_back(FixIt); } } - if (Opts.EnableSnippets) - LSP.textEdit->newText += SnippetSuffix; + if (Opts.EnableSnippets && !SnippetSuffix.empty()) { + if (!Opts.EnableFunctionArgSnippets && + ((Kind == CompletionItemKind::Function) || + (Kind == CompletionItemKind::Method)) && + (SnippetSuffix.front() == '(') && (SnippetSuffix.back() == ')')) + // Check whether function has any parameters or not. + LSP.textEdit->newText += SnippetSuffix.size() > 2 ? "(${0})" : "()"; + else + LSP.textEdit->newText += SnippetSuffix; + } + // FIXME(kadircet): Do not even fill insertText after making sure textEdit is // compatible with most of the editors. LSP.insertText = LSP.textEdit->newText; -- cgit v1.2.3