mapstruct / mapstruct-idea

An IntelliJ IDEA plugin for working with MapStruct
Other
141 stars 38 forks source link

Code Completion didn't work well. #182

Closed ovaso closed 5 months ago

ovaso commented 7 months ago

just like #75 metioned.

here's idea information: Runtime version: 17.0.10+1-b1087.17 amd64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. Windows 11.0 GC: G1 Young Generation, G1 Old Generation Memory: 4096M Cores: 12 Registry: debugger.new.tool.window.layout=true ide.experimental.ui=true editor.minimap.enabled=true Non-Bundled Plugins: com.intellij.zh (233.287) com.github.exidcuter.dockerregistryexplorer (1.1.0-stable) commit-message-helper-idea-plugin (1.4.1) com.nasller.CodeGlancePro (1.8.1) wu.seal.tool.jsontokotlin (3.7.4) lermitage.intellij.ilovedevtoys (1.10.2) com.markskelton.one-dark-theme (5.10.0) Statistic (4.2.14) indent-rainbow.indent-rainbow (2.2.0) GenerateSerialVersionUID (3.0.3) com.github.wangji92.arthas.plugin (2.44) jclasslib (6.0.4.2) com.github.setial (4.1.1) com.jetbrains.jax.ws (233.13135.65) com.intellij.spring.websocket (233.11799.196) String Manipulation (9.12.0) com.intellij.javaee.ejb (233.11799.196) com.intellij.spring.batch (233.14015.23) net.seesharpsoft.intellij.plugins.csv (3.3.0-233) MavenRunHelper (4.27.1-IJ2022.2) com.intellij.javaee.batch (233.11799.196) com.intellij.bigdatatools.core (233.14475.28) izhangzhihao.rainbow.brackets.lite (1.1.0) org.mapstruct.intellij (1.6.1) com.suusan2go.kotlin-fill-class (1.0.23) SequenceDiagram (3.0.8) com.apifox.uploader (1.2.2) io.github.linwancen.show-comment (2.16.0.2024.03.03_21.46) app.teamhub (17.0.0) com.intellij.bigdatatools.kafka (233.13135.103) cn.yiiguxing.plugin.translate (3.5.6) Kotlin: 233.14475.28-IJ

image

Maven comfiguration:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>x.bv</groupId>
    <artifactId>MapStructTest</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <lombok.version>1.18.30</lombok.version>
        <lombok-mapstruct-binding.version>0.2.0</lombok-mapstruct-binding.version>
        <mapstruct.version>1.5.5.Final</mapstruct.version>
    </properties>

    <dependencies>
        <!-- Lombok -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>${lombok.version}</version>
            <optional>true</optional>
        </dependency>

        <!-- MapStruct -->
        <dependency>
            <artifactId>mapstruct</artifactId>
            <groupId>org.mapstruct</groupId>
            <version>${mapstruct.version}</version>
        </dependency>

        <!-- Lombok-MapStruct-Binding -->
        <dependency>
            <artifactId>lombok-mapstruct-binding</artifactId>
            <groupId>org.projectlombok</groupId>
            <version>${lombok-mapstruct-binding.version}</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.11.0</version>
                <configuration>
                    <annotationProcessorPaths>
                        <path>
                            <artifactId>mapstruct-processor</artifactId>
                            <groupId>org.mapstruct</groupId>
                            <version>${mapstruct.version}</version>
                        </path>
                        <path>
                            <artifactId>lombok</artifactId>
                            <groupId>org.projectlombok</groupId>
                            <version>${lombok.version}</version>
                        </path>
                        <path>
                            <artifactId>lombok-mapstruct-binding</artifactId>
                            <groupId>org.projectlombok</groupId>
                            <version>${lombok-mapstruct-binding.version}</version>
                        </path>
                    </annotationProcessorPaths>
                    <showWarnings>false</showWarnings>
                    <source>17</source>
                    <target>17</target>
                    <encoding>UTF-8</encoding>
                    <jdkToolchain>
                        <version>17</version>
                    </jdkToolchain>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

And case goes like this: Video_2024-03-12_145339

thunderhook commented 7 months ago

Hi @ovaso! I could reproduce this by creating a new project with your pom.xml.

The code completion did not work because there were IDE compile errors in UserDomain and UserVO due to the missing <scope>provided</scope>. Adding this fixed the problem for me.

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>${lombok.version}</version>
            <scope>provided</scope>
            <optional>true</optional>
        </dependency>

Interestingly, when I removed the scope, it still worked. So I would suggest using the `provided' scope as suggested in the lombok maven setup guide.

Thanks for the gifs. Is this a special colour scheme that the user, sex, name, gender fields are displayed with a red colour? If not, it could mean that IntelliJ doesn't know about these fields. And therefore the mapstruct plugin has no knowledge about these fields either.

This smells like a problem with lombok or the lombok idea plugin. You could also use the "Repair IDE" action and see if that helps.

Side note to your pom: the lombok-mapstruct-binding is only needed inside the maven-compiler-plugin dependency block. You can remove it from your regular dependencies.

ovaso commented 7 months ago

hi @thunderhook, thanks for your warm advice and help.

The filed color is red is caused by a theme plugin in Intellij Idea named "One Dark Theme", matters nothing about field recognizing.

I've just tried the solutions you gaved above, things still not going well, the modified pom file was pinned in the following code block

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>x.bv</groupId>
    <artifactId>MapStructTest</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <lombok.version>1.18.18</lombok.version>
        <lombok-mapstruct-binding.version>0.2.0</lombok-mapstruct-binding.version>
        <mapstruct.version>1.5.5.Final</mapstruct.version>
    </properties>

    <dependencies>
        <!-- Lombok -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>${lombok.version}</version>
            <scope>provided</scope>
            <optional>true</optional>
        </dependency>

        <!-- MapStruct -->
        <dependency>
            <artifactId>mapstruct</artifactId>
            <groupId>org.mapstruct</groupId>
            <version>${mapstruct.version}</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.11.0</version>
                <dependencies>
                    <dependency>
                        <artifactId>lombok-mapstruct-binding</artifactId>
                        <groupId>org.projectlombok</groupId>
                        <version>${lombok-mapstruct-binding.version}</version>
                    </dependency>
                </dependencies>
                <configuration>
                    <source>17</source>
                    <target>17</target>
                    <!--<encoding>UTF-8</encoding>-->
                    <!--<jdkToolchain>-->
                    <!--    <version>17</version>-->
                    <!--</jdkToolchain>-->
                    <annotationProcessorPaths>
                        <path>
                            <artifactId>mapstruct-processor</artifactId>
                            <groupId>org.mapstruct</groupId>
                            <version>${mapstruct.version}</version>
                        </path>
                        <path>
                            <artifactId>lombok</artifactId>
                            <groupId>org.projectlombok</groupId>
                            <version>${lombok.version}</version>
                        </path>
                        <path>
                            <artifactId>lombok-mapstruct-binding</artifactId>
                            <groupId>org.projectlombok</groupId>
                            <version>${lombok-mapstruct-binding.version}</version>
                        </path>
                    </annotationProcessorPaths>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

And after runned Repire IDE options, effects shows like this: Video_2024-03-13_103311

Actually nothing changed after changing lombok's scope to provided, but there are several points shows plugin is indeed worked:

  1. when clicking the target or source field, it always take me to the right class file and target field.
  2. when using expression in @Mapping annotation, the completion works to help me to select importted class fields or methods

So if there are any else setting options i've ignored? And if I should make a repo and upload this demo project code?

image
ovaso commented 7 months ago

wait wait, misoperated

thunderhook commented 7 months ago

No problem, I'm happy to help.

That's interesting, so it seems that only the autocomplete is broken. I could not find your actual Intellij version in the first log you provided. Can you write that down?

Yes, it would be cool if you could make the sample project available on GitHub. Could you also add another DTO/VO object with Java getters and setters? We can then narrow down if it is a problem with Lombok or auto-completion in general.

At the moment I'm thinking that another plugin is interfering. But I am not sure if that is even possible.

I will try to reproduce this tonight with the sample project.

ovaso commented 7 months ago

Gladly offering sample source, and I put it here. mapstruct-sample-case

Sample contains two cases (using lombok, using java setter/getter), but autocomplete is still only available on expression field.

And, there are also the ide and plugin info, check README.md file.

Reply in this thread if you need any other setting options config, and i will offer more info

thunderhook commented 7 months ago

Hey, I downloaded the project and it works fine for me.

Instead of me installing all the plugins you use, could you please disable (not uninstall) any plugin and try it after an IDE restart?

ovaso commented 7 months ago

ok, and i will try a restored ide instance in later days to see if it will be well

ovaso commented 7 months ago

I've tried a new idea instance only with Lombok MapStruct Support plugin installed, but completion still not work

neither CE or Utimate can work well

IntelliJ IDEA 2023.3.5 (Community Edition) Build #IC-233.14808.21, built on March 12, 2024 Runtime version: 17.0.10+1-b1087.21 amd64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. Windows 11.0 GC: G1 Young Generation, G1 Old Generation Memory: 2048M Cores: 12 Registry: ide.experimental.ui=true Non-Bundled Plugins: Lombook Plugin (233.14808.21) org.mapstruct.intellij (1.6.1) Kotlin: 233.14808.21-IJ

thunderhook commented 7 months ago

I'm sorry to hear that. I'd like to help you, but without being able to reproduce this, I can't. We'll keep this open. Maybe someone else has the same problem and we can find out what you both have in common.

One last thing, what locale is configured in your environment?

UnclePi979 commented 6 months ago

Same for me (I have even disabled lombok plugin I have even disabled all downloaded plugins). Even using mapstruct-examples still doesn't work.

Problems encountered follows.

Effective features:

  1. Jump to the specified field
  2. Highlight Unmapped property: xxx
  3. Auto-implement mapper interface

Broken features:

  1. Annotation auto-completion, like @Mapping @Mappings, etc.

Configurations

OS: MacOS Pro Apple M1 14.2.1 (23C71) IDEA: IntelliJ IDEA 2023.3.5 (Ultimate Edition) IntelliJ IDEA 2024.1 (Ultimate Edition) pom.xml: https://github.com/mapstruct/mapstruct-examples/blob/main/mapstruct-field-mapping/pom.xml

Gif for screen recording

Apr-11-2024 00-02-50

IDEA plugins follows.

GenerateAllSetter (2.8.4) Go (233.14808.21) Go Template (233.11799.172) Grep Console (12.25.0-IJ2023.3) Jakarta EE: Web Services (JAX-WS) (233.13135.65) MapStruct Support (1.6.1) Maven Helper (4.28.0-IJ2022.2) POJO to JSON (2.0.2) Spring WebSocket (233.11799.196) Translation (3.5.4) Maven (233.14808.21) Maven Extension (233.14808.21) Code Coverage for Java (233.14808.21) Database Tools and SQL (233.14808.21) Docker (233.14808.21) FTP/SFTP/WebDAV Connectivity (233.14808.21) Jakarta EE: Application Servers (233.14808.21) Kubernetes (233.14808.21) Tomcat and TomEE (233.14808.21) Settings Sync (233.14808.21) JavaScript and TypeScript (233.14808.21) JavaScript Debugger (233.14808.21) JSONPath (233.14808.21) Node.js (233.14808.21) Node.js Remote Interpreter (233.14808.21) Polymer & Web Components (233.14808.21) Prettier (233.14808.21) Styled Components & Styled JSX (233.14808.21) AOP Pointcut Language (233.14808.21) Hibernate (233.14808.21) Jakarta EE Platform (233.14808.21) Jakarta EE: Bean Validation (233.14808.21) Jakarta EE: Contexts and Dependency Injection (CDI) (233.14808.21) Jakarta EE: Expression Language (EL) (233.14808.21) Jakarta EE: Messaging (JMS) (233.14808.21) Jakarta EE: Persistence (JPA) (233.14808.21) Jakarta EE: RESTful Web Services (JAX-RS) (233.14808.21) Jakarta EE: Web/Servlets (233.14808.21) JVM Microservices Frameworks (233.14808.21) Lombok (233.14808.21) Micronaut (233.14808.21) Persistence Frameworks (233.14808.21) Reactive Streams (233.14808.21) Spring (233.14808.21) Spring Boot (233.14808.21) Spring Cloud (233.14808.21) Spring Data (233.14808.21) Spring Initializr (233.14808.21) Spring Integration Patterns (233.14808.21) Spring Messaging (233.14808.21) Spring Security (233.14808.21) Spring Web (233.14808.21) NetBeans Keymap (233.14808.21) Visual Studio Keymap (233.14808.21) Gherkin (233.14808.21) Groovy (233.14808.21) Kotlin (233.14808.21-IJ) Markdown (233.14808.21) Properties (233.14808.21) Shell Script (233.14808.21) Toml (233.14808.21) YAML (233.14808.21) Endpoints (233.14808.21) HTTP Client (233.14808.21) OpenAPI Specifications (233.14808.21) CSS (233.14808.21) Less (233.14808.21) PostCSS (233.14808.21) Sass (233.14808.21) Tailwind CSS (233.14808.21) UI Designer (233.14808.21) Apache Velocity (233.14808.21) FreeMarker (233.14808.21) Jakarta EE: Server Pages (JSP) (233.14808.21) Cucumber for Java (233.14808.21) JUnit (233.14808.21) TestNG (233.14808.21) Git (233.14808.21) GitHub (233.14808.21) GitLab (233.14808.21) Mercurial (233.14808.21) Perforce Helix Core (233.14808.21) Subversion (233.14808.21) Bytecode Viewer (233.14808.21) Copyright (233.14808.21) Dependency Structure Matrix (233.14808.21) Diagrams (233.14808.21) EditorConfig (233.14808.21) Grazie Lite (233.14808.21) In-Editor Performance Hints (233.14808.21) IntelliLang (233.14808.21) Java Bytecode Decompiler (233.14808.21) Java Internationalization (233.14808.21) Java Stream Debugger (233.14808.21) Local Productivity Statistics (233.14808.21) Performance Testing (233.14808.21) Shared Project Indexes (233.14808.21) Task Management (233.14808.21) Terminal (233.14808.21) TextMate Bundles (233.14808.21) Time Tracking (233.14808.21) WebP Support (233.14808.21)

thunderhook commented 6 months ago

@ovaso Could you try the method in https://github.com/mapstruct/mapstruct-idea/issues/191#issuecomment-2068013398 to see if it is a problem with the MapStruct plugin or IntelliJ itself?

Thanks in advance!

thunderhook commented 5 months ago

Closing it for now. We can reopen it when he have a reproducer.