[PATCH] D50835: [clangd] Add parantheses while auto-completing functions.

Kadir Cetinkaya via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 17 07:32:38 PDT 2018


kadircet marked 3 inline comments as done.
kadircet added inline comments.


================
Comment at: clangd/CodeComplete.cpp:1377
+      // Check whether function has any parameters or not.
+      LSP.textEdit->newText += SnippetSuffix.size() > 2 ? "(${0})" : "()";
+    else
----------------
ioeric wrote:
> There seems to be no guarantee on whether the snippet is function arg template when `SnippetSuffix.size() > 2`. A heuristic we could use is probably checking that the template starts with `(` and ends with `)`? Alternatively, we could try to avoid generating the proper snippet according to the flag when we still have the function declaration around. Not sure if this is feasible for index results though.
Actually I was first trying to directly look at function argument count as you mentioned, but unfortunately Symbols coming from index don't have any declarations. Therefore it turns back to looking at Signature in this case, which is same with this one. Apart from that, IIUC, SnippetSuffix contains anything only when completion item is a function otherwise it is empty. So IMO this check should be OK.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50835





More information about the cfe-commits mailing list