use of org.eclipse.jdt.ls.core.internal.DidChangeWatchedFilesRegistrationOptions in project eclipse.jdt.ls by eclipse.
the class ProjectsManager method registerWatchers.
public List<FileSystemWatcher> registerWatchers() {
if (preferenceManager.getClientPreferences().isWorkspaceChangeWatchedFilesDynamicRegistered()) {
Set<String> sources = new HashSet<>();
try {
IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
for (IProject project : projects) {
if (DEFAULT_PROJECT_NAME.equals(project.getName())) {
continue;
}
IJavaProject javaProject = JavaCore.create(project);
if (javaProject != null && javaProject.exists()) {
IClasspathEntry[] classpath = javaProject.getRawClasspath();
for (IClasspathEntry entry : classpath) {
if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
IPath path = entry.getPath();
if (path != null) {
IFolder folder = ResourcesPlugin.getWorkspace().getRoot().getFolder(path);
if (folder.exists() && !folder.isDerived()) {
IPath location = folder.getLocation();
if (location != null) {
sources.add(location.toString() + "/**");
}
}
}
}
}
}
}
} catch (JavaModelException e) {
JavaLanguageServerPlugin.logException(e.getMessage(), e);
}
List<FileSystemWatcher> fileWatchers = new ArrayList<>();
for (String pattern : sources) {
FileSystemWatcher watcher = new FileSystemWatcher(pattern, FileSystemWatcher.WATCH_KIND_DEFAULT);
fileWatchers.add(watcher);
}
if (!sources.equals(watchers)) {
logInfo(">> registerFeature 'workspace/didChangeWatchedFiles'");
DidChangeWatchedFilesRegistrationOptions didChangeWatchedFilesRegistrationOptions = new DidChangeWatchedFilesRegistrationOptions(fileWatchers);
JavaLanguageServerPlugin.getInstance().unregisterCapability(Preferences.WORKSPACE_WATCHED_FILES_ID, Preferences.WORKSPACE_WATCHED_FILES);
JavaLanguageServerPlugin.getInstance().registerCapability(Preferences.WORKSPACE_WATCHED_FILES_ID, Preferences.WORKSPACE_WATCHED_FILES, didChangeWatchedFilesRegistrationOptions);
watchers.clear();
watchers.addAll(sources);
}
return fileWatchers;
}
return null;
}
Aggregations