From a59b7682568cd8bc306ba8e7e3c73153778c6a98 Mon Sep 17 00:00:00 2001
From: Dmytro Kashyn <50216138+dkashyn-sfdc@users.noreply.github.com>
Date: Fri, 11 Aug 2023 07:08:45 -0400
Subject: [PATCH] =?UTF-8?q?-=20Allow=20to=20suppress=20automatic=20Bazel?=
=?UTF-8?q?=20project=20opening=20if=20`.ijwb`=20or=20so=20=E2=80=A6=20(#5?=
=?UTF-8?q?208)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* - Allow to suppress automatic Bazel project opening if `.ijwb` or so already exists by setting `bazel.project.auto.open.if.present` to `false`
- Avoid activation of Bazel project auto import if `.ijwb` or other model that corresponds to current Bazel project mode is present.
* Registry key declaration
---
base/src/META-INF/blaze-base.xml | 3 +++
.../project/AutoImportProjectOpenProcessor.java | 13 +++++--------
.../base/project/BlazeProjectOpenProcessor.java | 5 +++--
3 files changed, 11 insertions(+), 10 deletions(-)
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