|
28 | 28 |
|
29 | 29 | import java.io.IOException; |
30 | 30 | import java.util.Collections; |
31 | | -import java.util.HashMap; |
32 | 31 | import java.util.List; |
33 | 32 | import java.util.Map; |
34 | 33 | import java.util.concurrent.CompletableFuture; |
35 | 34 | import java.util.concurrent.ConcurrentHashMap; |
36 | 35 | import java.util.concurrent.Executor; |
| 36 | +import java.util.stream.Collectors; |
| 37 | + |
37 | 38 | import org.apache.logging.log4j.LogManager; |
38 | 39 | import org.apache.logging.log4j.Logger; |
39 | 40 | import org.checkerframework.checker.nullness.qual.MonotonicNonNull; |
|
51 | 52 | import org.rascalmpl.vscode.lsp.util.locations.ColumnMaps; |
52 | 53 | import org.rascalmpl.vscode.lsp.util.locations.Locations; |
53 | 54 |
|
| 55 | +import io.usethesource.vallang.ISet; |
54 | 56 | import io.usethesource.vallang.ISourceLocation; |
55 | 57 |
|
56 | 58 | public class FileFacts { |
@@ -107,7 +109,7 @@ private class FileFact { |
107 | 109 |
|
108 | 110 | public FileFact(ISourceLocation file, Executor exec) { |
109 | 111 | this.file = file; |
110 | | - this.typeCheckResults = new ReplaceableFuture<>(CompletableFuture.completedFuture(Collections.emptyMap())); |
| 112 | + this.typeCheckResults = new ReplaceableFuture<>(typeCheck()); |
111 | 113 | this.summary = new LazyUpdateableReference<>( |
112 | 114 | new InterruptibleFuture<>(CompletableFuture.completedFuture(new SummaryBridge()), () -> { |
113 | 115 | }), |
@@ -150,14 +152,15 @@ private void sendDiagnostics() { |
150 | 152 | public void invalidate() { |
151 | 153 | summary.invalidate(); |
152 | 154 | 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 | + ))); |
161 | 164 | } |
162 | 165 |
|
163 | 166 | } |
|
0 commit comments