Skip to content
This repository has been archived by the owner on Jan 31, 2024. It is now read-only.

Commit

Permalink
Use belongsTo to cancel the init job
Browse files Browse the repository at this point in the history
  • Loading branch information
Poytr1 committed Jun 9, 2019
1 parent a393bb7 commit 8c73495
Showing 1 changed file with 10 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,28 +227,21 @@ InitializeResult initialize(InitializeParams param) {
}

public static void cancelInitJobFromURI(String uri) {
String rootName = ResourceUtils.canonicalFilePathFromURI(uri).toString();
Job[] jobs = Job.getJobManager().find(JAVA_LS_INITIALIZATION_JOBS);
IPath rootName = ResourceUtils.canonicalFilePathFromURI(uri);
Job[] jobs = Job.getJobManager().find(rootName);
for (Job job: jobs) {
String[] splitName = job.getName().split(":");
if (splitName.length == 2) {
String rootsName = splitName[1];
if (rootsName.contains(rootName)) {
job.cancel();
}
}
job.cancel();
}
}

private void triggerInitialization(Collection<IPath> roots) {
String rootsName = String.join(",", roots.stream().map(r -> r.toString()).collect(Collectors.toList()));
Job job = new WorkspaceJob("Initialize Workspace:" + rootsName) {
Job job = new WorkspaceJob("Initialize Workspace") {
@Override
public IStatus runInWorkspace(IProgressMonitor monitor) {
long start = System.currentTimeMillis();
SubMonitor subMonitor = SubMonitor.convert(monitor, 100);
try {
JavaLanguageServerPlugin.logInfo("Start initialize for" + rootsName);
JavaLanguageServerPlugin.logInfo("Start initialization");
projectsManager.setAutoBuilding(false);
projectsManager.initializeProjects(roots, subMonitor);
projectsManager.setAutoBuilding(preferenceManager.getPreferences().isAutobuildEnabled());
Expand All @@ -265,7 +258,11 @@ public IStatus runInWorkspace(IProgressMonitor monitor) {
*/
@Override
public boolean belongsTo(Object family) {
return JAVA_LS_INITIALIZATION_JOBS.equals(family);
boolean belongsToAnyRoot = false;
for (IPath root: roots) {
belongsToAnyRoot |= root.equals(family);
}
return JAVA_LS_INITIALIZATION_JOBS.equals(family) || belongsToAnyRoot;
}

};
Expand Down

0 comments on commit 8c73495

Please sign in to comment.