Skip to content

Commit 2d7e28a

Browse files
toinehartmansungshik
authored andcommitted
Fix issue that tree updates of document states post-parsing weren't explicitly executed on the worker pool yet (but possibly on the request pool)
1 parent d86572f commit 2d7e28a

3 files changed

Lines changed: 10 additions & 6 deletions

File tree

rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/TextDocumentState.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.List;
3131
import java.util.concurrent.CompletableFuture;
3232
import java.util.concurrent.CompletionException;
33+
import java.util.concurrent.ExecutorService;
3334
import java.util.concurrent.TimeUnit;
3435
import java.util.concurrent.atomic.AtomicReference;
3536
import java.util.function.BiFunction;
@@ -62,6 +63,7 @@ public class TextDocumentState {
6263

6364
private final BiFunction<ISourceLocation, String, CompletableFuture<ITree>> parser;
6465
private final ISourceLocation location;
66+
private final ExecutorService exec;
6567

6668
private final AtomicReference<Versioned<Update>> current;
6769
private final AtomicReference<@Nullable Versioned<ITree>> lastWithoutErrors;
@@ -70,12 +72,14 @@ public class TextDocumentState {
7072
public TextDocumentState(
7173
BiFunction<ISourceLocation, String, CompletableFuture<ITree>> parser,
7274
ISourceLocation location,
73-
int initialVersion, String initialContent, long initialTimestamp) {
75+
int initialVersion, String initialContent, long initialTimestamp,
76+
ExecutorService exec) {
7477

7578
this.parser = parser;
7679
this.location = location;
7780
this.lastWithoutErrors = new AtomicReference<>();
7881
this.last = new AtomicReference<>();
82+
this.exec = exec;
7983

8084
var u = new Update(initialVersion, initialContent, initialTimestamp);
8185
this.current = new AtomicReference<>(new Versioned<>(initialVersion, u));
@@ -200,7 +204,7 @@ public CompletableFuture<Versioned<List<Diagnostics.Template>>> getDiagnosticsAs
200204
private void parse() {
201205
try {
202206
parser.apply(location, content)
203-
.whenComplete((ITree t, Throwable e) -> {
207+
.whenCompleteAsync((ITree t, Throwable e) -> {
204208
if (e instanceof CompletionException && e.getCause() != null) {
205209
e = e.getCause();
206210
}
@@ -221,7 +225,7 @@ private void parse() {
221225
// Complete future to get diagnostics
222226
var diagnostics = new Versioned<>(version, diagnosticsList);
223227
diagnosticsAsync.complete(diagnostics);
224-
});
228+
}, exec);
225229
} catch (NoContributionException e) {
226230
logger.debug("Ignoring missing parser for {}", location, e);
227231
treeAsync.completeOnTimeout(new Versioned<>(version, IRascalValueFactory.getInstance().character(0), timestamp), 60, TimeUnit.SECONDS);
@@ -255,6 +259,6 @@ public long getLastModified() {
255259

256260
public TextDocumentState changeParser(BiFunction<ISourceLocation, String, CompletableFuture<ITree>> parsing) {
257261
var c = getCurrentContent();
258-
return new TextDocumentState(parsing, this.location, c.version(), c.get(), getLastModified());
262+
return new TextDocumentState(parsing, this.location, c.version(), c.get(), getLastModified(), exec);
259263
}
260264
}

rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/parametric/ParametricTextDocumentService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ private ParametricFileFacts facts(ISourceLocation doc) {
713713

714714
private TextDocumentState open(TextDocumentItem doc, long timestamp) {
715715
return files.computeIfAbsent(Locations.toLoc(doc),
716-
l -> new TextDocumentState(contributions(l)::parsing, l, doc.getVersion(), doc.getText(), timestamp));
716+
l -> new TextDocumentState(contributions(l)::parsing, l, doc.getVersion(), doc.getText(), timestamp, exec));
717717
}
718718

719719
private TextDocumentState getFile(ISourceLocation loc) {

rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/rascal/RascalTextDocumentService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ private static <T> T last(List<T> l) {
557557

558558
private TextDocumentState open(TextDocumentItem doc, long timestamp) {
559559
return documents.computeIfAbsent(Locations.toLoc(doc),
560-
l -> new TextDocumentState(availableRascalServices()::parseSourceFile, l, doc.getVersion(), doc.getText(), timestamp));
560+
l -> new TextDocumentState(availableRascalServices()::parseSourceFile, l, doc.getVersion(), doc.getText(), timestamp, exec));
561561
}
562562

563563
private TextDocumentState getFile(TextDocumentIdentifier doc) {

0 commit comments

Comments
 (0)