Improve project reconcile scheduling and classpath change notification
This commit is contained in:
@@ -10,30 +10,22 @@
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.boot.java.handlers;
|
||||
|
||||
import java.net.URI;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.lsp4j.TextDocumentIdentifier;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.ide.vscode.boot.app.BootJavaConfig;
|
||||
import org.springframework.ide.vscode.boot.common.IJavaProjectReconcileEngine;
|
||||
import org.springframework.ide.vscode.boot.common.ProjectReconcileScheduler;
|
||||
import org.springframework.ide.vscode.boot.java.rewrite.RewriteRecipeRepository;
|
||||
import org.springframework.ide.vscode.commons.java.IClasspathUtil;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.ProjectObserver;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
|
||||
import org.springframework.ide.vscode.commons.util.text.TextDocument;
|
||||
|
||||
public class BootJavaProjectReconcilerScheduler extends ProjectReconcileScheduler {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(BootJavaProjectReconcilerScheduler.class);
|
||||
|
||||
private static final List<String> FILES_TO_WATCH_GLOB = List.of("**/*.java");
|
||||
// private static final List<String> FILES_TO_WATCH_GLOB = List.of("**/*.java");
|
||||
|
||||
private ProjectObserver projectObserver;
|
||||
private BootJavaConfig config;
|
||||
@@ -88,29 +80,29 @@ public class BootJavaProjectReconcilerScheduler extends ProjectReconcileSchedule
|
||||
}
|
||||
});
|
||||
|
||||
getServer().getWorkspaceService().getFileObserver().onFilesChanged(FILES_TO_WATCH_GLOB, this::handleFiles);
|
||||
getServer().getWorkspaceService().getFileObserver().onFilesCreated(FILES_TO_WATCH_GLOB, this::handleFiles);
|
||||
// getServer().getWorkspaceService().getFileObserver().onFilesChanged(FILES_TO_WATCH_GLOB, this::handleFiles);
|
||||
// getServer().getWorkspaceService().getFileObserver().onFilesCreated(FILES_TO_WATCH_GLOB, this::handleFiles);
|
||||
|
||||
// TODO: index update even happens on every file save. Very expensive to blindly reconcile all projects.
|
||||
// Need to figure out a check if spring index has any changes
|
||||
// springIndexer.onUpdate(v -> reconcile());
|
||||
}
|
||||
|
||||
private void handleFiles(String[] files) {
|
||||
for (String f : files) {
|
||||
URI uri = URI.create(f);
|
||||
TextDocumentIdentifier docId = new TextDocumentIdentifier(uri.toASCIIString());
|
||||
TextDocument doc = getServer().getTextDocumentService().getLatestSnapshot(docId.getUri());
|
||||
if (doc == null) {
|
||||
getProjectFinder().find(docId).ifPresent(project -> {
|
||||
Path p = Paths.get(uri);
|
||||
if (IClasspathUtil.getSourceFolders(project.getClasspath())
|
||||
.filter(folder -> p.startsWith(folder.toPath())).findFirst().isPresent()) {
|
||||
scheduleValidation(project);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
// private void handleFiles(String[] files) {
|
||||
// for (String f : files) {
|
||||
// URI uri = URI.create(f);
|
||||
// TextDocumentIdentifier docId = new TextDocumentIdentifier(uri.toASCIIString());
|
||||
// TextDocument doc = getServer().getTextDocumentService().getLatestSnapshot(docId.getUri());
|
||||
// if (doc == null) {
|
||||
// getProjectFinder().find(docId).ifPresent(project -> {
|
||||
// Path p = Paths.get(uri);
|
||||
// if (IClasspathUtil.getSourceFolders(project.getClasspath())
|
||||
// .filter(folder -> p.startsWith(folder.toPath())).findFirst().isPresent()) {
|
||||
// scheduleValidation(project);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user