Vscode-cpptools: Auto adding brackets for function calls

Created on 14 Jul 2017  Â·  42Comments  Â·  Source: microsoft/vscode-cpptools

During auto-completion for methods, brackets do not get inserted automatically. Most of the time they are required and it's easier to delete them than insert them manually. Calling methods is common than passing them as arguments.

Eg: Tab or Return after "size_t n = name.len" should autocomplete to "size_t n = name.length()" rather than "size_t n = name.length" with the cursor between/after (according to whether there is function argument) the brackets.

Feature Request Language Service quick fix

Most helpful comment

Still waiting for this feature to be implemented. It is this feature that keeps me using CLion instead of VSCode.

All 42 comments

I think this idea has merit, but it's not something that we can implement in the extension. You would have to ask VS Code to implement it.

We do not have control of the cursor position and if we supplied the completion result in your example, the cursor would end up after the closing paren in every case. This would be ok for methods with no arguments, but not for methods requiring arguments. Even if we could put the cursor in the right place, that would mess up VS Code's notifications for parameter hints since they expect the user to type the opening paren before they will initiate a request for parameter hints.

There's a way to do this with certain language extensions (typescript, go). Details here: https://github.com/Microsoft/vscode-go/issues/276#issuecomment-205439716

@bobbrow I'm sorry but this is BS, Several other language extensions (Go, TS, JS, C#) added this and it is a must for C/C++. And actually, the VS Code team does not plan to do this, I quote "we defer it to the language service" from here: https://github.com/Microsoft/vscode/issues/1021#issuecomment-171893794 .

So there is no one other than the cpp team that can give us this functionality.

I'm seeing typescript invoking completion when ( is typed? Is that the desired result or something else?

I think we need to add ( as a "commit character" for methods (i.e. https://github.com/OmniSharp/omnisharp-vscode/issues/1487 ). It's part of the CompletionItem type in the latest language server protocol, but the one we use appears to be old and is missing it (https://microsoft.github.io/language-server-protocol/specification ).

I actually tried to look through the code but I didn't even manage to find the part where the autocompletion happens. So I hope someone can either implement this or point to the code which is responsible for completion.

@IgorOne It's implemented in our closed-source Microsoft.VSCode.CPP.Extension.* binary. I agree that we should fix this, but I'm not sure of an ETA yet (seems almost more like a bug than a feature request).

Our latest 0.21.0-insiders3 triggers completion when ( is used. Is that good enough or is adding the () on Enter/Tab/Click, still desired?

Setting C_Cpp.updateChannel to "Insiders" is another way to get the update.

Coming from JetBrains world, I'd also find this feature extremely useful. I'd much rather see it implemented in a way that @hd2015 describes, so as soon as you press enter to accept a suggestion, a pair of brackets is added for me (provided it's a function call, not a variable) and cursor is placed either inside of after them (which is what happens in JetBrains IDEs). What @sean-mcmanus talks about is already present in VSCode (at least in my version), but it's not exactly what we're looking for as all it does is adding a closing bracket as soon as you type opening one, which has nothing to do with IntelliSense and code completion.

@JacasEdi The change we added was that typing "(" commits the completion. The only difference is typing ( to finish the completion versus typing tab/enter. I'll keep this issue open to track the tab/enter method.

UPDATE: We have a fix, but it won't be in 0.22.0-insiders, because we intend to add a setting that controls how the parenthesis completion.

@sean-mcmanus Is this problem solved? The autocompletion of brackets is really in-need.

@foreverlms Yeah, we just need to add some setting like C_Cpp.methodCompletion: "AddNoParens", "AddLeftParen", "AddBothParens". The work to do that has been post-poned till later.

@sean-mcmanus Thanks! And I also want to ask that how can I automatically turn . after pointers into ->? I haven't found a specific answer. Appreciate for your reply.

@foreverlms You found the issue tracking that at https://github.com/Microsoft/vscode-cpptools/issues/862.

is it fixed yet ? coming from PyCharm this feature is a must for me

@Raymoun17 Not fixed yet -- needs settings added.

yes, this feature is very important. from visual studio 2017 and use c++ ' user.

This feature is very important and I also want this feature, too.

Still waiting for this feature to be implemented. It is this feature that keeps me using CLion instead of VSCode.

It would be really awesome to get this feature.

Agreed, this feature would be excellent to have.

It can be solved by ticking javascript.suggest.completeFunctionCalls property up. Here is the gif.

https://gfycat.com/cleveractualhornbill

finally

Le sam. 8 févr. 2020 à 06:18, Soner notifications@github.com a écrit :

It can be solved by ticking javascript.suggest.completeFunctionCalls
property up. Here is the gif.

https://gfycat.com/cleveractualhornbill

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/microsoft/vscode-cpptools/issues/882?email_source=notifications&email_token=AEX6TYVJYWDD552CMNATAQTRB2IJ5A5CNFSM4DTAGX6KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOELFPSQY#issuecomment-583727427,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AEX6TYW3A26M6EI7INV6VNTRB2IJ5ANCNFSM4DTAGX6A
.

@akrsnr Yes, but that only works for Javascript and not C.

@hhc97 it does work in js, ts, but it doesn't work in js inside html:

<script>
  document.getElementById
</script>

Here getElementById didn't get the parenthesis added :(

@dodalovic What I mean is that it does not work when coding in the C programming language.

Almost 3 years old issue and still no fix. :(

This missing feature is the reason I prefer atom with the autocomplete-clang package. It is much more comfortable... but it's still atom -.-

Wait this feature and " . to -> "

Has this feature been added yet?

@Er2620
This feature has not been added. It's currently planned to be worked on after version 1.0.0 of the extension.

@Er2620
This feature has not been added. It's currently planned to be worked on after version 1.0.0 of the extension.

Ok, thank you for letting me know.

status of this feature?

@superRaptor911 the status of this feature request has not changed. It's under the milestone that's post version 1.0.0 of the extension.

Would really like this feature and surprised its taking so long.

This feature is really important, please

I would like this essential feature too!

Ridiculous. Such an essential and easy to implement feature but it takes ages because of *

Commented moderated. We can understand frustration, but please keep it respectful here. Microsoft Code of Conduct

Please MS! Just implement this essential feature that makes so many coders happy.

Yeah, I had an implementaton in cpptools from Feb 2019, but we needed some setting to control the behavior, such as C_Cpp.methodCompletion: "AddNoParens", "AddLeftParen", "AddBothParens"...no one submitted a PR to add those settings.

I'm sort of busy working on Windows ARM64 support...trying not to get distracted by random feature requests.

@bobbrow Was there a reason this was moved to Backlog? It seems like it'd be a quick fix.

We haven't lost sight of this. It has sufficient upvotes and will be included in a future milestone. But we can only work on so many things at a time. We will update the milestone when it has been scheduled for a release. Thank you for your patience.

Every text editor has this feature but not this one! I'm surprised and disappointed. This is the only reason of not using vscode.

@bobbrow This has 47 votes now -- seems pretty high to me.

Was this page helpful?
0 / 5 - 0 ratings