56

Is is possible to tweak VS Code so that when function gets autocompleted, it is written with () instead of just plain function name?

For example when I type str and autocomplete to strlen I would like to get strlen(), it saves quite some time.

starball
  • 20,030
  • 7
  • 43
  • 238
Rokas Lakštauskas
  • 1,078
  • 1
  • 8
  • 17

13 Answers13

69

It can be solved by ticking javascript.suggest.completeFunctionCalls property up.

yuriy636
  • 11,171
  • 5
  • 37
  • 42
  • Appears not to work for methods -- opened a related question: https://stackoverflow.com/questions/66676976/vscode-autocomplete-function-and-method-parentheses-javascript – ultraGentle Mar 17 '21 at 16:16
21

For Python when using the Python extension the relevant setting is:

python.autocomplete.addBrackets

As per the comment bellow, if you use Pylance the setting is:

python.analysis.completeFunctionParens

Eyal Levin
  • 16,271
  • 6
  • 66
  • 56
13

For C and C++, use this setting:

"C_Cpp.autocompleteAddParentheses": true
yuriy636
  • 11,171
  • 5
  • 37
  • 42
The Quantum Physicist
  • 24,987
  • 19
  • 103
  • 189
8

Some language extensions allow using ( as a so-called "commit character" to trigger the insertion of a completion item. This works in at least TypeScript, JavaScript and Haxe.

If "editor.autoClosingBrackets" has not been disabled, this will also auto-insert the closing ).

If it doesn't work for a particular language extension, perhaps consider opening a feature request on the repository in question.

Gama11
  • 31,714
  • 9
  • 78
  • 100
  • Thanks, it works great on JS! Now I need to find a way to make it work with PHP. – Rokas Lakštauskas Apr 08 '19 at 06:28
  • 1
    That has to be handled by the language extension. Perhaps you open a feature request on the PHP extension / check if they would accept a pull request with this feature. – Gama11 Apr 08 '19 at 08:51
  • This does not work with Flutter as well after toggling the option mentioned above! Every time I have to add the brackets manually :D - SG – SSG Feb 09 '21 at 22:15
  • Works for python too! – sos Jun 06 '22 at 08:45
6

Just like @snr's solution in JavaScript.

For TypeScript, you can try this:

"typescript.suggest.completeFunctionCalls": true

iamnotnano
  • 61
  • 1
  • 2
5

in settings.json file Set "python.autoComplete.addBrackets": true.

set "python.autoComplete.addBrackets": true

Dumidu Pramith
  • 376
  • 3
  • 8
  • 1
    Please consider including the code itself rather than (just) a screenshot, as the former is more accessible and allows text searching and copying. – kelvin May 22 '21 at 17:45
  • 5
    I am using Pylance and found I did not need ```"python.autocomplete.addBrackets": true``` but what did work for me was ```"python.analysis.completeFunctionParens": true``` – Cam Nov 28 '21 at 11:48
5

For Python, when using Pylance, add in settings.json:

"[python]": {
    "python.analysis.completeFunctionParens": true,
},
yuriy636
  • 11,171
  • 5
  • 37
  • 42
Darcy
  • 51
  • 1
  • 1
4

You can go-to File->Preferences->Settings
Input pythonenter image description here

And click on Edit in settings.json
After that write down "python.analysis.completeFunctionParens": true, and reload VS Code

Damir Nafikov
  • 162
  • 1
  • 9
1

It's possible. You can create your own snippets, and it will be shown in the intellisense: User Defined snippets. You can also use snippet-creator extension for comfort.

amirali
  • 1,888
  • 1
  • 11
  • 32
0

If you are working in flutter, try resetting all settings of VS Code because it do add parentheses by default.

0

In the latest release of vs code open setting > search "parenthesis" > scroll for

python>analysis: Complete Function Parens

mark tick Then you are ready to go.

0

There's currently no general setting that applies to all languages. VS Code leaves this to individual language services to implement (which is actually very reasonable given its extensibility model).

  • For JavaScript, use "javascript.suggest.completeFunctionCalls": true. This will cause functions to be completed with their parameter signature.

  • Analogously, for TypeScript, use "typescript.suggest.completeFunctionCalls": true.

  • For the PHP Intelephense extension, the default value of the intelephense.completion.triggerParameterHints setting is true.

  • For the Python extension, use "python.analysis.completeFunctionParens": true.

  • For C and C++ using the vscode-cpptools extension, use "C_Cpp.autocompleteAddParentheses": true.

  • For the Rust Analyzer extension, use rust-analyzer.completion.callable.snippets setting with either the value "fill_arguments", or "add_parenthesis". "fill_arguments" adds parenthesis and pre-fills arguments.

  • I did a cursory search through the Java extension's settings and didn't find anything that looked related (maybe I just missed it). I also tried googling for feature-request issue tickets ("github vscode java issues autocomplete function parenthesis") and didn't find anything from a cursory look through the top search results.

  • For C#, see Method intellisense does not add parentheses #1453, which is closed to defer to the Roslyn issue IDE: Intellisense: Insert full method call #12363

  • The Dart extension just does this by default.

Loosely related: this (fairly outdated and closed) VS Code issue ticket: Autocomplete should insert parenthesis for methods #1021.

There are some extensions I'm not sure about their behaviour (and am too lazy to try out right now): R, Go, etc.

starball
  • 20,030
  • 7
  • 43
  • 238
0

In the new version of VS Code, there is no UI element we can check/uncheck to enable this feature for javascript or typescript but as another Stackoverflow solution suggests, you need to edit the settings.json file in your system and add the following lines to your JSON object

  1. F1 or 'Ctrl + Shift + P' to bring the command palette.
  2. Select Settings.json for user settings.
  3. Paste the following to the end of the file and save.

"typescript.suggest.completeFunctionCalls": true,
"javascript.suggest.completeFunctionCalls": true,

Originally posted at: VSCode autocomplete function *and method* parentheses (js/ts)