Merge branch 'master' of github.com:spring-projects/sts4
This commit is contained in:
@@ -92,7 +92,7 @@ public class BootJavaLanguageServer extends SimpleLanguageServer {
|
||||
|
||||
projectFinder = serverParams.projectFinder;
|
||||
projectObserver = serverParams.projectObserver;
|
||||
cuCache = new CompilationUnitCache(projectFinder, getWorkspaceService().getFileObserver(), projectObserver);
|
||||
cuCache = new CompilationUnitCache(projectFinder, getTextDocumentService(), projectObserver);
|
||||
|
||||
propertyIndexProvider = serverParams.indexProvider;
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ package org.springframework.ide.vscode.boot.java.utils;
|
||||
|
||||
import java.net.URI;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -29,8 +28,8 @@ import org.springframework.ide.vscode.commons.java.IClasspath;
|
||||
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.SimpleTextDocumentService;
|
||||
import org.springframework.ide.vscode.commons.util.BadLocationException;
|
||||
import org.springframework.ide.vscode.commons.util.FileObserver;
|
||||
import org.springframework.ide.vscode.commons.util.text.TextDocument;
|
||||
|
||||
import com.google.common.cache.Cache;
|
||||
@@ -38,32 +37,26 @@ import com.google.common.cache.CacheBuilder;
|
||||
|
||||
public final class CompilationUnitCache {
|
||||
|
||||
private static final String GLOB_ALL_JAVA_FILES = "**/*.java";
|
||||
|
||||
private JavaProjectFinder projectFinder;
|
||||
private FileObserver fileObserver;
|
||||
private ProjectObserver projectObserver;
|
||||
private Cache<URI, CompilationUnit> uriToCu;
|
||||
private Cache<IJavaProject, Set<URI>> projectToDocs;
|
||||
private String fileChangeSubscription;
|
||||
private String fileDeletedSubscription;
|
||||
private ProjectObserver.Listener projectListener;
|
||||
|
||||
private ReadLock readLock;
|
||||
private WriteLock writeLock;
|
||||
|
||||
public CompilationUnitCache(JavaProjectFinder projectFinder, FileObserver fileObserver, ProjectObserver projectObserver) {
|
||||
public CompilationUnitCache(JavaProjectFinder projectFinder, SimpleTextDocumentService documentService, ProjectObserver projectObserver) {
|
||||
this.projectFinder = projectFinder;
|
||||
this.fileObserver = fileObserver;
|
||||
this.projectObserver = projectObserver;
|
||||
projectListener = new CUProjectListener();
|
||||
|
||||
uriToCu = CacheBuilder.newBuilder().build();
|
||||
projectToDocs = CacheBuilder.newBuilder().build();
|
||||
|
||||
if (this.fileObserver != null) {
|
||||
fileChangeSubscription = this.fileObserver.onFileChanged(Collections.singletonList(GLOB_ALL_JAVA_FILES), (uri) -> invalidateCuForJavaFile(uri));
|
||||
fileDeletedSubscription = this.fileObserver.onFileDeleted(Collections.singletonList(GLOB_ALL_JAVA_FILES), (uri) -> invalidateCuForJavaFile(uri));
|
||||
if (documentService != null) {
|
||||
documentService.onDidChangeContent(doc -> invalidateCuForJavaFile(doc.getDocument().getId().getUri()));
|
||||
documentService.onDidClose(doc -> invalidateCuForJavaFile(doc.getId().getUri()));
|
||||
}
|
||||
|
||||
if (this.projectObserver != null) {
|
||||
@@ -76,10 +69,6 @@ public final class CompilationUnitCache {
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
if (fileObserver != null) {
|
||||
fileObserver.unsubscribe(fileChangeSubscription);
|
||||
fileObserver.unsubscribe(fileDeletedSubscription);
|
||||
}
|
||||
if (projectObserver != null) {
|
||||
projectObserver.removeListener(projectListener);
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ public class CompilationUnitCacheTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cu_cache_invalidated_by_file_change() throws Exception {
|
||||
public void cu_cache_invalidated_by_doc_change() throws Exception {
|
||||
harness.intialize(null);
|
||||
|
||||
TextDocument doc = new TextDocument(harness.createTempUri(), LanguageId.JAVA, 0, "package my.package\n" +
|
||||
@@ -71,10 +71,12 @@ public class CompilationUnitCacheTest {
|
||||
"public class SomeClass {\n" +
|
||||
"\n" +
|
||||
"}\n");
|
||||
|
||||
harness.newEditorFromFileUri(doc.getUri(), doc.getLanguageId());
|
||||
CompilationUnit cu = harness.getServer().getCompilationUnitCache().getCompilationUnit(doc);
|
||||
assertNotNull(cu);
|
||||
|
||||
harness.changeFile(doc.getUri());
|
||||
harness.changeDocument(doc.getUri(), 0, 0, " ");
|
||||
CompilationUnit cuAnother = harness.getServer().getCompilationUnitCache().getCompilationUnit(doc);
|
||||
assertNotNull(cuAnother);
|
||||
assertFalse(cu == cuAnother);
|
||||
@@ -84,7 +86,7 @@ public class CompilationUnitCacheTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cu_cache_invalidated_by_file_removal() throws Exception {
|
||||
public void cu_cache_invalidated_by_doc_close() throws Exception {
|
||||
harness.intialize(null);
|
||||
|
||||
TextDocument doc = new TextDocument(harness.createTempUri(), LanguageId.JAVA, 0, "package my.package\n" +
|
||||
@@ -92,10 +94,12 @@ public class CompilationUnitCacheTest {
|
||||
"public class SomeClass {\n" +
|
||||
"\n" +
|
||||
"}\n");
|
||||
|
||||
harness.newEditorFromFileUri(doc.getUri(), doc.getLanguageId());
|
||||
CompilationUnit cu = harness.getServer().getCompilationUnitCache().getCompilationUnit(doc);
|
||||
assertNotNull(cu);
|
||||
|
||||
harness.deleteFile(doc.getUri());
|
||||
harness.closeDocument(doc.getId());
|
||||
CompilationUnit cuAnother = harness.getServer().getCompilationUnitCache().getCompilationUnit(doc);
|
||||
assertNotNull(cuAnother);
|
||||
assertFalse(cu == cuAnother);
|
||||
|
||||
Reference in New Issue
Block a user