From 82bf8943c599e34b4f4a4d8121780ebf3acd9449 Mon Sep 17 00:00:00 2001 From: Toine Hartman Date: Mon, 21 Jul 2025 17:31:20 +0200 Subject: [PATCH 1/2] Start type checker when file fact is created. --- .../vscode/lsp/rascal/model/FileFacts.java | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) 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..6de2405f7 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 { @@ -107,7 +108,7 @@ private class FileFact { public FileFact(ISourceLocation file, Executor exec) { 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) + ))); } } From de57ba92ce9e652c63b9d39ce5b9ea00aafe851e Mon Sep 17 00:00:00 2001 From: Toine Hartman Date: Tue, 22 Jul 2025 15:42:32 +0200 Subject: [PATCH 2/2] Remove unused constructor param. --- .../java/org/rascalmpl/vscode/lsp/rascal/model/FileFacts.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 6de2405f7..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 @@ -92,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) { @@ -106,7 +106,7 @@ 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<>(typeCheck()); this.summary = new LazyUpdateableReference<>(