Replace project sorter for initial classpath events...
Now uses FileBuffers instead of open editors. This avoid long blocking on ui thread syncExec.
This commit is contained in:
@@ -14,59 +14,33 @@ import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.core.filebuffers.FileBuffers;
|
||||
import org.eclipse.core.filebuffers.IFileBuffer;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.ui.IEditorInput;
|
||||
import org.eclipse.ui.IEditorPart;
|
||||
import org.eclipse.ui.IEditorReference;
|
||||
import org.eclipse.ui.IWorkbenchPage;
|
||||
import org.eclipse.ui.PartInitException;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.part.FileEditorInput;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.springframework.tooling.jdt.ls.commons.Logger;
|
||||
|
||||
public class ProjectSorter implements Comparator<IProject> {
|
||||
|
||||
private IProject activeProject;
|
||||
private Set<IProject> projectsWithEditors;
|
||||
|
||||
public ProjectSorter() {
|
||||
private Logger logger = Logger.forEclipsePlugin(() -> LanguageServerCommonsActivator.getInstance());
|
||||
|
||||
public ProjectSorter() {
|
||||
logger.log("Creating project sorter...");
|
||||
this.projectsWithEditors = new HashSet<IProject>();
|
||||
|
||||
PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
|
||||
IEditorInput editorInput = activeEditor.getEditorInput();
|
||||
activeProject = getProject(editorInput);
|
||||
|
||||
IWorkbenchPage[] pages = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPages();
|
||||
for (IWorkbenchPage page : pages) {
|
||||
IEditorReference[] references = page.getEditorReferences();
|
||||
for (IEditorReference editorReference : references) {
|
||||
try {
|
||||
IEditorInput additionalInput = editorReference.getEditorInput();
|
||||
IProject additionalProject = getProject(additionalInput);
|
||||
|
||||
if (additionalProject != null && additionalProject != activeProject) {
|
||||
projectsWithEditors.add(additionalProject);
|
||||
}
|
||||
} catch (PartInitException e) {
|
||||
// ignore this editor
|
||||
}
|
||||
}
|
||||
}
|
||||
IFileBuffer[] openBuffers = FileBuffers.getTextFileBufferManager().getFileBuffers();
|
||||
for (IFileBuffer ob : openBuffers) {
|
||||
IPath path = ob.getLocation();
|
||||
System.out.println(path);
|
||||
if (path.segmentCount() >= 1) {
|
||||
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(path.segment(0));
|
||||
projectsWithEditors.add(project);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private IProject getProject(IEditorInput editorInput) {
|
||||
if (editorInput != null && editorInput instanceof FileEditorInput) {
|
||||
FileEditorInput fileInput = (FileEditorInput) editorInput;
|
||||
return fileInput.getFile() != null ? fileInput.getFile().getProject() : null;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
logger.log("Creating project sorter... DONE");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -76,11 +50,7 @@ public class ProjectSorter implements Comparator<IProject> {
|
||||
|
||||
private int score(IProject project) {
|
||||
if (project == null) return 0;
|
||||
|
||||
if (project == activeProject) return 10;
|
||||
if (projectsWithEditors.contains(project)) return 5;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -99,9 +99,12 @@ public class ReusableClasspathListenerHandler {
|
||||
|
||||
public void subscribe(String callbackCommandId, boolean isBatched) {
|
||||
// keep out of synchronized block to avoid workspace locks
|
||||
logger.log("Sorting projects...");
|
||||
IProject[] sortedProjects = getSortedProjects();
|
||||
logger.log("Sorting projects... DONE");
|
||||
|
||||
synchronized(this) {
|
||||
logger.log("inside synchronized Subscriptions");
|
||||
if (!subscribers.containsKey(callbackCommandId)) {
|
||||
logger.log("subscribing to classpath changes: " + callbackCommandId +" isBatched = "+isBatched);
|
||||
classpathListener = new ClasspathListenerManager(logger, new ClasspathListener() {
|
||||
|
||||
@@ -42,7 +42,9 @@ import org.springframework.ide.vscode.commons.util.FileObserver;
|
||||
import org.springframework.ide.vscode.commons.util.UriUtil;
|
||||
|
||||
import reactor.core.Disposable;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.util.context.Context;
|
||||
|
||||
public class JdtLsProjectCache implements InitializableJavaProjectsService {
|
||||
|
||||
@@ -269,14 +271,10 @@ public class JdtLsProjectCache implements InitializableJavaProjectsService {
|
||||
}
|
||||
})
|
||||
.timeout(INITIALIZE_TIMEOUT)
|
||||
.doOnSubscribe(x -> log.info("addClasspathListener ..."))
|
||||
.doOnSuccess(x -> log.info("addClasspathListener DONE"))
|
||||
.doOnError(t -> {
|
||||
if (isNoJdtError(t)) {
|
||||
log.info("JDT Language Server not available. Fallback classpath provider will be used instead.");
|
||||
} else if (isOldJdt(t)) {
|
||||
log.info("JDT Lanuage Server too old. Fallback classpath provider will be used instead.");
|
||||
} else {
|
||||
log.error("Unexpected error registering classpath listener with JDT. Fallback classpath provider will be used instead.", t);
|
||||
}
|
||||
log.error("Unexpected error registering classpath listener with JDT. Fallback classpath provider will be used instead.", t);
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user