Dart-Code / Dart-Code

Dart and Flutter support for VS Code
https://dartcode.org/
MIT License
1.5k stars 307 forks source link

Getter and Setter generator #1616

Open bramvbilsen opened 5 years ago

bramvbilsen commented 5 years ago

Feature Request

There is an extremely useful feature in IntelliJ which allows you to automatically generate setters and getters for a class's member variables. This would be amazing to have in VS Code!

(Apologies if this feature already exists, I have not found it.)

DanTup commented 5 years ago

There's an "Encapsulate field" assist - is this what you're looking for?

Screenshot 2019-04-12 at 19 11 48 Screenshot 2019-04-12 at 19 11 53
bramvbilsen commented 5 years ago

@DanTup It is! ... kinda. In IntelliJ, I can create getters and setters separately (I do not always need a setter for example) and for multiple variables at once. Also, with the current implementation you can only generate the getter and setter for a variable that is not private. I'd already made sure all of my variables were private when I started declaring them, thus for the generation to work, I had to refactor those to public vars. In IntelliJ, it Is possible to create getters and setters for variables that are already private.

But the Encapsulate field function is definitely nice to have, didn't know about it yet!

DanTup commented 5 years ago

Ah, I see. Can you give a screenshot of how it looks in IntelliJ? Most functionality like this powered by the analysis server (the VS Code plugin doesn't parse any code like this itself) so I wonder whether it's doing its own (IntelliJ does currently parse the code) or if it's there somewhere and I've just not wired it up.

Thanks!

bramvbilsen commented 5 years ago

Here are some screenshots of what it looks like in IntelliJ:

Screenshot 2019-04-13 at 13 43 31 Screenshot 2019-04-13 at 13 43 45 Screenshot 2019-04-13 at 13 43 50

The last one shows how easy it is to generate them for multiple member variables at once, which is something I use a lot!
Hope this helps :)

DanTup commented 5 years ago

@pq are these coded directly in the IntelliJ plugin using its AST rather than from the server?

pq commented 5 years ago

@DanTup: I believe these are from the Dart Plugin (and not server).

See, for example:

https://github.com/JetBrains/intellij-plugins/blob/master/Dart/src/com/jetbrains/lang/dart/ide/generation/DartGenerateGetterAction.java

DanTup commented 5 years ago

Ah, got it - not something we can easily piggy-back then. Do you know if there are any analytics on how much it's used? Since it'd need work in the server, it'd be good to know if it's used much (or alternatively, we can see if this issue gets many 👍 's).

pq commented 5 years ago

I'm not sure about analytics but believe jetbrains tracks them.

@devoncarew or @alexander-doroshko could elaborate?

alexander-doroshko commented 5 years ago

I'm afraid I don't have numbers.

Ndirangug commented 3 years ago

I'd really love this feature

Ndirangug commented 3 years ago

I'd really love this feature

I found this extension https://marketplace.visualstudio.com/items?itemName=PeterHdd.dartgettersetter