Skip to content

Commit

Permalink
- Allow to suppress automatic Bazel project opening if .ijwb or so … (
Browse files Browse the repository at this point in the history
#5208)

* - 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
  • Loading branch information
dkashyn-sfdc authored Aug 11, 2023
1 parent 95ca4cf commit a59b768
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
3 changes: 3 additions & 0 deletions base/src/META-INF/blaze-base.xml
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,9 @@
<registryKey defaultValue="false"
description="Scan for non-root source folders in source jars. (requires re-sync)"
key="bazel.sync.detect.source.roots"/>
<registryKey defaultValue="true"
description="By default Bazel plugin takes control and opens project if .ijwb folder is present. This property can be used to disable this behavior to allow to open .idea or other project models if they are exists."
key="bazel.project.auto.open.if.present"/>
</extensions>

<extensions defaultExtensionNs="com.intellij">
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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
Expand Down

0 comments on commit a59b768

Please sign in to comment.