@@ -268,6 +268,26 @@ public void testPrepareAndClose() throws Exception {
268268 fake .closed );
269269 }
270270
271+ @ Test
272+ public void testHoverAndDiagnostics () throws Exception {
273+ final FakeLsp fake = fake (q -> Collections .emptyList ());
274+ final String code = "#@ double sigma\n import json\n json.dumps(sigma)" ;
275+ org .scijava .code .api .Hover hover = completer .hover (new CompletionRequest (
276+ code , code .indexOf ("dumps" ) + 1 , language , null , null , null ));
277+ if (hover .update () != null ) hover = hover .update ().get (5 ,
278+ TimeUnit .SECONDS );
279+ assertEquals ("<pre>dumps</pre>" , hover .text ());
280+ assertEquals (code .indexOf ("dumps" ) + 1 , last (fake ).offset );
281+ // Not in comments or strings.
282+ assertTrue (completer .hover (new CompletionRequest ("# json.dumps" , 4 ,
283+ language , null , null , null )).isEmpty ());
284+
285+ final List <org .scijava .code .api .Diagnostic > problems = completer .diagnose (
286+ new CompletionRequest (code , language , null )).get (5 , TimeUnit .SECONDS );
287+ assertEquals (1 , problems .size ());
288+ assertTrue (last (fake ).doc .text ().endsWith (code ));
289+ }
290+
271291 @ Test
272292 public void testServerQuery () {
273293 final FakeLsp fake = fake (q -> Collections .emptyList ());
@@ -291,13 +311,15 @@ public void testServerOptions() {
291311 final JediLanguageServerSpec spec = new JediLanguageServerSpec (() -> null ,
292312 new java .io .File ("workspace" ), new java .io .File ("server.log" ));
293313 assertEquals ("python" , spec .languageId ());
314+ final String diagnostics = "diagnostics={enable=true, didOpen=true, " +
315+ "didChange=true, didSave=false}" ;
294316 assertEquals ("{workspace={environmentPath=/env/bin/python, " +
295- "extraPaths=[/overlay]}, diagnostics={enable=false}} " , String .valueOf (
296- spec .initializationOptions (new EnvironmentContext ("/env/bin/python" ,
317+ "extraPaths=[/overlay]}, " + diagnostics + "} " , String .valueOf (spec
318+ .initializationOptions (new EnvironmentContext ("/env/bin/python" ,
297319 Collections .singletonList ("/overlay" ), null ))));
298320 // Without a script environment: the server's own.
299- assertEquals ("{workspace={extraPaths=[]}, diagnostics={enable=false}}" ,
300- String .valueOf (spec .initializationOptions (EnvironmentContext .EMPTY )));
321+ assertEquals ("{workspace={extraPaths=[]}, " + diagnostics + "}" , String
322+ .valueOf (spec .initializationOptions (EnvironmentContext .EMPTY )));
301323 assertTrue (spec .rootUri (EnvironmentContext .EMPTY ).startsWith ("file:" ));
302324 new java .io .File ("workspace" ).delete ();
303325 }
@@ -552,6 +574,25 @@ public CompletableFuture<SignatureHelp> signatureHelp(
552574 active , callStart ));
553575 }
554576
577+ @ Override
578+ public CompletableFuture <org .scijava .code .api .Hover > hover (
579+ final ScriptDocument doc , final String uri , final int offset )
580+ {
581+ asked .add (new Asked (doc , uri , offset , 0 ));
582+ return CompletableFuture .completedFuture (new org .scijava .code .api .Hover (
583+ "<pre>dumps</pre>" , offset , offset ));
584+ }
585+
586+ @ Override
587+ public CompletableFuture <List <org .scijava .code .api .Diagnostic >> diagnose (
588+ final ScriptDocument doc , final String uri , final long timeout )
589+ {
590+ asked .add (new Asked (doc , uri , 0 , 0 ));
591+ return CompletableFuture .completedFuture (Collections .singletonList (
592+ new org .scijava .code .api .Diagnostic (0 , 1 ,
593+ org .scijava .code .api .Diagnostic .Severity .ERROR , "Oops" , "fake" )));
594+ }
595+
555596 @ Override
556597 public void prepare (final ScriptDocument doc , final String uri ) {
557598 asked .add (new Asked (doc , uri , doc .original ().length (), 0 ));
0 commit comments