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;
|
projectFinder = serverParams.projectFinder;
|
||||||
projectObserver = serverParams.projectObserver;
|
projectObserver = serverParams.projectObserver;
|
||||||
cuCache = new CompilationUnitCache(projectFinder, getWorkspaceService().getFileObserver(), projectObserver);
|
cuCache = new CompilationUnitCache(projectFinder, getTextDocumentService(), projectObserver);
|
||||||
|
|
||||||
propertyIndexProvider = serverParams.indexProvider;
|
propertyIndexProvider = serverParams.indexProvider;
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ package org.springframework.ide.vscode.boot.java.utils;
|
|||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
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.java.IJavaProject;
|
||||||
import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder;
|
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.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.BadLocationException;
|
||||||
import org.springframework.ide.vscode.commons.util.FileObserver;
|
|
||||||
import org.springframework.ide.vscode.commons.util.text.TextDocument;
|
import org.springframework.ide.vscode.commons.util.text.TextDocument;
|
||||||
|
|
||||||
import com.google.common.cache.Cache;
|
import com.google.common.cache.Cache;
|
||||||
@@ -38,32 +37,26 @@ import com.google.common.cache.CacheBuilder;
|
|||||||
|
|
||||||
public final class CompilationUnitCache {
|
public final class CompilationUnitCache {
|
||||||
|
|
||||||
private static final String GLOB_ALL_JAVA_FILES = "**/*.java";
|
|
||||||
|
|
||||||
private JavaProjectFinder projectFinder;
|
private JavaProjectFinder projectFinder;
|
||||||
private FileObserver fileObserver;
|
|
||||||
private ProjectObserver projectObserver;
|
private ProjectObserver projectObserver;
|
||||||
private Cache<URI, CompilationUnit> uriToCu;
|
private Cache<URI, CompilationUnit> uriToCu;
|
||||||
private Cache<IJavaProject, Set<URI>> projectToDocs;
|
private Cache<IJavaProject, Set<URI>> projectToDocs;
|
||||||
private String fileChangeSubscription;
|
|
||||||
private String fileDeletedSubscription;
|
|
||||||
private ProjectObserver.Listener projectListener;
|
private ProjectObserver.Listener projectListener;
|
||||||
|
|
||||||
private ReadLock readLock;
|
private ReadLock readLock;
|
||||||
private WriteLock writeLock;
|
private WriteLock writeLock;
|
||||||
|
|
||||||
public CompilationUnitCache(JavaProjectFinder projectFinder, FileObserver fileObserver, ProjectObserver projectObserver) {
|
public CompilationUnitCache(JavaProjectFinder projectFinder, SimpleTextDocumentService documentService, ProjectObserver projectObserver) {
|
||||||
this.projectFinder = projectFinder;
|
this.projectFinder = projectFinder;
|
||||||
this.fileObserver = fileObserver;
|
|
||||||
this.projectObserver = projectObserver;
|
this.projectObserver = projectObserver;
|
||||||
projectListener = new CUProjectListener();
|
projectListener = new CUProjectListener();
|
||||||
|
|
||||||
uriToCu = CacheBuilder.newBuilder().build();
|
uriToCu = CacheBuilder.newBuilder().build();
|
||||||
projectToDocs = CacheBuilder.newBuilder().build();
|
projectToDocs = CacheBuilder.newBuilder().build();
|
||||||
|
|
||||||
if (this.fileObserver != null) {
|
if (documentService != null) {
|
||||||
fileChangeSubscription = this.fileObserver.onFileChanged(Collections.singletonList(GLOB_ALL_JAVA_FILES), (uri) -> invalidateCuForJavaFile(uri));
|
documentService.onDidChangeContent(doc -> invalidateCuForJavaFile(doc.getDocument().getId().getUri()));
|
||||||
fileDeletedSubscription = this.fileObserver.onFileDeleted(Collections.singletonList(GLOB_ALL_JAVA_FILES), (uri) -> invalidateCuForJavaFile(uri));
|
documentService.onDidClose(doc -> invalidateCuForJavaFile(doc.getId().getUri()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.projectObserver != null) {
|
if (this.projectObserver != null) {
|
||||||
@@ -76,10 +69,6 @@ public final class CompilationUnitCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
if (fileObserver != null) {
|
|
||||||
fileObserver.unsubscribe(fileChangeSubscription);
|
|
||||||
fileObserver.unsubscribe(fileDeletedSubscription);
|
|
||||||
}
|
|
||||||
if (projectObserver != null) {
|
if (projectObserver != null) {
|
||||||
projectObserver.removeListener(projectListener);
|
projectObserver.removeListener(projectListener);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ public class CompilationUnitCacheTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void cu_cache_invalidated_by_file_change() throws Exception {
|
public void cu_cache_invalidated_by_doc_change() throws Exception {
|
||||||
harness.intialize(null);
|
harness.intialize(null);
|
||||||
|
|
||||||
TextDocument doc = new TextDocument(harness.createTempUri(), LanguageId.JAVA, 0, "package my.package\n" +
|
TextDocument doc = new TextDocument(harness.createTempUri(), LanguageId.JAVA, 0, "package my.package\n" +
|
||||||
@@ -71,10 +71,12 @@ public class CompilationUnitCacheTest {
|
|||||||
"public class SomeClass {\n" +
|
"public class SomeClass {\n" +
|
||||||
"\n" +
|
"\n" +
|
||||||
"}\n");
|
"}\n");
|
||||||
|
|
||||||
|
harness.newEditorFromFileUri(doc.getUri(), doc.getLanguageId());
|
||||||
CompilationUnit cu = harness.getServer().getCompilationUnitCache().getCompilationUnit(doc);
|
CompilationUnit cu = harness.getServer().getCompilationUnitCache().getCompilationUnit(doc);
|
||||||
assertNotNull(cu);
|
assertNotNull(cu);
|
||||||
|
|
||||||
harness.changeFile(doc.getUri());
|
harness.changeDocument(doc.getUri(), 0, 0, " ");
|
||||||
CompilationUnit cuAnother = harness.getServer().getCompilationUnitCache().getCompilationUnit(doc);
|
CompilationUnit cuAnother = harness.getServer().getCompilationUnitCache().getCompilationUnit(doc);
|
||||||
assertNotNull(cuAnother);
|
assertNotNull(cuAnother);
|
||||||
assertFalse(cu == cuAnother);
|
assertFalse(cu == cuAnother);
|
||||||
@@ -84,7 +86,7 @@ public class CompilationUnitCacheTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void cu_cache_invalidated_by_file_removal() throws Exception {
|
public void cu_cache_invalidated_by_doc_close() throws Exception {
|
||||||
harness.intialize(null);
|
harness.intialize(null);
|
||||||
|
|
||||||
TextDocument doc = new TextDocument(harness.createTempUri(), LanguageId.JAVA, 0, "package my.package\n" +
|
TextDocument doc = new TextDocument(harness.createTempUri(), LanguageId.JAVA, 0, "package my.package\n" +
|
||||||
@@ -92,10 +94,12 @@ public class CompilationUnitCacheTest {
|
|||||||
"public class SomeClass {\n" +
|
"public class SomeClass {\n" +
|
||||||
"\n" +
|
"\n" +
|
||||||
"}\n");
|
"}\n");
|
||||||
|
|
||||||
|
harness.newEditorFromFileUri(doc.getUri(), doc.getLanguageId());
|
||||||
CompilationUnit cu = harness.getServer().getCompilationUnitCache().getCompilationUnit(doc);
|
CompilationUnit cu = harness.getServer().getCompilationUnitCache().getCompilationUnit(doc);
|
||||||
assertNotNull(cu);
|
assertNotNull(cu);
|
||||||
|
|
||||||
harness.deleteFile(doc.getUri());
|
harness.closeDocument(doc.getId());
|
||||||
CompilationUnit cuAnother = harness.getServer().getCompilationUnitCache().getCompilationUnit(doc);
|
CompilationUnit cuAnother = harness.getServer().getCompilationUnitCache().getCompilationUnit(doc);
|
||||||
assertNotNull(cuAnother);
|
assertNotNull(cuAnother);
|
||||||
assertFalse(cu == cuAnother);
|
assertFalse(cu == cuAnother);
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ import org.eclipse.lsp4j.DiagnosticSeverity;
|
|||||||
import org.eclipse.lsp4j.DidChangeConfigurationParams;
|
import org.eclipse.lsp4j.DidChangeConfigurationParams;
|
||||||
import org.eclipse.lsp4j.DidChangeTextDocumentParams;
|
import org.eclipse.lsp4j.DidChangeTextDocumentParams;
|
||||||
import org.eclipse.lsp4j.DidChangeWatchedFilesParams;
|
import org.eclipse.lsp4j.DidChangeWatchedFilesParams;
|
||||||
|
import org.eclipse.lsp4j.DidCloseTextDocumentParams;
|
||||||
import org.eclipse.lsp4j.DidOpenTextDocumentParams;
|
import org.eclipse.lsp4j.DidOpenTextDocumentParams;
|
||||||
import org.eclipse.lsp4j.DocumentSymbolParams;
|
import org.eclipse.lsp4j.DocumentSymbolParams;
|
||||||
import org.eclipse.lsp4j.ExecuteCommandCapabilities;
|
import org.eclipse.lsp4j.ExecuteCommandCapabilities;
|
||||||
@@ -78,6 +79,7 @@ import org.eclipse.lsp4j.ShowMessageRequestParams;
|
|||||||
import org.eclipse.lsp4j.SymbolInformation;
|
import org.eclipse.lsp4j.SymbolInformation;
|
||||||
import org.eclipse.lsp4j.TextDocumentClientCapabilities;
|
import org.eclipse.lsp4j.TextDocumentClientCapabilities;
|
||||||
import org.eclipse.lsp4j.TextDocumentContentChangeEvent;
|
import org.eclipse.lsp4j.TextDocumentContentChangeEvent;
|
||||||
|
import org.eclipse.lsp4j.TextDocumentIdentifier;
|
||||||
import org.eclipse.lsp4j.TextDocumentItem;
|
import org.eclipse.lsp4j.TextDocumentItem;
|
||||||
import org.eclipse.lsp4j.TextDocumentPositionParams;
|
import org.eclipse.lsp4j.TextDocumentPositionParams;
|
||||||
import org.eclipse.lsp4j.TextDocumentSyncKind;
|
import org.eclipse.lsp4j.TextDocumentSyncKind;
|
||||||
@@ -300,6 +302,13 @@ public class LanguageServerHarness<S extends SimpleLanguageServer> {
|
|||||||
return documentInfo;
|
return documentInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void closeDocument(TextDocumentIdentifier id) {
|
||||||
|
DidCloseTextDocumentParams didClose = new DidCloseTextDocumentParams(id);
|
||||||
|
if (getServer() != null) {
|
||||||
|
getServer().getTextDocumentService().didClose(didClose);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public TextDocumentInfo openDocument(File file, String languageId) throws Exception {
|
public TextDocumentInfo openDocument(File file, String languageId) throws Exception {
|
||||||
return openDocument(getOrReadFile(file, languageId));
|
return openDocument(getOrReadFile(file, languageId));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user