diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/rascal/model/FileFacts.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/rascal/model/FileFacts.java index 6a656b8a4..2db4efc93 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/rascal/model/FileFacts.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/rascal/model/FileFacts.java @@ -27,12 +27,12 @@ package org.rascalmpl.vscode.lsp.rascal.model; import java.util.Collections; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.Executor; +import java.util.stream.Collectors; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -51,6 +51,7 @@ import org.rascalmpl.vscode.lsp.util.locations.ColumnMaps; import org.rascalmpl.vscode.lsp.util.locations.Locations; +import io.usethesource.vallang.ISet; import io.usethesource.vallang.ISourceLocation; public class FileFacts { @@ -91,7 +92,7 @@ private FileFact getFile(ISourceLocation l) { if (resolved == null) { resolved = l; } - return files.computeIfAbsent(resolved, l1 -> new FileFact(l1, exec)); + return files.computeIfAbsent(resolved, l1 -> new FileFact(l1)); } public PathConfig getPathConfig(ISourceLocation file) { @@ -105,9 +106,9 @@ private class FileFact { private volatile List typeCheckerMessages = Collections.emptyList(); private final ReplaceableFuture>> typeCheckResults; - public FileFact(ISourceLocation file, Executor exec) { + public FileFact(ISourceLocation file) { this.file = file; - this.typeCheckResults = new ReplaceableFuture<>(CompletableFuture.completedFuture(Collections.emptyMap())); + this.typeCheckResults = new ReplaceableFuture<>(typeCheck()); this.summary = new LazyUpdateableReference<>( new InterruptibleFuture<>(CompletableFuture.completedFuture(new SummaryBridge()), () -> { }), @@ -150,14 +151,15 @@ private void sendDiagnostics() { public void invalidate() { summary.invalidate(); typeCheckerMessages.clear(); - this.typeCheckResults.replace( - rascal.compileFile(file, confs.lookupConfig(file), exec) - .thenApply(m -> { - Map> result = new HashMap<>(m.size()); - m.forEach((l, msgs) -> result.put(l, Diagnostics.translateDiagnostics(l, msgs, cm))); - return result; - }) - ).thenAccept(m -> m.forEach((f, msgs) -> getFile(f).reportTypeCheckerErrors(msgs))); + this.typeCheckResults.replace(typeCheck()).thenAccept(m -> m.forEach((f, msgs) -> getFile(f).reportTypeCheckerErrors(msgs))); + } + + private InterruptibleFuture>> typeCheck() { + return rascal.compileFile(file, confs.lookupConfig(file), exec) + .thenApply(m -> m.entrySet().stream().collect(Collectors.toMap( + Map.Entry::getKey, + e -> Diagnostics.translateDiagnostics(e.getKey(), e.getValue(), cm) + ))); } }