From 7385e8954527fa37a7233faaf5aade5f37117e36 Mon Sep 17 00:00:00 2001 From: Gunnar Wagenknecht Date: Wed, 7 Aug 2024 10:43:28 +0200 Subject: [PATCH] Use unqualified label where possible --- .../core/edits/AddDependenciesJob.java | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/edits/AddDependenciesJob.java b/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/edits/AddDependenciesJob.java index 598adc1d..633ca728 100644 --- a/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/edits/AddDependenciesJob.java +++ b/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/edits/AddDependenciesJob.java @@ -32,8 +32,31 @@ public class AddDependenciesJob extends WorkspaceJob { + protected static String toUnqualifiedLabelIfPossible(Label l) { + var targetName = l.targetName().toString(); + + var externalWorkspaceName = l.externalWorkspaceName(); + if (l.blazePackage().isWorkspaceRoot() && targetName.equals(externalWorkspaceName)) { + // just the external workspace + return "@" + externalWorkspaceName; + } + + if (!l.blazePackage().isWorkspaceRoot()) { + var lastFolderInPackagePath = l.blazePackage().asPath().getFileName(); + if ((lastFolderInPackagePath != null) && lastFolderInPackagePath.toString().equals(targetName)) { + // shorten to just the package path + var label = "//" + l.blazePackage(); + return externalWorkspaceName != null ? "@" + externalWorkspaceName + label : label; + } + } + + // use full qualified label + return l.toString(); + } + protected final BazelProject bazelProject; protected final Collection