summaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorGeorge Fraser <george@fivetran.com>2018-12-30 17:08:39 -0800
committerGeorge Fraser <george@fivetran.com>2018-12-30 17:08:39 -0800
commitbf5a86da23782a0b297f4862fef9ca6597ca9cbc (patch)
treedc262f13c64fb454f13a10042ea4e94ab4f27bb9 /src/main
parentf8f680f3636a132975381e8bb8ca55f7af8bd68a (diff)
downloadjava-language-server-bf5a86da23782a0b297f4862fef9ca6597ca9cbc.zip
Constantly reindex files with errors
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/javacs/CompileBatch.java11
-rw-r--r--src/main/java/org/javacs/Index.java6
-rw-r--r--src/main/java/org/javacs/JavaCompilerService.java27
3 files changed, 32 insertions, 12 deletions
diff --git a/src/main/java/org/javacs/CompileBatch.java b/src/main/java/org/javacs/CompileBatch.java
index f344c82..a705abb 100644
--- a/src/main/java/org/javacs/CompileBatch.java
+++ b/src/main/java/org/javacs/CompileBatch.java
@@ -116,13 +116,22 @@ public class CompileBatch {
var uri = f.getSourceFile().toUri();
var path = Paths.get(uri);
var refs = index(f);
+ // Remember when file was modified
FileTime modified;
try {
modified = Files.getLastModifiedTime(path);
} catch (IOException e) {
throw new RuntimeException(e);
}
- var i = new Index(refs, modified.toInstant());
+ // Remember if file contains any errors
+ var containsError = false;
+ for (var d : parent.diags) {
+ var isError = d.getKind() == Diagnostic.Kind.ERROR;
+ var sameUri = d.getSource().toUri().equals(uri);
+ if (isError && sameUri) containsError = true;
+ }
+ // Add file to index
+ var i = new Index(refs, modified.toInstant(), containsError);
index.put(uri, i);
}
return index;
diff --git a/src/main/java/org/javacs/Index.java b/src/main/java/org/javacs/Index.java
index 2e7aaab..482a464 100644
--- a/src/main/java/org/javacs/Index.java
+++ b/src/main/java/org/javacs/Index.java
@@ -4,14 +4,16 @@ import java.time.Instant;
import java.util.List;
public class Index {
- public static final Index EMPTY = new Index(List.of(), Instant.EPOCH);
+ public static final Index EMPTY = new Index(List.of(), Instant.EPOCH, false);
public final List<Ptr> refs;
// TODO modified time can rewind when you switch branches, need to track modified and look for exact match
public final Instant created;
+ public final boolean containsError;
- public Index(List<Ptr> refs, Instant created) {
+ public Index(List<Ptr> refs, Instant created, boolean containsError) {
this.refs = refs;
this.created = created;
+ this.containsError = containsError;
}
}
diff --git a/src/main/java/org/javacs/JavaCompilerService.java b/src/main/java/org/javacs/JavaCompilerService.java
index 624cb95..ddcb82f 100644
--- a/src/main/java/org/javacs/JavaCompilerService.java
+++ b/src/main/java/org/javacs/JavaCompilerService.java
@@ -304,25 +304,34 @@ public class JavaCompilerService {
private void updateIndex(Collection<URI> possible, ReportProgress progress) {
LOG.info(String.format("Check %d files for modifications compared to index...", possible.size()));
+
+ // Figure out all files that have been changed, or contained errors at the time they were indexed
var outOfDate = new ArrayList<URI>();
+ var hasError = new ArrayList<URI>();
for (var p : possible) {
var i = index.getOrDefault(p, Index.EMPTY);
var modified = Instant.ofEpochMilli(new File(p).lastModified());
- if (modified.isAfter(i.created)) {
- outOfDate.add(p);
- }
+ if (modified.isAfter(i.created)) outOfDate.add(p);
+ if (i.containsError) hasError.add(p);
}
- LOG.info(String.format("... %d files are out-of-date", outOfDate.size()));
+ if (outOfDate.size() > 0) LOG.info(String.format("... %d files are out-of-date", outOfDate.size()));
+ if (hasError.size() > 0) LOG.info(String.format("... %d files contain errors", hasError.size()));
+
// If there's nothing to update, return
- if (outOfDate.isEmpty()) return;
+ var needsUpdate = new ArrayList<URI>();
+ needsUpdate.addAll(outOfDate);
+ needsUpdate.addAll(hasError);
+ if (needsUpdate.isEmpty()) return;
+
// If there's more than 1 file, report progress
- if (outOfDate.size() > 1) { // TODO this could probably be tuned to be higher
- progress.start(String.format("Index %d files", outOfDate.size()));
+ if (needsUpdate.size() > 1) { // TODO this could probably be tuned to be higher
+ progress.start(String.format("Index %d files", needsUpdate.size()));
} else {
progress = ReportProgress.EMPTY;
}
- // Reindex
- var counts = compileBatch(outOfDate, progress).countReferences();
+
+ // Compile in a batch and update the index
+ var counts = compileBatch(needsUpdate, progress).countReferences();
index.putAll(counts);
}