r/node • u/[deleted] • Dec 09 '18
LPT: configure auto parentheses for methods in VSCode
https://gfycat.com/TameSphericalAnnelid11
u/CheeseFest Dec 09 '18
asks obligatory question about your spiffy syntax highlighting...
14
Dec 09 '18
Shades of Purple by Ahmad Awais https://marketplace.visualstudio.com/items?itemName=ahmadawais.shades-of-purple
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
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
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
myFunc1
u/gigastack Dec 10 '18
It doesn’t really matter since it’s a complex object. Const just prevents accidental redeclaration.
2
4
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
1
1
1
1
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
0
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!
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!
(In the gif, I'm pressing 'a' to bring up autocomplete, Enter to autocomplete, Tab to input x, Tab to input y)