Skip to content

Commit

Permalink
New folders do not register in the jdt.ls workspace #10115 (#11084)
Browse files Browse the repository at this point in the history
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 <vrubezhny@redhat.com>
  • Loading branch information
vrubezhny authored and tsmaeder committed Oct 17, 2018
1 parent 50c94e9 commit e4434b4
Showing 1 changed file with 23 additions and 4 deletions.
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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<Integer> 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
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit e4434b4

Please sign in to comment.