AntoniRokitnicki / AdvancedExpressionFolding

Advanced Java Folding 2 ​(Fork)​
https://plugins.jetbrains.com/plugin/23659-advanced-java-folding-2-fork-
Apache License 2.0
6 stars 2 forks source link

[FEATURE] Switches for different features #111

Open remal opened 2 months ago

remal commented 2 months ago

Is your feature request related to a problem? Please describe. Lombok emulation confuses me often.

Describe the solution you'd like Plugin settings with an ability to turn off Lombok emulation

Additional context Lombok emulation works great for DTOs. However, for services I'd personally prefer to see every single getter.

BTW I'm a huge Lombok fan, but for some reason this feature here confuses me.

AntoniRokitnicki commented 2 months ago

I do know Lombok emulation can be confusing. I have a similar issue sometimes as well.

My first idea to resolve your issue would be to have like an input text where you can put regex to turn off @Data for.

However, there is a new feature I just started to work on.

My idea is to create field-level @Getter with a new feature

for example:

LombokTestData data;
public LombokTestData getData() {
    return data;
}

would fold into @Getter LombokTestData data;

but

LombokTestData data;
public LombokTestData getData() {
    //anything else except `return data;` here
}

would fold into

@Getter(dirty) LombokTestData data;

later it can be extended to @Getter(throwIfNull), same stuff with @Setter.

I can also add a checkbox to turn off folding on the dirty getter.

Adding anything else that a checkbox is too complex now, for example, I extended the checkbox view Screenshot 2024-05-15 at 19 21 39 but it's not working in the current versions of IntelliJ, because they changed how CodeFoldingOptionsProvider works. I'd need to rewrite everything (also I'd need to abandon older versions of IntelliJ) and I don't want to do it right now.

P.S. I can add a checkbox to just ignore Lombok annotations (or just @Getter) on .*Service.* classes if you want. Maybe you have some better ideas on how to handle this issue. Maybe you have a different issue ;-)

remal commented 1 month ago

Hi @AntoniRokitnicki !

Actually, my issue is not my code. My issue is library code. Obviously, I can't add comments there.

I'd suggest not to add class-level annotations, but to add field-level annotations. It will be less confusing in my opinion. The main concern is that sometimes getters have other return types than fields. Example: ArrayList field, but List getter. I wouldn't expect this plugin to hide this moment behind an annotation.

I can't filter by @*.Service annotation. It's not only about Spring (or alternatives). Gradle has services too, but no @Service annotation. When you develop a Gradle plugin, you can't filter by an annotation. Also, Gradle tasks don't always have annotations.

The issue with Gradle, actually, is that I remember that in some version return type of some getter was changed. So, I'd like to see getters to be sure that I remember moments like this correctly. Otherwise it's quite easy to break compatibility with some old version of Gradle.

BTW where does your screenshot come from? I can't find any settings for this plugin.

AntoniRokitnicki commented 1 month ago

Hi @remal,

Thank you for your suggestions and detailed feedback.

For now, I’d rather not add very specific features. However, I was reading over the weekend that it might be possible to detect whether the code is inside a library or not. Would turning off folding for code in JAR files be useful for you?

Additionally, I have added a lot of Lombok features in the latest canary release, which you might find useful. All annotations are now at the field level as well. https://github.com/AntoniRokitnicki/AdvancedExpressionFolding?tab=readme-ov-file#canary-installation-every-commits-creates-a-new-version

you can see them here without installing: https://github.com/AntoniRokitnicki/AdvancedExpressionFolding/blob/master/folded/LombokTestData-folded.java

Regarding the screenshot, it is from an older version of IntelliJ. Due to a breaking API change, this feature stopped working in the current versions.