From aa9895d35018606b295b04f758bb25bef979922c Mon Sep 17 00:00:00 2001 From: Ittai Zeidman Date: Thu, 14 Nov 2019 11:28:14 +0200 Subject: [PATCH] only filters labels according to parent packages for LanguageClass.C (#47) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * only filters labels according to parent packages for LanguageClass.C This is to keep supporting CPP need while also supporting aggregate targets More info: https://bazelbuild.slack.com/archives/CM8JQCANN/p1566481600003600 Filter was deliberately added to fix an issue with C++ headers. The original bug was that opening the BUILD file for foo/bar.h caused it to open baz/qux/BUILD because there’s a cc_library target in baz/qux that includes foo/bar.h in its headers. The source-to-target look up queries the index for the target during the last sync which compiled the source file. In this case, it was the cc_library target in baz/qux. So the fix was to ensure that the BUILD file is always for the parent package (foo/bar) --- .../blaze/base/actions/BuildFileUtils.java | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/base/src/com/google/idea/blaze/base/actions/BuildFileUtils.java b/base/src/com/google/idea/blaze/base/actions/BuildFileUtils.java index c9d8d9c27b2..9cf043e6e21 100644 --- a/base/src/com/google/idea/blaze/base/actions/BuildFileUtils.java +++ b/base/src/com/google/idea/blaze/base/actions/BuildFileUtils.java @@ -25,11 +25,13 @@ import com.google.idea.blaze.base.lang.buildfile.search.BlazePackage; import com.google.idea.blaze.base.model.BlazeProjectData; import com.google.idea.blaze.base.model.primitives.Label; +import com.google.idea.blaze.base.model.primitives.LanguageClass; import com.google.idea.blaze.base.model.primitives.WorkspacePath; import com.google.idea.blaze.base.sync.data.BlazeProjectDataManager; import com.google.idea.blaze.base.targetmaps.SourceToTargetMap; import com.google.idea.common.experiments.BoolExperiment; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.io.FileUtilRt; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFileSystemItem; @@ -37,6 +39,7 @@ import java.io.File; import java.util.Arrays; import java.util.Set; +import java.util.stream.Stream; import javax.annotation.Nullable; /** BUILD-file utility methods used by actions. */ @@ -74,9 +77,11 @@ static PsiElement findBuildTarget(Project project, BlazePackage parentPackage, F if (packagePath == null) { return null; } + final Stream