3030import java .util .List ;
3131import java .util .concurrent .CompletableFuture ;
3232import java .util .concurrent .CompletionException ;
33+ import java .util .concurrent .ExecutorService ;
3334import java .util .concurrent .TimeUnit ;
3435import java .util .concurrent .atomic .AtomicReference ;
3536import 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}
0 commit comments