Auto import is not working in a java file when multiple root/subfolder project in one workspace
[provide a description of the issue]
Environment
- Operating System: MacOS
- JDK version: 17
- Visual Studio Code version: Version: 1.70.2
- Java extension version: v1.9.0
Steps To Reproduce
Step 1: delete a necessary import in a java under one project under multiple root workspace Step 2: the extension can not import automatically
[Please attach a sample project reproducing the error] Please attach logs
Current Result
lack of dependency import and build failed
Expected Result
auto import the dependency necessarily
Additional Informations
Can you share more details about auto import the dependency necessarily, adding the required import statement automatically?
expressive_scenarios.zip attached the workspace already and also you can navigate to /Users/leon/Technical Agile/TacLearning/sample-code-cucumber4java/expressive_scenarios/02/src/test/java/tic_tac_toe/BoardSteps.java and comment any function like Pending Exception and then save to see whether it will auto import
// comment the line to import PendingException and then save to see whether it will auto import // import io.cucumber.java.PendingException; // or comment all PendingException and then uncomment later // throw new PendingException();
Can you share more details about
auto import the dependency necessarily, adding the required import statement automatically?
@qzi I can't reproduce the issue. Could you show your settings.json?
@qzi I can't reproduce the issue. Could you show your settings.json?
"redhat.telemetry.enabled": true,
only this setting relate to redhat only in my user setting.
I think you can call a new function in a new dependency imported by maven, then you can reproduce the issue without any auto import performed in a java file if the project is under multiple root workspace
@qzi could you try to add
"java.saveActions.organizeImports": true
"editor.formatOnSave": true, "java.saveActions.organizeImports": true, "autoimport.showNotifications": true,
These ones are already added before I raised this issue and also have you tried auto imported in the head of the java file under a multiple root project in a workspace, you can try my compressed zip
@qzi could you try the following project expressive_scenarios.zip I have renamed the artifactId property in all your projects.
@qzi could you try the following project expressive_scenarios.zip I have renamed the artifactId property in all your projects.
Oh, I got your point, thanks for your support. I am more confident to use vs code to program java now.
By the way, even the artifactId is the same, but in IntelliJ idea, it still works well to import automatically, so can we adjust our condition strategy in this plugin to keep it more robust
The same issue about auto import
Nagigate to [root]/18/src/test/java/RunCukesTest.java
// import io.cucumber.junit.CucumberOptions.SnippetType;
can not auto import ...
@qzi automatic import (on file save) won't work if there are ambiguous imports. In your file, if you organize imports manually, you'll be presented with a choice to disambiguate imports:

@rgrunber @testforstephen we could improve import on file save and show the disambiguation UI if the current editor matches the file being saved. Nothing we can do with multiple ambiguous imports on multiple files and "Save All".
@qzi automatic import (on file save) won't work if there are ambiguous imports. In your file, if you organize imports manually, you'll be presented with a choice to disambiguate imports:
@fbricon I think the better approach is to show the ambiguous import in the menu of quick fix, maybe it is the bug issue of quick fix