diff --git a/base/src/META-INF/blaze-base.xml b/base/src/META-INF/blaze-base.xml
index 04da8ba721c..c7773d54833 100644
--- a/base/src/META-INF/blaze-base.xml
+++ b/base/src/META-INF/blaze-base.xml
@@ -345,6 +345,9 @@
+
diff --git a/base/src/com/google/idea/blaze/base/project/AutoImportProjectOpenProcessor.java b/base/src/com/google/idea/blaze/base/project/AutoImportProjectOpenProcessor.java
index 212d0958f08..d7fc32ae2fa 100644
--- a/base/src/com/google/idea/blaze/base/project/AutoImportProjectOpenProcessor.java
+++ b/base/src/com/google/idea/blaze/base/project/AutoImportProjectOpenProcessor.java
@@ -1,16 +1,12 @@
package com.google.idea.blaze.base.project;
-import com.google.idea.blaze.base.model.primitives.WorkspacePath;
+import static com.google.idea.blaze.base.project.BlazeProjectOpenProcessor.getIdeaSubdirectory;
+
import com.google.idea.blaze.base.model.primitives.WorkspaceRoot;
import com.google.idea.blaze.base.projectview.ProjectView;
import com.google.idea.blaze.base.projectview.ProjectView.Builder;
import com.google.idea.blaze.base.projectview.ProjectViewSet;
import com.google.idea.blaze.base.projectview.parser.ProjectViewParser;
-import com.google.idea.blaze.base.projectview.section.ListSection;
-import com.google.idea.blaze.base.projectview.section.ScalarSection;
-import com.google.idea.blaze.base.projectview.section.sections.AutomaticallyDeriveTargetsSection;
-import com.google.idea.blaze.base.projectview.section.sections.DirectoryEntry;
-import com.google.idea.blaze.base.projectview.section.sections.DirectorySection;
import com.google.idea.blaze.base.projectview.section.sections.TextBlock;
import com.google.idea.blaze.base.projectview.section.sections.TextBlockSection;
import com.google.idea.blaze.base.settings.Blaze;
@@ -24,7 +20,6 @@
import com.google.idea.blaze.base.wizard2.WorkspaceTypeData;
import com.google.idea.sdkcompat.general.BaseSdkCompat;
import com.intellij.ide.SaveAndSyncHandler;
-import com.intellij.ide.impl.OpenProjectTask;
import com.intellij.ide.impl.ProjectUtil;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
@@ -89,8 +84,10 @@ public boolean lookForProjectsInDirectory() {
@Override
public boolean canOpenProject(@NotNull VirtualFile virtualFile) {
+ // Auto import activated only if it is not disabled, there is no existing project model in the folder
+ // and Bazel workspace is detected.
return !Registry.is("bazel.auto.import.disabled")
- && isBazelWorkspace(virtualFile);
+ && getIdeaSubdirectory(virtualFile) == null && isBazelWorkspace(virtualFile);
}
private boolean isBazelWorkspace(VirtualFile virtualFile) {
diff --git a/base/src/com/google/idea/blaze/base/project/BlazeProjectOpenProcessor.java b/base/src/com/google/idea/blaze/base/project/BlazeProjectOpenProcessor.java
index 2fc16fe9097..fa669760757 100644
--- a/base/src/com/google/idea/blaze/base/project/BlazeProjectOpenProcessor.java
+++ b/base/src/com/google/idea/blaze/base/project/BlazeProjectOpenProcessor.java
@@ -19,6 +19,7 @@
import com.google.idea.blaze.base.sync.data.BlazeDataStorage;
import com.google.idea.sdkcompat.general.BaseSdkCompat;
import com.intellij.openapi.project.Project;
+import com.intellij.openapi.util.registry.Registry;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.projectImport.ProjectOpenProcessor;
import icons.BlazeIcons;
@@ -42,7 +43,7 @@ public Icon getIcon() {
private static final String DEPRECATED_PROJECT_DATA_SUBDIRECTORY = ".project";
@Nullable
- private static VirtualFile getIdeaSubdirectory(VirtualFile file) {
+ public static VirtualFile getIdeaSubdirectory(VirtualFile file) {
VirtualFile projectSubdirectory = file.findChild(BlazeDataStorage.PROJECT_DATA_SUBDIRECTORY);
if (projectSubdirectory == null || !projectSubdirectory.isDirectory()) {
projectSubdirectory = file.findChild(DEPRECATED_PROJECT_DATA_SUBDIRECTORY);
@@ -68,7 +69,7 @@ public boolean canOpenProject(VirtualFile file) {
@Override
public boolean isStrongProjectInfoHolder() {
- return true;
+ return Registry.is("bazel.project.auto.open.if.present", true);
}
@Override