Skip to content

Commit

Permalink
Avoid running document lifecycle in a workspace runnable unless it is…
Browse files Browse the repository at this point in the history
… necessary (eclipse-jdtls#2641)
  • Loading branch information
testforstephen authored May 9, 2023
1 parent 2b32352 commit daa965d
Showing 1 changed file with 19 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -302,44 +302,32 @@ public IProblemRequestor getProblemRequestor(ICompilationUnit workingCopy) {

public void didClose(DidCloseTextDocumentParams params) {
documentVersions.remove(params.getTextDocument().getUri());
try {
ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
handleClosed(params);
}
}, null, IWorkspace.AVOID_UPDATE, new NullProgressMonitor());
} catch (CoreException e) {
JavaLanguageServerPlugin.logException("Handle document close ", e);
}
handleClosed(params);
}

public void didOpen(DidOpenTextDocumentParams params) {
documentVersions.put(params.getTextDocument().getUri(), params.getTextDocument().getVersion());
try {
ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
handleOpen(params);
}
}, null, IWorkspace.AVOID_UPDATE, new NullProgressMonitor());
} catch (CoreException e) {
JavaLanguageServerPlugin.logException("Handle document open ", e);
String uri = params.getTextDocument().getUri();
documentVersions.put(uri, params.getTextDocument().getVersion());
IFile resource = JDTUtils.findFile(uri);
if (resource != null) { // Open a managed file from the existing projects.
handleOpen(params);
} else { // Open an unmanaged file, use a workspace runnable to mount it to default project or invisible project.
try {
ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
handleOpen(params);
}
}, null, IWorkspace.AVOID_UPDATE, new NullProgressMonitor());
} catch (CoreException e) {
JavaLanguageServerPlugin.logException("Handle document open ", e);
}
}
}

public void didChange(DidChangeTextDocumentParams params) {
documentVersions.put(params.getTextDocument().getUri(), params.getTextDocument().getVersion());
try {
ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
handleChanged(params);
}
}, null, IWorkspace.AVOID_UPDATE, new NullProgressMonitor());
} catch (CoreException e) {
JavaLanguageServerPlugin.logException("Handle document change ", e);
}
handleChanged(params);
}

public void didSave(DidSaveTextDocumentParams params) {
Expand All @@ -349,15 +337,14 @@ public void didSave(DidSaveTextDocumentParams params) {
handleSaved(params);
} else {
// some refactorings may be applied by the way, wrap those in a WorkspaceRunnable
ISchedulingRule rule = JDTUtils.getRule(params.getTextDocument().getUri());
try {
JobHelpers.waitForJobs(DocumentLifeCycleHandler.DOCUMENT_LIFE_CYCLE_JOBS, new NullProgressMonitor());
ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
handleSaved(params);
}
}, rule, IWorkspace.AVOID_UPDATE, new NullProgressMonitor());
}, null, IWorkspace.AVOID_UPDATE, new NullProgressMonitor());
} catch (CoreException e) {
JavaLanguageServerPlugin.logException("Handle document save ", e);
}
Expand Down

0 comments on commit daa965d

Please sign in to comment.