Skip to content

Avoid re-using same job #2356

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

Merged
merged 1 commit into from
Nov 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -119,20 +119,7 @@ public boolean belongsTo(Object family) {
return DOCUMENT_LIFE_CYCLE_JOBS.equals(family);
}
};
this.publishDiagnosticsJob = new WorkspaceJob("Publish Diagnostics") {
@Override
public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
return publishDiagnostics(monitor);
}

/* (non-Javadoc)
* @see org.eclipse.core.runtime.jobs.Job#belongsTo(java.lang.Object)
*/
@Override
public boolean belongsTo(Object family) {
return PUBLISH_DIAGNOSTICS_JOBS.equals(family);
}
};
this.publishDiagnosticsJob = new PublishDiagnosticJob(ResourcesPlugin.getWorkspace().getRoot());
}
}

Expand All @@ -159,7 +146,7 @@ protected void triggerValidation(ICompilationUnit cu, long delay) throws JavaMod
ISchedulingRule rule = getRule(toReconcile);
if (publishDiagnosticsJob != null) {
publishDiagnosticsJob.cancel();
publishDiagnosticsJob.setRule(rule);
publishDiagnosticsJob = new PublishDiagnosticJob(rule);
}
validationTimer.setRule(rule);
validationTimer.schedule(delay);
Expand Down Expand Up @@ -573,7 +560,7 @@ private void inferInvisibleProjectSourceRoot(ICompilationUnit unit) {
if (javaProject == null) {
return;
}

IProject project = javaProject.getProject();
if (ProjectUtils.isUnmanagedFolder(project)) {
PreferenceManager preferencesManager = JavaLanguageServerPlugin.getPreferencesManager();
Expand Down Expand Up @@ -651,6 +638,33 @@ private boolean needInferSourceRoot(IJavaProject javaProject, ICompilationUnit u
return false;
}

/**
* @author mistria
*
*/
private final class PublishDiagnosticJob extends WorkspaceJob {
/**
* @param rule
*/
private PublishDiagnosticJob(ISchedulingRule rule) {
super("Publish Diagnostics");
setRule(rule);
}

@Override
public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
return publishDiagnostics(monitor);
}

/* (non-Javadoc)
* @see org.eclipse.core.runtime.jobs.Job#belongsTo(java.lang.Object)
*/
@Override
public boolean belongsTo(Object family) {
return PUBLISH_DIAGNOSTICS_JOBS.equals(family);
}
}

/**
* Can be passed to requests that are sensitive to document changes
* in order to monitor the version and cancel the request if necessary.
Expand Down