Skip to content

Commit 82bf894

Browse files
committed
Start type checker when file fact is created.
1 parent 9bee119 commit 82bf894

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

  • rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/rascal/model

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@
2727
package org.rascalmpl.vscode.lsp.rascal.model;
2828

2929
import java.util.Collections;
30-
import java.util.HashMap;
3130
import java.util.List;
3231
import java.util.Map;
3332
import java.util.concurrent.CompletableFuture;
3433
import java.util.concurrent.ConcurrentHashMap;
3534
import java.util.concurrent.Executor;
35+
import java.util.stream.Collectors;
3636

3737
import org.apache.logging.log4j.LogManager;
3838
import org.apache.logging.log4j.Logger;
@@ -51,6 +51,7 @@
5151
import org.rascalmpl.vscode.lsp.util.locations.ColumnMaps;
5252
import org.rascalmpl.vscode.lsp.util.locations.Locations;
5353

54+
import io.usethesource.vallang.ISet;
5455
import io.usethesource.vallang.ISourceLocation;
5556

5657
public class FileFacts {
@@ -107,7 +108,7 @@ private class FileFact {
107108

108109
public FileFact(ISourceLocation file, Executor exec) {
109110
this.file = file;
110-
this.typeCheckResults = new ReplaceableFuture<>(CompletableFuture.completedFuture(Collections.emptyMap()));
111+
this.typeCheckResults = new ReplaceableFuture<>(typeCheck());
111112
this.summary = new LazyUpdateableReference<>(
112113
new InterruptibleFuture<>(CompletableFuture.completedFuture(new SummaryBridge()), () -> {
113114
}),
@@ -150,14 +151,15 @@ private void sendDiagnostics() {
150151
public void invalidate() {
151152
summary.invalidate();
152153
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)));
154+
this.typeCheckResults.replace(typeCheck()).thenAccept(m -> m.forEach((f, msgs) -> getFile(f).reportTypeCheckerErrors(msgs)));
155+
}
156+
157+
private InterruptibleFuture<Map<ISourceLocation, List<Diagnostic>>> typeCheck() {
158+
return rascal.compileFile(file, confs.lookupConfig(file), exec)
159+
.thenApply(m -> m.entrySet().stream().collect(Collectors.toMap(
160+
Map.Entry<ISourceLocation, ISet>::getKey,
161+
e -> Diagnostics.translateDiagnostics(e.getKey(), e.getValue(), cm)
162+
)));
161163
}
162164

163165
}

0 commit comments

Comments
 (0)