From e3167ae98c66b46d964f881b719cc08373d2744f Mon Sep 17 00:00:00 2001 From: "Victor V. Rubezhny" Date: Wed, 26 Sep 2018 12:32:43 +0200 Subject: [PATCH] New folders do not register in the jdt.ls workspace #10115 (#11084) This fix adds a filtering of java projects (folders from the projects of other types will not be reported to jdt.ls) Signed-off-by: Victor Rubezhny --- .../PlainJavaProjectSourceFolderWatcher.java | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/plugins/plugin-java/che-plugin-java-plain/che-plugin-java-plain-server/src/main/java/org/eclipse/che/plugin/java/plain/server/inject/PlainJavaProjectSourceFolderWatcher.java b/plugins/plugin-java/che-plugin-java-plain/che-plugin-java-plain-server/src/main/java/org/eclipse/che/plugin/java/plain/server/inject/PlainJavaProjectSourceFolderWatcher.java index 6994e46b309..0c0f8bf38ab 100644 --- a/plugins/plugin-java/che-plugin-java-plain/che-plugin-java-plain-server/src/main/java/org/eclipse/che/plugin/java/plain/server/inject/PlainJavaProjectSourceFolderWatcher.java +++ b/plugins/plugin-java/che-plugin-java-plain/che-plugin-java-plain-server/src/main/java/org/eclipse/che/plugin/java/plain/server/inject/PlainJavaProjectSourceFolderWatcher.java @@ -15,12 +15,15 @@ import static java.util.Collections.singletonList; import static org.eclipse.che.api.languageserver.LanguageServiceUtils.prefixURI; import static org.eclipse.che.api.languageserver.LanguageServiceUtils.removeUriScheme; +import static org.eclipse.che.ide.ext.java.shared.Constants.JAVAC; import static org.eclipse.che.jdt.ls.extension.api.Commands.GET_PROJECT_SOURCE_LOCATIONS_COMMAND; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; import java.lang.reflect.Type; +import java.nio.file.LinkOption; +import java.nio.file.Path; import java.nio.file.PathMatcher; import java.nio.file.Paths; import java.util.ArrayList; @@ -31,9 +34,12 @@ import javax.annotation.PreDestroy; import javax.inject.Inject; import org.eclipse.che.api.core.notification.EventService; +import org.eclipse.che.api.fs.server.PathTransformer; import org.eclipse.che.api.languageserver.ExtendedLanguageServer; import org.eclipse.che.api.languageserver.FindServer; +import org.eclipse.che.api.project.server.ProjectManager; import org.eclipse.che.api.project.server.notification.ProjectUpdatedEvent; +import org.eclipse.che.api.project.shared.RegisteredProject; import org.eclipse.che.api.watcher.server.FileWatcherManager; import org.eclipse.che.api.watcher.server.impl.FileWatcherByPathMatcher; import org.eclipse.che.plugin.java.inject.JavaModule; @@ -55,21 +61,26 @@ public class PlainJavaProjectSourceFolderWatcher { private final FileWatcherManager manager; private final FileWatcherByPathMatcher matcher; private final FindServer lsRegistry; - + private final ProjectManager projectManager; private final EventService eventService; - private final CopyOnWriteArrayList watcherIds = new CopyOnWriteArrayList<>(); + private PathTransformer pathTransformer; + @Inject public PlainJavaProjectSourceFolderWatcher( FileWatcherManager manager, FileWatcherByPathMatcher matcher, FindServer lsRegistry, - EventService eventService) { + ProjectManager projectManager, + EventService eventService, + PathTransformer pathTransformer) { this.manager = manager; this.matcher = matcher; this.lsRegistry = lsRegistry; + this.projectManager = projectManager; this.eventService = eventService; + this.pathTransformer = pathTransformer; } @PostConstruct @@ -116,7 +127,15 @@ private void onProjectUpdated(ProjectUpdatedEvent event) { } private PathMatcher folderMatcher() { - return it -> isDirectory(it); + return it -> isDirectoryOfJavaProject(it); + } + + private boolean isDirectoryOfJavaProject(Path path, LinkOption... options) { + if (!isDirectory(path, options)) { + return false; + } + RegisteredProject project = projectManager.getClosestOrNull(pathTransformer.transform(path)); + return project != null && project.getType().equals(JAVAC); } private void report(String path, FileChangeType changeType) {