From 2fed1728d2a556385f183e9bfe351b55d43ecba4 Mon Sep 17 00:00:00 2001 From: Sheng Chen Date: Mon, 13 Nov 2023 00:18:49 -0800 Subject: [PATCH] feat: Implement onWillUpdate() in GradleBuildServerBuildSupport (#1405) Signed-off-by: Sheng Chen --- .../GradleBuildServerBuildSupport.java | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/GradleBuildServerBuildSupport.java b/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/GradleBuildServerBuildSupport.java index d9b469b4a..5f6d11166 100644 --- a/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/GradleBuildServerBuildSupport.java +++ b/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/GradleBuildServerBuildSupport.java @@ -8,7 +8,9 @@ import java.net.URISyntaxException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; +import java.util.HashSet; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.LinkedList; @@ -126,6 +128,20 @@ public boolean applies(IProject project) { return Utils.isGradleBuildServerProject(project); } + public void onWillUpdate(Collection projects, IProgressMonitor monitor) throws CoreException { + Set roots = new HashSet<>(); + for (IProject project : projects) { + IPath rootPath = ProjectUtils.findBelongedWorkspaceRoot(project.getLocation()); + if (rootPath != null) { + roots.add(rootPath); + } + } + for (IPath rootPath : roots) { + BuildServerConnection connection = ImporterPlugin.getBuildServerConnection(rootPath); + connection.workspaceReload().join(); + } + } + @Override public void update(IProject project, boolean force, IProgressMonitor monitor) throws CoreException { if (!applies(project)) { @@ -139,10 +155,8 @@ public void update(IProject project, boolean force, IProgressMonitor monitor) th JavaLanguageServerPlugin.logError("Cannot find workspace root for project: " + project.getName()); return; } - BuildServerConnection buildServer = ImporterPlugin.getBuildServerConnection(rootPath); - buildServer.workspaceReload().join(); - - Map> buildTargetMap = Utils.getBuildTargetsMappedByProjectPath(buildServer); + BuildServerConnection connection = ImporterPlugin.getBuildServerConnection(rootPath); + Map> buildTargetMap = Utils.getBuildTargetsMappedByProjectPath(connection); for (URI uri : buildTargetMap.keySet()) { IProject projectFromUri = ProjectUtils.getProjectFromUri(uri.toString()); if (projectFromUri == null || !Utils.isGradleBuildServerProject(projectFromUri)) {