Skip to content

Organize Imports should automatically add required modules in module-info #1388

Open
eclipse-jdtls/eclipse.jdt.ls
#3964

Description

@anthonyvdotbe

When I do Organize Imports, I'd like for the module-info.java file to be updated automatically as well.

Environment
  • Operating System: Windows 10
  • JDK version: 14
  • Visual Studio Code version: 1.44.0
  • Java extension version: 0.59.1
Steps To Reproduce
  1. create a file App.java as below inside a modular project
  2. do Organize Imports
class App {
    void run() {
        HttpClient client;
    }
}
Current Result

After importing java.net.http.HttpClient, the module-info.java file is unchanged.

Expected Result

The module-info.java file is automatically updated with:

requires java.net.http;

Activity

  1. self-assigned this
    on Apr 13, 2020
  2. robstryker commented on Oct 29, 2026

    @robstryker
    Contributor

    I've given this a quick test. Organize imports properly adds the import.

    However, eclipse will have a ctrl+1 suggestion to add the module to module-info.java, and vscode-java does not do this.

    @shin19991207 When you're not busy, do you think you can look into why this particular suggestion doesn't exist? :D

  3. moved this to Pending review in Java Toolingon Nov 3, 2026
  4. added this to the End of November 2026 milestone on Nov 4, 2026
  5. datho7561 commented on Nov 4, 2026

    @datho7561
    Contributor

    I think it'd be nice to also handle adding the requires entry when using the "Organize Imports" command instead of having to do activate the quick fix separately; I think that'll need to be handled upstream in jdt.core though, since currently the upstream "Organize Imports" also doesn't add the requires entry to the module-info.java

  6. moved this from Pending review to Done in Java Toolingon Nov 4, 2026
  7. datho7561 commented on Nov 4, 2026

    @datho7561
    Contributor

    @shin19991207 if you have time, do mind investigating what I mentioned as well? It might require changes in jdt.core.manipulation (under jdt.ui)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions