Skip to content

Commit bd79abf

Browse files
committed
Start type checker when file fact is created.
1 parent 95ceb84 commit bd79abf

File tree

1 file changed

+13
-10
lines changed
  • rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/rascal/model

1 file changed

+13
-10
lines changed

rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/rascal/model/FileFacts.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@
2828

2929
import java.io.IOException;
3030
import java.util.Collections;
31-
import java.util.HashMap;
3231
import java.util.List;
3332
import java.util.Map;
3433
import java.util.concurrent.CompletableFuture;
3534
import java.util.concurrent.ConcurrentHashMap;
3635
import java.util.concurrent.Executor;
36+
import java.util.stream.Collectors;
37+
3738
import org.apache.logging.log4j.LogManager;
3839
import org.apache.logging.log4j.Logger;
3940
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
@@ -51,6 +52,7 @@
5152
import org.rascalmpl.vscode.lsp.util.locations.ColumnMaps;
5253
import org.rascalmpl.vscode.lsp.util.locations.Locations;
5354

55+
import io.usethesource.vallang.ISet;
5456
import io.usethesource.vallang.ISourceLocation;
5557

5658
public class FileFacts {
@@ -107,7 +109,7 @@ private class FileFact {
107109

108110
public FileFact(ISourceLocation file, Executor exec) {
109111
this.file = file;
110-
this.typeCheckResults = new ReplaceableFuture<>(CompletableFuture.completedFuture(Collections.emptyMap()));
112+
this.typeCheckResults = new ReplaceableFuture<>(typeCheck());
111113
this.summary = new LazyUpdateableReference<>(
112114
new InterruptibleFuture<>(CompletableFuture.completedFuture(new SummaryBridge()), () -> {
113115
}),
@@ -150,14 +152,15 @@ private void sendDiagnostics() {
150152
public void invalidate() {
151153
summary.invalidate();
152154
typeCheckerMessages.clear();
153-
this.typeCheckResults.replace(
154-
rascal.compileFile(file, confs.lookupConfig(file), exec)
155-
.thenApply(m -> {
156-
Map<ISourceLocation, List<Diagnostic>> result = new HashMap<>(m.size());
157-
m.forEach((l, msgs) -> result.put(l, Diagnostics.translateDiagnostics(l, msgs, cm)));
158-
return result;
159-
})
160-
).thenAccept(m -> m.forEach((f, msgs) -> getFile(f).reportTypeCheckerErrors(msgs)));
155+
this.typeCheckResults.replace(typeCheck()).thenAccept(m -> m.forEach((f, msgs) -> getFile(f).reportTypeCheckerErrors(msgs)));
156+
}
157+
158+
private InterruptibleFuture<Map<ISourceLocation, List<Diagnostic>>> typeCheck() {
159+
return rascal.compileFile(file, confs.lookupConfig(file), exec)
160+
.thenApply(m -> m.entrySet().stream().collect(Collectors.toMap(
161+
Map.Entry<ISourceLocation, ISet>::getKey,
162+
e -> Diagnostics.translateDiagnostics(e.getKey(), e.getValue(), cm)
163+
)));
161164
}
162165

163166
}

0 commit comments

Comments
 (0)