3838import java .util .Collections ;
3939import java .util .List ;
4040import java .util .Map ;
41+ import java .util .Optional ;
42+ import java .util .concurrent .CompletableFuture ;
4143import java .util .concurrent .TimeUnit ;
4244import java .util .stream .Collectors ;
4345
@@ -134,7 +136,7 @@ public void testMembersOfBindings() {
134136 }
135137
136138 @ Test
137- public void testDiagnostics () {
139+ public void testDiagnostics () throws Exception {
138140 // Syntax errors, and unresolvable classes: errors, where they are.
139141 assertEquals (Collections .singletonList ("Error@1:11-12 Unexpected input: '+'" ),
140142 problems ("sigma = 1.5\n def x = (1 +\n " ));
@@ -289,8 +291,8 @@ public void testInterpreterBindings() {
289291 final ScriptContext live = new SimpleScriptContext ();
290292 live .setAttribute ("injected" , new ArrayList <String >(),
291293 ScriptContext .ENGINE_SCOPE );
292- final List <String > texts = labels (items (session (new Environment (null ,
293- Collections . emptyList (), live )), "injected.si" ));
294+ final List <String > texts = labels (items (session (new Environment (). withLive (
295+ live )), "injected.si" ));
294296 assertTrue (texts .contains ("size" ), texts .toString ());
295297 }
296298
@@ -348,15 +350,21 @@ public void testImportOffset() {
348350
349351 /** A session about plain Groovy, with a server of its own. */
350352 private static ScriptSession session (final Environment env ) {
351- return new ScriptSession (context .service (LanguageServerService .class ),
352- TEST_LANGUAGE , env .live ());
353+ final LanguageServerService servers = context .service (
354+ LanguageServerService .class );
355+ return env .live ().map (live -> new ScriptSession (servers , TEST_LANGUAGE ,
356+ live )).orElseGet (() -> new ScriptSession (servers , TEST_LANGUAGE ));
353357 }
354358
355359 /** The problems found in a script, e.g. {@code Error@0:4-6 message}. */
356- private static List <String > problems (final String code ) {
360+ private static List <String > problems (final String code ) throws Exception {
361+ final CompletableFuture <List <Diagnostic >> heard =
362+ new CompletableFuture <>();
357363 final List <Diagnostic > found ;
358- try (ScriptSession session = session (Environment .NONE )) {
359- found = session .update (code ).diagnostics (20_000 );
364+ try (ScriptSession session = session (new Environment ())) {
365+ session .setDiagnosticsListener (heard ::complete );
366+ session .update (code );
367+ found = heard .get (20 , TimeUnit .SECONDS );
360368 }
361369 return found .stream ().map (d -> d .getSeverity () + "@" + d .getRange ().getStart ()
362370 .getLine () + ":" + d .getRange ().getStart ().getCharacter () + "-" + d
@@ -365,7 +373,7 @@ private static List<String> problems(final String code) {
365373 }
366374
367375 private static SignatureHelp help (final String code ) {
368- try (ScriptSession session = session (Environment . NONE )) {
376+ try (ScriptSession session = session (new Environment () )) {
369377 return session .signatureHelp (code , code .length ()).get (30 ,
370378 TimeUnit .SECONDS );
371379 }
@@ -386,7 +394,7 @@ private static String describe(final SignatureHelp help) {
386394 }
387395
388396 private static List <CompletionItem > items (final String code ) {
389- return items (session (Environment . NONE ), code );
397+ return items (session (new Environment () ), code );
390398 }
391399
392400 private static List <CompletionItem > items (final ScriptSession session ,
0 commit comments