Skip to content

Filter files matching files.exclude from project #216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
1 change: 1 addition & 0 deletions jdtls.ext/com.microsoft.jdtls.ext.core/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<extension point="org.eclipse.jdt.ls.core.delegateCommandHandler">
<delegateCommandHandler class="com.microsoft.jdtls.ext.core.CommandHandler">
<command id="java.project.list"/>
<command id="java.project.updateFilters"/>
<command id="java.getPackageData"/>
<command id="java.resolvePath" />
</delegateCommandHandler>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public Object executeCommand(String commandId, List<Object> arguments, IProgress
switch (commandId) {
case "java.project.list":
return ProjectCommand.execute(arguments, monitor);
case "java.project.updateFilters":
return ProjectCommand.updateFilters(arguments, monitor);
case "java.getPackageData":
return PackageCommand.getChildren(arguments, monitor);
case "java.resolvePath":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,17 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

import org.eclipse.core.resources.FileInfoMatcherDescription;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceFilterDescription;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
Expand Down Expand Up @@ -47,6 +54,44 @@ public static List<PackageNode> execute(List<Object> arguments, IProgressMonitor
return children;
}

@SuppressWarnings("unchecked")
public static boolean updateFilters(List<Object> arguments, IProgressMonitor monitor) throws Exception {
final Set<String> patterns = new HashSet<>((List<String>) arguments.get(0));
final IProject[] projects = getWorkspaceRoot().getProjects();
final Set<IProject> filterUpdated = new HashSet<>();
for (final IProject project : projects) {
if (!project.exists()) {
continue;
}
final Map<String, IResourceFilterDescription> filters = Arrays.stream(project.getFilters()).collect(Collectors.toMap(
filter -> (String) filter.getFileInfoMatcherDescription().getArguments(), filter -> filter
));
for (final String pattern: patterns) { // Handle newly added filters
if (filters.containsKey(pattern)) {
continue;
}
project.createFilter(
IResourceFilterDescription.EXCLUDE_ALL |
IResourceFilterDescription.FILES |
IResourceFilterDescription.FOLDERS |
IResourceFilterDescription.INHERITABLE,
new FileInfoMatcherDescription("org.eclipse.core.resources.regexFilterMatcher", pattern), 0, monitor);
filterUpdated.add(project);
}
for (final String pattern: filters.keySet()) { // Handle deleted filters
if (patterns.contains(pattern)) {
continue;
}
filters.get(pattern).delete(0, monitor);
filterUpdated.add(project);
}
if (filterUpdated.contains(project)) { // Refresh the hierachy if filter is updated
project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
}
}
return filterUpdated.size() > 0;
}

private static IWorkspaceRoot getWorkspaceRoot() {
return ResourcesPlugin.getWorkspace().getRoot();
}
Expand Down
Loading