summaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorGeorge Fraser <george@fivetran.com>2019-01-18 22:34:22 -0800
committerGeorge Fraser <george@fivetran.com>2019-01-18 22:34:22 -0800
commit14e60343372249d58748409a2705ff999c387858 (patch)
tree125310196db1d388682a22c7fd81552471a639e3 /src/main
parent32123abda7097d14b1a326e6e9bee52d9ae94761 (diff)
downloadjava-language-server-14e60343372249d58748409a2705ff999c387858.zip
Speed up list
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/javacs/FileStore.java10
-rw-r--r--src/main/java/org/javacs/SourceFileManager.java6
2 files changed, 6 insertions, 10 deletions
diff --git a/src/main/java/org/javacs/FileStore.java b/src/main/java/org/javacs/FileStore.java
index 6982caa..61488a7 100644
--- a/src/main/java/org/javacs/FileStore.java
+++ b/src/main/java/org/javacs/FileStore.java
@@ -35,6 +35,7 @@ class FileStore {
private static final Map<URI, VersionedContent> activeDocuments = new HashMap<>();
/** javaSources[file] is the javaSources time of a .java source file. */
+ // TODO organize by package name for speed of list(...)
private static final TreeMap<Path, Info> javaSources = new TreeMap<>();
private static class Info {
@@ -88,7 +89,6 @@ class FileStore {
for (var kv : javaSources.entrySet()) {
var file = kv.getKey();
var info = kv.getValue();
- if (!FileStore.isJavaFile(file)) continue;
if (info.packageName.equals(packageName)) list.add(file);
}
return list;
@@ -176,14 +176,14 @@ class FileStore {
static void open(DidOpenTextDocumentParams params) {
var document = params.textDocument;
var uri = document.uri;
- if (!FileStore.isJavaFile(uri)) return;
+ if (!isJavaFile(uri)) return;
activeDocuments.put(uri, new VersionedContent(document.text, document.version));
}
static void change(DidChangeTextDocumentParams params) {
var document = params.textDocument;
var uri = document.uri;
- if (FileStore.isJavaFile(uri)) {
+ if (isJavaFile(uri)) {
var existing = activeDocuments.get(uri);
var newText = existing.content;
@@ -201,7 +201,7 @@ class FileStore {
static void close(DidCloseTextDocumentParams params) {
var document = params.textDocument;
var uri = document.uri;
- if (FileStore.isJavaFile(uri)) {
+ if (isJavaFile(uri)) {
// Remove from source cache
activeDocuments.remove(uri);
}
@@ -217,7 +217,7 @@ class FileStore {
}
static String contents(URI file) {
- if (!FileStore.isJavaFile(file)) {
+ if (!isJavaFile(file)) {
throw new RuntimeException(file + " is not a java file");
}
if (activeDocuments.containsKey(file)) {
diff --git a/src/main/java/org/javacs/SourceFileManager.java b/src/main/java/org/javacs/SourceFileManager.java
index 9ea750f..b7e701e 100644
--- a/src/main/java/org/javacs/SourceFileManager.java
+++ b/src/main/java/org/javacs/SourceFileManager.java
@@ -26,17 +26,13 @@ class SourceFileManager extends ForwardingJavaFileManager<StandardJavaFileManage
public Iterable<JavaFileObject> list(
Location location, String packageName, Set<JavaFileObject.Kind> kinds, boolean recurse) throws IOException {
if (location == StandardLocation.SOURCE_PATH) {
- var stream = FileStore.list(packageName).stream().map(this::asJavaFileObject).filter(this::isJavaSource);
+ var stream = FileStore.list(packageName).stream().map(this::asJavaFileObject);
return stream::iterator;
} else {
return super.list(location, packageName, kinds, recurse);
}
}
- private boolean isJavaSource(JavaFileObject file) {
- return FileStore.isJavaFile(file.toUri());
- }
-
private JavaFileObject asJavaFileObject(Path file) {
return new SourceFileObject(file);
}