Skip to content
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

Avoid running document lifecycle in a workspace runnable unless it is necessary #2641

Merged
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 @@ -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