MartinJohns / vscode-inline-types

MIT License
45 stars 16 forks source link

[Feat Request] support inline params name #1

Closed axetroy closed 6 years ago

axetroy commented 6 years ago

This extension is awesome and useful.

Can you consider to add a feature for CallExpression AST node?

before:

function getUserInfo(name: string): void {
  //
}

getUserInfo("username");

after:

function getUserInfo(name: string): void {
  //
}

// "name: " is a decorator, create by extension
getUserInfo(name: "username");
MartinJohns commented 6 years ago

Hey @axetroy! I'm glad you like the extension, and I'm surprised someone actually found it. :-)

I can add the feature you want this evening, and I plan to make the different options configurable using the VS Code settings. And there are some gotchas and bugs which I also will tackle soon.

MartinJohns commented 6 years ago

Hey @axetroy,

When testing this new feature I've noticed something and I'd like to hear your opinion on it, as you suggested the feature.

When a variable is passed as the argument that matches the parameters name, should there still be a decoration rendered?

For example:

function someFunc(name: string, age: number, job: string): void { /* ... */ }

const name = 'Bob';
const occupation = 'Builder';
someFunc(name, 40, occupation);

Should this result in a rendered decoration: someFunc(name: name, age: 40, job: occupation); Or omit the decoraton: someFunc(name, age: 50, job: occupation);

I tend to prefer the omit option, as the repetition serves no purpose.

MartinJohns commented 6 years ago

I've opted for the omit version. If you desire the opposite, please just open a new feature request. :-)

I've also released version 0.2.0 which contains this feature.

axetroy commented 6 years ago

@MartinJohns great!

I would like to enable this feature as default.

If you were used Webstorm, you should found this feature is supported by build-in.

It's clear to known what params you call with this function.

for example:

before:

function createPoint(x: number, y: number) {
  return {
    x,
    y
  };
}

const point = createPoint(0, 1);

after:

1

with this feature, I have clearly known that x = 0, y = 1 and will not mistake them