From a4740605d1017a8439b00933cddb449e9c7131e8 Mon Sep 17 00:00:00 2001 From: Jason Trinh Date: Mon, 25 Nov 2024 13:43:11 +0100 Subject: [PATCH] fix issues with aspect templates not available in query sync mode (#7048) * fix issues with aspect templates not available in query sync mode * revise based on review --- .../strategy/SyncAspectTemplateProvider.java | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/base/src/com/google/idea/blaze/base/sync/aspects/strategy/SyncAspectTemplateProvider.java b/base/src/com/google/idea/blaze/base/sync/aspects/strategy/SyncAspectTemplateProvider.java index c407a6a3061..b2900fe9738 100644 --- a/base/src/com/google/idea/blaze/base/sync/aspects/strategy/SyncAspectTemplateProvider.java +++ b/base/src/com/google/idea/blaze/base/sync/aspects/strategy/SyncAspectTemplateProvider.java @@ -56,6 +56,15 @@ public void onSyncStart(Project project, BlazeContext context, SyncMode syncMode prepareProjectAspect(project); } + @Override + public void onQuerySyncStart(Project project, BlazeContext context) { + try { + prepareProjectAspect(project); + } catch (SyncFailedException e) { + throw new RuntimeException(e); + } + } + private void prepareProjectAspect(Project project) throws SyncFailedException { var manager = BlazeProjectDataManager.getInstance(project); @@ -112,7 +121,7 @@ private void writeLanguageInfos( Path realizedAspectsPath, File templateAspects, Project project) throws SyncFailedException { - var templateLanguageStringMap = getLanguageStringMap(manager, project); + var templateLanguageStringMap = getLanguageStringMap(manager); writeLanguageInfo(manager, realizedAspectsPath, templateAspects, TEMPLATE_JAVA, REALIZED_JAVA, templateLanguageStringMap); writeLanguageInfo(manager, realizedAspectsPath, templateAspects, TEMPLATE_PYTHON, REALIZED_PYTHON, templateLanguageStringMap); } @@ -131,16 +140,16 @@ private void writeLanguageInfo( } } - private static @NotNull Map getLanguageStringMap(BlazeProjectDataManager manager, Project project) { - var projectData = Optional.ofNullable(manager.getBlazeProjectData()); // It can be empty on intial sync. Fall back to no lauguage support - var blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData(); + private static @NotNull Map getLanguageStringMap(BlazeProjectDataManager manager) { + var projectData = Optional.ofNullable(manager.getBlazeProjectData()); // It can be empty on intial sync. Fall back to no language support var activeLanguages = projectData.map(it -> it.getWorkspaceLanguageSettings().getActiveLanguages()).orElse(ImmutableSet.of()); - var isJavaEnabled = activeLanguages.contains(LanguageClass.JAVA) - && blazeProjectData != null - && blazeProjectData.getExternalWorkspaceData().getByRepoName("rules_java") != null; - var isPythonEnabled = activeLanguages.contains(LanguageClass.PYTHON) - && blazeProjectData != null - && blazeProjectData.getExternalWorkspaceData().getByRepoName("rules_python") != null; + // TODO: adapt the logic to query sync + boolean isQuerySync = projectData.map(BlazeProjectData::isQuerySync).orElse(false); + var externalWorkspaceData = isQuerySync ? null : projectData.map(BlazeProjectData::getExternalWorkspaceData).orElse(null); + var isJavaEnabled = activeLanguages.contains(LanguageClass.JAVA) && + (isQuerySync || (externalWorkspaceData != null && externalWorkspaceData.getByRepoName("rules_java") != null)); + var isPythonEnabled = activeLanguages.contains(LanguageClass.PYTHON) && + (isQuerySync || (externalWorkspaceData != null && externalWorkspaceData.getByRepoName("rules_python") != null)); var isAtLeastBazel8 = projectData.map(it -> it.getBlazeVersionData().bazelIsAtLeastVersion(8, 0, 0)).orElse(false); return Map.of( "bazel8OrAbove", isAtLeastBazel8 ? "true" : "false",