diff --git a/base/src/com/google/idea/blaze/base/qsync/CandidatePackageFinder.java b/base/src/com/google/idea/blaze/base/qsync/CandidatePackageFinder.java index 331e149189f..f5e9deea3c7 100644 --- a/base/src/com/google/idea/blaze/base/qsync/CandidatePackageFinder.java +++ b/base/src/com/google/idea/blaze/base/qsync/CandidatePackageFinder.java @@ -90,6 +90,8 @@ public ImmutableList getCandidatePackages( // - at least two paths with any packages in // this is to offer the user some choice, and ensure we don't add paths with no packages in // (which would cause the query to fail later on). + // However, sometimes there might be a case where there's only one valid package. + // in such a case, we return it, but we don't add it unconditionally. do { cancellationCheck.run(); packages = runQuery(forPath); @@ -97,7 +99,7 @@ public ImmutableList getCandidatePackages( candidates.add(new CandidatePackage(forPath, packages.size())); } forPath = forPath.getParent(); - } while (candidates.size() < 2 && packages.size() < 2); + } while (candidates.size() < 2 && packages.size() < 2 && forPath != null); return ImmutableList.copyOf(candidates); } diff --git a/base/src/com/google/idea/blaze/base/qsync/action/AddToProjectAction.java b/base/src/com/google/idea/blaze/base/qsync/action/AddToProjectAction.java index 32838f67850..ed9ead6f2b0 100644 --- a/base/src/com/google/idea/blaze/base/qsync/action/AddToProjectAction.java +++ b/base/src/com/google/idea/blaze/base/qsync/action/AddToProjectAction.java @@ -221,16 +221,12 @@ protected ImmutableList compute( } }); - if (candidatePackages.size() == 1) { - doAddToProjectView(Iterables.getOnlyElement(candidatePackages)); - } else { ListPopup popup = - JBPopupFactory.getInstance() - .createListPopup( - SelectPackagePopupStep.create( - candidatePackages, Performer.this::doAddToProjectView)); + JBPopupFactory.getInstance() + .createListPopup( + SelectPackagePopupStep.create( + candidatePackages, Performer.this::doAddToProjectView)); popupPositioner.showInCorrectPosition(popup); - } } catch (BuildException e) { notify( NotificationType.ERROR,