2

I'm facing some issues with autocompletion feature for yml files containing spring configuration. I found very similar question on stackoverflow but my reputation is too low to write a comment there. The solution doesn't work for me.

I enabled annotation processor enter image description here I'm using the newest Ultimate version of IntelliJ.

I added the following dependency to my pom.xml file:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-configuration-processor</artifactId>
    <optional>true</optional>
</dependency>

I have two classes:

public class BooProperties {
    private int workerCount;
    // getters and setters
}

and:

@ConfigurationProperties("server.worker")
public class FooProperties {
    private int workerCount;
    private int subWorkerCount;
    private int limit;
    @NestedConfigurationProperty
    private Map<String, BooProperties> group = new HashMap<>();
    // getters and setters
}

My whole project can be found here in github.

Autocompletion works generally: enter image description here

But it doesn't work for map keys (I also would like to work for values, but this is much too far right now) enter image description here Despite I added file additional-spring-configuration-metadata.json:

{
  "properties":[{
    "name": "server.worker.group",
    "type":"java.util.Map<java.lang.String, com.BooProperties>",
    "description": ".....",
    "sourceType":"com.FooProperties"
  }],
  "hints":[{
    "name":"server.worker.group.keys",
    "values": [
      {
        "value": "1"
      },
      {
        "value": "2"
      }
    ]
  }]
}

I'm stuck. I cannot find any material about that on the Internet.

Best regards

bogóś
  • 51
  • 7
  • this is because it would need value completion, which by my knowledge it does not have. with the map, the key as well as the value are variable and not pre defined, so IntelliJ does not know what to put there – Amir Schnell Dec 07 '20 at 15:56
  • Yes, you are correct. However I provided a `hint` in `additional-spring-configuration-metadata.json` file - but it is ignored – bogóś Dec 07 '20 at 16:06
  • Moreover, I expect that IntelliJ autocompletes properties name for fields in `BooProperties` class – bogóś Dec 07 '20 at 16:21
  • I think the hints autocompletion would only work for the value part of the config, not for the key. So if you are putting hints for `server.worker.group.keys` then I assume IntelliJ would give you these as autocompletion when you type `server.worker.group.keys: ` – Amir Schnell Dec 08 '20 at 08:37
  • The sam thing actually happens in the class `JpaProperties`. It has a `Map` calles `properties`, and there is no autocompletion for that either. – Amir Schnell Dec 08 '20 at 08:38
  • Based on the Java class "Map", the annotation processor should recognize that keys can be custom. Below, it should continue with strictness, as yourclass can have well-defined property names in a POJO. Unfortunately it's not implemented like that. Autocompletion would not be expected for key type String, it only works well when your key is an enumeration. – Mick Belker - Pseudonym Dec 21 '21 at 15:27

0 Answers0