r/node • • Dec 09 '18

LPT: configure auto parentheses for methods in VSCode

https://gfycat.com/TameSphericalAnnelid
288 Upvotes

31 comments sorted by

70

u/[deleted] Dec 09 '18 edited Dec 09 '18

Coming from Xcode, it felt foreign for methods to not autocomplete with open parentheses with parameter options in place (meaning you can simply start typing to input parameters.)

Fortunately you can configure VSCode's settings to do this!

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

(In the gif, I'm pressing 'a' to bring up autocomplete, Enter to autocomplete, Tab to input x, Tab to input y)

5

u/[deleted] Dec 09 '18

This really cool. Does it work with CommonJs modules? Methods from other files?

3

u/[deleted] Dec 09 '18

Yes it does! :)

4

u/[deleted] Dec 09 '18

Thanks for sharing this!

-3

u/Inzire Dec 09 '18

!Remindme

1

u/RemindMeBot Dec 09 '18

Defaulted to one day.

I will be messaging you on 2018-12-10 22:18:09 UTC to remind you of this link.

CLICK THIS LINK to send a PM to also be reminded and to reduce spam.

Parent commenter can delete this message to hide from others.


FAQsCustomYour RemindersFeedbackCodeBrowser Extensions

0

u/[deleted] Dec 10 '18

[deleted]

1

u/dotpaul Dec 15 '18

!remindme

11

u/CheeseFest Dec 09 '18

asks obligatory question about your spiffy syntax highlighting...

5

u/dr_steve_bruel Dec 09 '18

Wow I was wondering how to do that. Some methods would create parentheses but most would not.

4

u/[deleted] Dec 09 '18

One gotchya with this setting is that methods declared as variables, i.e.

let myFunc = (obj) => {  }

will not auto-parentheses for myFunc. But I think this is intuitive for cases where you're passing a function reference around v.s. calling an explicit function.

4

u/jbkly Dec 10 '18

That makes sense, it's an anonymous function.

4

u/PM-YOUR-BOOKS Dec 10 '18

Boo for using a let instead of a const for function definition. ;)

5

u/GottfriedEulerNewton Dec 10 '18

You don't know what's next for myFunc

1

u/gigastack Dec 10 '18

It doesn’t really matter since it’s a complex object. Const just prevents accidental redeclaration.

2

u/GottfriedEulerNewton Dec 10 '18

No, i know and agree const is best.

I was just being "funny"

4

u/banananize Dec 09 '18

Looks like you're using Shades of Purple. It's my favorite. ✌️

4

u/NoInkling Dec 10 '18

I tried this for a while but it started to get annoying due to the flexibility of params in a lot of JS functions (overloads, essentially), and the fact that functions are objects so you don't always want to invoke them.

2

u/cinnic Dec 10 '18

Anyone know if this is possible in webstorm?

2

u/imax89 Dec 10 '18

I dont remember it exactly , but it’s always been available in WS. I use WS since the version 2016.1

1

u/BabyLegsDeadpool Dec 10 '18

When I saw this, my first thought was "LPT: use WebStorm." This has been standard for a long time.

1

u/amplify895 Dec 10 '18

Is there an Atom package similar to this??

1

u/albtech87 Dec 10 '18

!Remindme

1

u/rozzzly Dec 10 '18

!remindme

1

u/rozzzly Dec 23 '18

!remindme

1

u/goodgoshitsotis Dec 10 '18

Function add(...): number

Does ": number" identify the return type by validating the value?

Apologies if this is a silly question. I have never seen that after a function before.

2

u/joemckie Dec 10 '18

It’s FlowType/TypeScript

0

u/[deleted] Dec 10 '18

[deleted]

3

u/goodgoshitsotis Dec 10 '18

Thanks for taking the time to answer and thanks to /u/joemckie as well.

Totally get it read the docs

Thanks again!